|
From: <a-...@us...> - 2009-12-11 08:54:08
|
Revision: 119
http://simspark.svn.sourceforge.net/simspark/?rev=119&view=rev
Author: a-held
Date: 2009-12-11 08:54:01 +0000 (Fri, 11 Dec 2009)
Log Message:
-----------
Implemented bridge pattern for RayCollider and PlaneCollider
Modified Paths:
--------------
branches/multiphys/spark/lib/oxygen/CMakeLists.txt
branches/multiphys/spark/lib/oxygen/physicsserver/planecollider.cpp
branches/multiphys/spark/lib/oxygen/physicsserver/planecollider.h
branches/multiphys/spark/lib/oxygen/physicsserver/raycollider.cpp
branches/multiphys/spark/lib/oxygen/physicsserver/raycollider.h
Added Paths:
-----------
branches/multiphys/spark/lib/oxygen/physicsserver/int/planecolliderint.h
branches/multiphys/spark/lib/oxygen/physicsserver/int/raycolliderint.h
branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeplanecollider.cpp
branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeplanecollider.h
branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderaycollider.cpp
branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderaycollider.h
Modified: branches/multiphys/spark/lib/oxygen/CMakeLists.txt
===================================================================
--- branches/multiphys/spark/lib/oxygen/CMakeLists.txt 2009-12-10 08:34:56 UTC (rev 118)
+++ branches/multiphys/spark/lib/oxygen/CMakeLists.txt 2009-12-11 08:54:01 UTC (rev 119)
@@ -68,6 +68,8 @@
physicsserver/int/emptycolliderint.h
physicsserver/int/physicsobjectint.h
physicsserver/int/physicsserverint.h
+ physicsserver/int/planecolliderint.h
+ physicsserver/int/raycolliderint.h
physicsserver/int/rigidbodyint.h
physicsserver/int/softbodyint.h
physicsserver/int/spaceint.h
@@ -89,6 +91,8 @@
physicsserver/ode/odeemptycollider.h
physicsserver/ode/odephysicsobject.h
physicsserver/ode/odephysicsserver.h
+ physicsserver/ode/odeplanecollider.h
+ physicsserver/ode/oderaycollider.h
physicsserver/ode/oderigidbody.h
physicsserver/ode/odesoftbody.h
physicsserver/ode/odespace.h
@@ -245,6 +249,8 @@
physicsserver/ode/odeemptycollider.cpp
physicsserver/ode/odephysicsobject.cpp
physicsserver/ode/odephysicsserver.cpp
+ physicsserver/ode/odeplanecollider.cpp
+ physicsserver/ode/oderaycollider.cpp
physicsserver/ode/oderigidbody.cpp
physicsserver/ode/odesoftbody.cpp
physicsserver/ode/odespace.cpp
Added: branches/multiphys/spark/lib/oxygen/physicsserver/int/planecolliderint.h
===================================================================
--- branches/multiphys/spark/lib/oxygen/physicsserver/int/planecolliderint.h (rev 0)
+++ branches/multiphys/spark/lib/oxygen/physicsserver/int/planecolliderint.h 2009-12-11 08:54:01 UTC (rev 119)
@@ -0,0 +1,46 @@
+/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
+
+ this file is part of rcssserver3D
+ Fri May 9 2003
+ Copyright (C) 2002,2003 Koblenz University
+ Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
+ $Id: space.h 102 2009-11-18 07:24:29Z a-held $
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef OXYGEN_PLANECOLLIDERINT_H
+#define OXYGEN_PLANECOLLIDERINT_H
+
+#include <salt/matrix.h>
+#include <salt/vector.h>
+#include <oxygen/oxygen_defines.h>
+
+namespace oxygen
+{
+
+class OXYGEN_API PlaneColliderInt
+{
+public:
+ virtual void SetPlaneParams(float a, float b, float c, float d) = 0;
+ virtual void SetParams(const salt::Vector3f& pos, salt::Vector3f normal) = 0;
+ virtual float GetPointDepth(const salt::Vector3f& pos) = 0;
+
+ virtual long GetGeomID() = 0;
+ virtual void CreatePlane() = 0;
+};
+
+} //namespace oxygen
+
+#endif //OXYGEN_PLANECOLLIDERINT_H
Added: branches/multiphys/spark/lib/oxygen/physicsserver/int/raycolliderint.h
===================================================================
--- branches/multiphys/spark/lib/oxygen/physicsserver/int/raycolliderint.h (rev 0)
+++ branches/multiphys/spark/lib/oxygen/physicsserver/int/raycolliderint.h 2009-12-11 08:54:01 UTC (rev 119)
@@ -0,0 +1,42 @@
+/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
+
+ this file is part of rcssserver3D
+ Fri May 9 2003
+ Copyright (C) 2002,2003 Koblenz University
+ Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
+ $Id: raycolliderint.h 102 2009-11-18 07:24:29Z a-held $
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef OXYGEN_RAYCOLLIDERINT_H
+#define OXYGEN_RAYCOLLIDERINT_H
+
+#include <salt/vector.h>
+#include <oxygen/oxygen_defines.h>
+
+namespace oxygen
+{
+
+class OXYGEN_API RayColliderInt
+{
+public:
+ virtual void SetParams(salt::Vector3f pos, salt::Vector3f dir, float length) = 0;
+ virtual void CreateRay() = 0;
+ virtual long GetGeomID() = 0;
+};
+
+} //namespace oxygen
+
+#endif //OXYGEN_RAYCOLLIDERINT_H
Added: branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeplanecollider.cpp
===================================================================
--- branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeplanecollider.cpp (rev 0)
+++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeplanecollider.cpp 2009-12-11 08:54:01 UTC (rev 119)
@@ -0,0 +1,58 @@
+/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
+
+ this file is part of rcssserver3D
+ Fri May 9 2003
+ Copyright (C) 2003 Koblenz University
+ $Id: planecollider.cpp 108 2009-11-25 10:20:10Z a-held $
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <oxygen/physicsserver/ode/odeplanecollider.h>
+
+using namespace oxygen;
+using namespace salt;
+
+ODEPlaneCollider::ODEPlaneCollider() : ODECollider()
+{
+}
+
+void ODEPlaneCollider::SetPlaneParams(float a, float b, float c, float d)
+{
+ dGeomPlaneSetParams(mODEGeom, a, b, c, d);
+}
+
+void ODEPlaneCollider::CreatePlane()
+{
+ // a plane with normal pointing up, going through the origin
+ mODEGeom = dCreatePlane(0, 0, 1, 0, 0);
+ mGeomID = (long) mODEGeom;
+}
+
+void ODEPlaneCollider::SetParams(const salt::Vector3f& pos, salt::Vector3f normal)
+{
+ normal.Normalize();
+ float d = pos.Dot(normal);
+ dGeomPlaneSetParams(mODEGeom, normal.x(), normal.y(), normal.z(), d);
+}
+
+float ODEPlaneCollider::GetPointDepth(const Vector3f& pos)
+{
+ return dGeomPlanePointDepth
+ (mODEGeom,pos[0],pos[1],pos[2]);
+}
+
+long ODEPlaneCollider::GetGeomID(){
+ return mGeomID;
+}
Added: branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeplanecollider.h
===================================================================
--- branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeplanecollider.h (rev 0)
+++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeplanecollider.h 2009-12-11 08:54:01 UTC (rev 119)
@@ -0,0 +1,47 @@
+/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
+
+ this file is part of rcssserver3D
+ Fri May 9 2003
+ Copyright (C) 2002,2003 Koblenz University
+ Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
+ $Id: odeplanecollider.h 102 2009-11-18 07:24:29Z a-held $
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef OXYGEN_ODEPLANECOLLIDER_H
+#define OXYGEN_ODEPLANECOLLIDER_H
+
+#include <oxygen/physicsserver/ode/odecollider.h>
+#include <oxygen/physicsserver/int/planecolliderint.h>
+#include <oxygen/oxygen_defines.h>
+
+namespace oxygen
+{
+
+class OXYGEN_API ODEPlaneCollider : public PlaneColliderInt, public ODECollider
+{
+public:
+ ODEPlaneCollider();
+ void SetPlaneParams(float a, float b, float c, float d);
+ void SetParams(const salt::Vector3f& pos, salt::Vector3f normal);
+ float GetPointDepth(const salt::Vector3f& pos);
+
+ long GetGeomID();
+ void CreatePlane();
+};
+
+} //namespace oxygen
+
+#endif //OXYGEN_ODEPLANECOLLIDER_H
Added: branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderaycollider.cpp
===================================================================
--- branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderaycollider.cpp (rev 0)
+++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderaycollider.cpp 2009-12-11 08:54:01 UTC (rev 119)
@@ -0,0 +1,46 @@
+/* -*- mode: c++ -*-
+
+ this file is part of rcssserver3D
+ Fri May 9 2003
+ Copyright (C) 2003 Koblenz University
+ $Id: raycollider.cpp 108 2009-11-25 10:20:10Z a-held $
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <oxygen/physicsserver/ode/oderaycollider.h>
+
+using namespace oxygen;
+
+ODERayCollider::ODERayCollider() : ODECollider()
+{
+
+}
+
+void ODERayCollider::SetParams(salt::Vector3f pos,
+ salt::Vector3f dir, float length)
+{
+ dGeomRaySet(mODEGeom, pos[0], pos[1], pos[2], dir[0], dir[1], dir[2]);
+ dGeomRaySetLength(mODEGeom, length);
+}
+
+void ODERayCollider::CreateRay()
+{
+ mODEGeom = dCreateRay(0, 1.0f);
+ mGeomID = (long) mODEGeom;
+}
+
+long ODERayCollider::GetGeomID(){
+ return mGeomID;
+}
Added: branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderaycollider.h
===================================================================
--- branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderaycollider.h (rev 0)
+++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderaycollider.h 2009-12-11 08:54:01 UTC (rev 119)
@@ -0,0 +1,44 @@
+/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
+
+ this file is part of rcssserver3D
+ Fri May 9 2003
+ Copyright (C) 2002,2003 Koblenz University
+ Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
+ $Id: oderaycollider.h 102 2009-11-18 07:24:29Z a-held $
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef OXYGEN_ODERAYCOLLIDER_H
+#define OXYGEN_ODERAYCOLLIDER_H
+
+#include <oxygen/physicsserver/ode/odecollider.h>
+#include <oxygen/physicsserver/int/raycolliderint.h>
+#include <oxygen/oxygen_defines.h>
+
+namespace oxygen
+{
+
+class OXYGEN_API ODERayCollider : public RayColliderInt, public ODECollider
+{
+public:
+ ODERayCollider();
+ void SetParams(salt::Vector3f pos, salt::Vector3f dir, float length);
+ void CreateRay();
+ long GetGeomID();
+};
+
+} //namespace oxygen
+
+#endif //OXYGEN_ODERAYCOLLIDER_H
Modified: branches/multiphys/spark/lib/oxygen/physicsserver/planecollider.cpp
===================================================================
--- branches/multiphys/spark/lib/oxygen/physicsserver/planecollider.cpp 2009-12-10 08:34:56 UTC (rev 118)
+++ branches/multiphys/spark/lib/oxygen/physicsserver/planecollider.cpp 2009-12-11 08:54:01 UTC (rev 119)
@@ -20,12 +20,15 @@
*/
#include <oxygen/physicsserver/planecollider.h>
+#include <oxygen/physicsserver/ode/odeplanecollider.h>
+#include <zeitgeist/logserver/logserver.h>
using namespace oxygen;
using namespace salt;
PlaneCollider::PlaneCollider() : Collider()
{
+ mPlaneColliderImp = boost::shared_ptr<ODEPlaneCollider>(new ODEPlaneCollider());
}
void PlaneCollider::SetParams(float a, float b, float c, float d)
@@ -40,7 +43,7 @@
d /= l;
}
- dGeomPlaneSetParams(mODEGeom, a, b, c, d);
+ mPlaneColliderImp->SetPlaneParams(a, b, c, d);
}
bool PlaneCollider::ConstructInternal()
@@ -50,39 +53,35 @@
return false;
}
- // a plane with normal pointing up, going through the origin
- mODEGeom = dCreatePlane(0, 0, 1, 0, 0);
+ //create default plane
+ mPlaneColliderImp->CreatePlane();
+ mODEGeom = (dGeomID) mPlaneColliderImp->GetGeomID();
- return (mODEGeom != 0);
+ return (mPlaneColliderImp->GetGeomID() != 0);
}
-void
-PlaneCollider::SetParams(const salt::Vector3f& pos, salt::Vector3f normal)
+void PlaneCollider::SetParams(const salt::Vector3f& pos, salt::Vector3f normal)
{
normal.Normalize();
float d = pos.Dot(normal);
- dGeomPlaneSetParams(mODEGeom, normal.x(), normal.y(), normal.z(), d);
+ mPlaneColliderImp->SetPlaneParams(normal.x(), normal.y(), normal.z(), d);
+ //dGeomPlaneSetParams(mODEGeom, normal.x(), normal.y(), normal.z(), d);
}
-void
-PlaneCollider::SetPosition(const salt::Vector3f& /*pos*/)
+void PlaneCollider::SetPosition(const salt::Vector3f& /*pos*/)
{
- // planes are non placeable geoms
+ GetLog()->Error()
+ << "(PlaneCollider) WARNING: tried to set the position of a non-placeable geom, ignored\n";
}
-void
-PlaneCollider::SetRotation(const Matrix& /*rot*/)
+void PlaneCollider::SetRotation(const Matrix& /*rot*/)
{
- // planes are non placeable geoms
+ GetLog()->Error()
+ << "(PlaneCollider) WARNING: tried to set the rotation of a non-placeable geom, ignored\n";
}
-float
-PlaneCollider::GetPointDepth(const Vector3f& pos)
+float PlaneCollider::GetPointDepth(const Vector3f& pos)
{
Vector3f worldPos(GetWorldTransform() * pos);
- return dGeomPlanePointDepth
- (mODEGeom,worldPos[0],worldPos[1],worldPos[2]);
+ return mPlaneColliderImp->GetPointDepth(worldPos);
}
-
-
-
Modified: branches/multiphys/spark/lib/oxygen/physicsserver/planecollider.h
===================================================================
--- branches/multiphys/spark/lib/oxygen/physicsserver/planecollider.h 2009-12-10 08:34:56 UTC (rev 118)
+++ branches/multiphys/spark/lib/oxygen/physicsserver/planecollider.h 2009-12-11 08:54:01 UTC (rev 119)
@@ -27,6 +27,7 @@
namespace oxygen
{
+class PlaneColliderInt;
/** PlaneCollider encapsulates an ODE plane geometry object. Planes
are non-placeable geoms, i.e. unlike placeable geoms, planes do
@@ -74,6 +75,9 @@
/** constructs a default plane with normal pointing up, going
through the origin */
virtual bool ConstructInternal();
+
+private:
+ boost::shared_ptr<PlaneColliderInt> mPlaneColliderImp;
};
DECLARE_CLASS(PlaneCollider);
Modified: branches/multiphys/spark/lib/oxygen/physicsserver/raycollider.cpp
===================================================================
--- branches/multiphys/spark/lib/oxygen/physicsserver/raycollider.cpp 2009-12-10 08:34:56 UTC (rev 118)
+++ branches/multiphys/spark/lib/oxygen/physicsserver/raycollider.cpp 2009-12-11 08:54:01 UTC (rev 119)
@@ -19,24 +19,23 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <oxygen/physicsserver/ode/oderaycollider.h>
#include <oxygen/physicsserver/raycollider.h>
using namespace oxygen;
RayCollider::RayCollider() : Collider()
{
+ mRayColliderImp = boost::shared_ptr<ODERayCollider>(new ODERayCollider());
}
-void
-RayCollider::SetParams(salt::Vector3f pos,
+void RayCollider::SetParams(salt::Vector3f pos,
salt::Vector3f dir, float length)
{
- dGeomRaySet(mODEGeom, pos[0], pos[1], pos[2], dir[0], dir[1], dir[2]);
- dGeomRaySetLength(mODEGeom, length);
+ mRayColliderImp->SetParams(pos, dir, length);
}
-bool
-RayCollider::ConstructInternal()
+bool RayCollider::ConstructInternal()
{
if (! Collider::ConstructInternal())
{
@@ -44,7 +43,8 @@
}
// create a unit ray
- mODEGeom = dCreateRay(0, 1.0f);
+ mRayColliderImp->CreateRay();
+ mODEGeom = (dGeomID) mRayColliderImp->GetGeomID();
- return (mODEGeom != 0);
+ return (mRayColliderImp->GetGeomID() != 0);
}
Modified: branches/multiphys/spark/lib/oxygen/physicsserver/raycollider.h
===================================================================
--- branches/multiphys/spark/lib/oxygen/physicsserver/raycollider.h 2009-12-10 08:34:56 UTC (rev 118)
+++ branches/multiphys/spark/lib/oxygen/physicsserver/raycollider.h 2009-12-11 08:54:01 UTC (rev 119)
@@ -27,6 +27,7 @@
namespace oxygen
{
+class RayColliderInt;
/** RayCollider encapsulates an ODE ray geometry "object".
*
@@ -54,6 +55,9 @@
protected:
/** constructs a default ray with a length of 1 */
virtual bool ConstructInternal();
+
+private:
+ boost::shared_ptr<RayColliderInt> mRayColliderImp;
};
DECLARE_CLASS(RayCollider);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|