From: <a-...@us...> - 2009-11-19 10:10:58
|
Revision: 106 http://simspark.svn.sourceforge.net/simspark/?rev=106&view=rev Author: a-held Date: 2009-11-19 10:10:50 +0000 (Thu, 19 Nov 2009) Log Message: ----------- implemented bridge pattern for at least some methods in the Space class replaced ODEObject with a neutrally named PhysicsObject class Modified Paths: -------------- branches/multiphys/spark/lib/oxygen/CMakeLists.txt branches/multiphys/spark/lib/oxygen/oxygen.cpp branches/multiphys/spark/lib/oxygen/oxygen.h branches/multiphys/spark/lib/oxygen/physicsserver/angularmotor.h branches/multiphys/spark/lib/oxygen/physicsserver/body.cpp branches/multiphys/spark/lib/oxygen/physicsserver/body.h branches/multiphys/spark/lib/oxygen/physicsserver/body_c.cpp branches/multiphys/spark/lib/oxygen/physicsserver/collider.cpp branches/multiphys/spark/lib/oxygen/physicsserver/collider.h branches/multiphys/spark/lib/oxygen/physicsserver/collider_c.cpp branches/multiphys/spark/lib/oxygen/physicsserver/int/spaceint.h branches/multiphys/spark/lib/oxygen/physicsserver/joint.cpp branches/multiphys/spark/lib/oxygen/physicsserver/joint.h branches/multiphys/spark/lib/oxygen/physicsserver/joint_c.cpp branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeobject.h branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.cpp branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.h branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeworld.cpp branches/multiphys/spark/lib/oxygen/physicsserver/space.cpp branches/multiphys/spark/lib/oxygen/physicsserver/space.h branches/multiphys/spark/lib/oxygen/physicsserver/space_c.cpp branches/multiphys/spark/lib/oxygen/physicsserver/world.cpp branches/multiphys/spark/lib/oxygen/physicsserver/world.h branches/multiphys/spark/lib/oxygen/physicsserver/world_c.cpp Added Paths: ----------- branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.cpp branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.h branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject_c.cpp Modified: branches/multiphys/spark/lib/oxygen/CMakeLists.txt =================================================================== --- branches/multiphys/spark/lib/oxygen/CMakeLists.txt 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/CMakeLists.txt 2009-11-19 10:10:50 UTC (rev 106) @@ -14,6 +14,7 @@ gamecontrolserver/behavior.h oxygen.h oxygen_defines.h + physicsserver/physicsobject.h physicsserver/body.h physicsserver/bodycontroller.h physicsserver/boxcollider.h @@ -44,7 +45,6 @@ physicsserver/int/worldint.h #ode-specific files - physicsserver/ode/odeobject.h physicsserver/ode/odeworld.h physicsserver/ode/odewrapper.h @@ -107,6 +107,8 @@ gamecontrolserver/behavior.cpp gamecontrolserver/behavior_c.cpp oxygen.cpp + physicsserver/physicsobject.cpp + physicsserver/physicsobject_c.cpp physicsserver/body.cpp physicsserver/body_c.cpp physicsserver/bodycontroller.cpp @@ -167,8 +169,6 @@ physicsserver/ode/odespace_c.cpp physicsserver/ode/odeworld.cpp physicsserver/ode/odeworld_c.cpp - physicsserver/ode/odeobject.cpp - physicsserver/ode/odeobject_c.cpp sceneserver/basenode.cpp sceneserver/basenode_c.cpp Modified: branches/multiphys/spark/lib/oxygen/oxygen.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/oxygen.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/oxygen.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -53,6 +53,7 @@ // physics zg.GetCore()->RegisterClassObject(new CLASS(PhysicsServer), "oxygen/"); + zg.GetCore()->RegisterClassObject(new CLASS(PhysicsObject), "oxygen/"); zg.GetCore()->RegisterClassObject(new CLASS(Body), "oxygen/"); zg.GetCore()->RegisterClassObject(new CLASS(BodyController), "oxygen/"); zg.GetCore()->RegisterClassObject(new CLASS(DragController), "oxygen/"); @@ -85,10 +86,6 @@ zg.GetCore()->RegisterClassObject(new CLASS(AgentAspect), "oxygen/"); zg.GetCore()->RegisterClassObject(new CLASS(Effector), "oxygen/"); zg.GetCore()->RegisterClassObject(new CLASS(Perceptor), "oxygen/"); - - //ODE-specific classes - zg.GetCore()->RegisterClassObject(new CLASS(ODEObject), "oxygen/"); - #ifdef HAVE_SPADES_HEADERS // spades Modified: branches/multiphys/spark/lib/oxygen/oxygen.h =================================================================== --- branches/multiphys/spark/lib/oxygen/oxygen.h 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/oxygen.h 2009-11-19 10:10:50 UTC (rev 106) @@ -35,6 +35,7 @@ #include "gamecontrolserver/behavior.h" //abstract physics classes +#include <oxygen/physicsserver/physicsobject.h> #include "physicsserver/body.h" #include "physicsserver/bodycontroller.h" #include "physicsserver/dragcontroller.h" @@ -60,9 +61,6 @@ #include "physicsserver/universaljoint.h" #include "physicsserver/hinge2joint.h" -//ode-specific includes -#include <oxygen/physicsserver/ode/odeobject.h> - #include "sceneserver/basenode.h" #include "sceneserver/camera.h" #include "sceneserver/fpscontroller.h" Modified: branches/multiphys/spark/lib/oxygen/physicsserver/angularmotor.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/angularmotor.h 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/angularmotor.h 2009-11-19 10:10:50 UTC (rev 106) @@ -21,7 +21,7 @@ #define OXYGEN_ANGULARMOTOR_H #include <oxygen/oxygen_defines.h> -#include "joint.h" +#include <oxygen/physicsserver/joint.h> namespace oxygen { Modified: branches/multiphys/spark/lib/oxygen/physicsserver/body.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/body.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/body.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -30,7 +30,7 @@ using namespace salt; using namespace std; -Body::Body() : ODEObject(), mODEBody(0), mMassTrans(0,0,0), mMassTransformed(false) +Body::Body() : PhysicsObject(), mODEBody(0), mMassTrans(0,0,0), mMassTransformed(false) { } @@ -115,7 +115,7 @@ void Body::OnLink() { - ODEObject::OnLink(); + PhysicsObject::OnLink(); if (! CreateBody()) { Modified: branches/multiphys/spark/lib/oxygen/physicsserver/body.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/body.h 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/body.h 2009-11-19 10:10:50 UTC (rev 106) @@ -23,7 +23,7 @@ #define OXYGEN_BODY_H #include <oxygen/oxygen_defines.h> -#include <oxygen/physicsserver/ode/odeobject.h> +#include <oxygen/physicsserver/physicsobject.h> namespace oxygen { @@ -36,7 +36,7 @@ usually constant over time: Mass, Center of mass and Inertia matrix (mass distribution matrix) */ -class OXYGEN_API Body : public ODEObject +class OXYGEN_API Body : public PhysicsObject { // // Functions Modified: branches/multiphys/spark/lib/oxygen/physicsserver/body_c.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/body_c.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/body_c.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -568,7 +568,7 @@ void CLASS(Body)::DefineClass() { - DEFINE_BASECLASS(oxygen/ODEObject); + DEFINE_BASECLASS(oxygen/PhysicsObject); DEFINE_FUNCTION(enable); DEFINE_FUNCTION(disable); DEFINE_FUNCTION(isEnabled); Modified: branches/multiphys/spark/lib/oxygen/physicsserver/collider.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/collider.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/collider.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -32,7 +32,7 @@ using namespace boost; using namespace std; -Collider::Collider() : ODEObject(), mODEGeom(0) +Collider::Collider() : PhysicsObject(), mODEGeom(0) { } @@ -42,7 +42,7 @@ void Collider::OnLink() { - ODEObject::OnLink(); + PhysicsObject::OnLink(); weak_ptr<Node> parent = GetParent(); @@ -95,7 +95,7 @@ void Collider::OnUnlink() { - ODEObject::OnUnlink(); + PhysicsObject::OnUnlink(); // remove collision geometry from space dSpaceID space = GetParentSpaceID(); Modified: branches/multiphys/spark/lib/oxygen/physicsserver/collider.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/collider.h 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/collider.h 2009-11-19 10:10:50 UTC (rev 106) @@ -22,7 +22,7 @@ #ifndef OXYGEN_COLLIDER_H #define OXYGEN_COLLIDER_H -#include <oxygen/physicsserver/ode/odeobject.h> +#include <oxygen/physicsserver/physicsobject.h> #include <string> #include <set> #include <oxygen/oxygen_defines.h> @@ -42,7 +42,7 @@ bodies. A body and a geom together represent all the properties of the simulated object. */ -class OXYGEN_API Collider : public ODEObject +class OXYGEN_API Collider : public PhysicsObject { // // Functions Modified: branches/multiphys/spark/lib/oxygen/physicsserver/collider_c.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/collider_c.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/collider_c.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -104,10 +104,10 @@ void CLASS(Collider)::DefineClass() { + DEFINE_BASECLASS(oxygen/PhysicsObject); DEFINE_FUNCTION(setPosition); DEFINE_FUNCTION(setLocalPosition); DEFINE_FUNCTION(setRotation); DEFINE_FUNCTION(addCollisionHandler); DEFINE_FUNCTION(addNotCollideWithColliderName); - DEFINE_BASECLASS(oxygen/ODEObject); } Modified: branches/multiphys/spark/lib/oxygen/physicsserver/int/spaceint.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/int/spaceint.h 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/int/spaceint.h 2009-11-19 10:10:50 UTC (rev 106) @@ -23,7 +23,7 @@ #ifndef OXYGEN_SPACEINT_H #define OXYGEN_SPACEINT_H -#include <oxygen/physicsserver/ode/odeobject.h> +#include <oxygen/physicsserver/physicsobject.h> #include <set> #include <oxygen/oxygen_defines.h> @@ -33,20 +33,20 @@ class Body; class Collider; -class OXYGEN_API SpaceInt : public ODEObject +class OXYGEN_API SpaceInt : public PhysicsObject { public: typedef std::set<dSpaceID> TSpaceIdSet; - SpaceInt() : ODEObject(){}; + SpaceInt() : PhysicsObject(){}; virtual ~SpaceInt(){}; //virtual void collisionNearCallback (void *data, dGeomID obj1, dGeomID obj2) = 0; virtual dSpaceID GetODESpace() const = 0; virtual dJointGroupID GetODEJointGroup() const = 0; virtual void Collide() = 0; - virtual void DestroyODEObject() = 0; + virtual void DestroyPhysicsObject() = 0; virtual dSpaceID GetParentSpaceID() = 0; virtual bool IsGlobalSpace() = 0; virtual void DisableInnerCollision(bool disable) = 0; @@ -59,6 +59,8 @@ virtual bool ConstructInternal() = 0; virtual void PostPhysicsUpdateInternal() = 0; virtual void DestroySpaceObjects() = 0; + + boost::shared_ptr<Scene> scene; }; DECLARE_ABSTRACTCLASS(SpaceInt); Modified: branches/multiphys/spark/lib/oxygen/physicsserver/joint.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/joint.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/joint.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -27,7 +27,7 @@ using namespace salt; Joint::Joint() : -ODEObject(), mODEJoint(0), +PhysicsObject(), mODEJoint(0), mJointMaxSpeed1(0), mJointMaxSpeed2(0), mIsLimitJointMaxSpeed1(false), mIsLimitJointMaxSpeed2(false) { @@ -431,7 +431,7 @@ return GetParameter(dParamFMax + (idx * dParamGroup)); } -void Joint::DestroyODEObject() +void Joint::DestroyPhysicsObject() { if (! mODEJoint) { Modified: branches/multiphys/spark/lib/oxygen/physicsserver/joint.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/joint.h 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/joint.h 2009-11-19 10:10:50 UTC (rev 106) @@ -23,7 +23,7 @@ #define OXYGEN_JOINT_H #include <oxygen/oxygen_defines.h> -#include <oxygen/physicsserver/ode/odeobject.h> +#include <oxygen/physicsserver/physicsobject.h> namespace oxygen { @@ -47,7 +47,7 @@ rates) directly, instead you must set the corresponding body positions and velocities. */ -class OXYGEN_API Joint : public ODEObject +class OXYGEN_API Joint : public PhysicsObject { public: enum EBodyIndex @@ -67,7 +67,7 @@ virtual ~Joint(); /** destroy the managed ODE object */ - virtual void DestroyODEObject(); + virtual void DestroyPhysicsObject(); /** attaches the joint to some new bodies. If the joint is already attached, it will be detached from the old bodies first. To Modified: branches/multiphys/spark/lib/oxygen/physicsserver/joint_c.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/joint_c.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/joint_c.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -547,7 +547,7 @@ void CLASS(Joint)::DefineClass() { - DEFINE_BASECLASS(oxygen/ODEObject); + DEFINE_BASECLASS(oxygen/PhysicsObject); DEFINE_FUNCTION(attach); DEFINE_FUNCTION(setHighStopDeg); DEFINE_FUNCTION(getHighStopDeg); Modified: branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeobject.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeobject.h 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeobject.h 2009-11-19 10:10:50 UTC (rev 106) @@ -40,23 +40,23 @@ // // Functions // - ODEObject(); - virtual ~ODEObject(); + ODEObject(){}; + virtual ~ODEObject(){}; /** This rountine is called, before the hierarchy object is removed from the parent. It can be overridden to support custom 'unlink' behavior. */ - virtual void OnUnlink(); + virtual void OnUnlink(){}; /** returns the ODE world handle */ - dWorldID GetWorldID(); + dWorldID GetWorldID(){}; /** returns the nearest parent space ODE handle */ - dSpaceID FindSpaceID(); + dSpaceID FindSpaceID(){}; /** returns the ODE handle ID of the containing parent space */ - virtual dSpaceID GetParentSpaceID(); + virtual dSpaceID GetParentSpaceID(){}; /** destroy the managed ODE object */ virtual void DestroyODEObject(){}; @@ -66,7 +66,7 @@ boost::shared_ptr<World> GetWorld(); /** finds the nearest parent space node */ - boost::shared_ptr<Space> GetSpace(); + boost::shared_ptr<Space> GetSpace(){}; /** converts the rotation part of a salt::Matrix to an ODE dMatrix3 */ Modified: branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -184,12 +184,12 @@ void ODESpace::OnUnlink() { DisableInnerCollision(false); - ODEObject::OnUnlink(); + PhysicsObject::OnUnlink(); } void ODESpace::OnLink() { - ODEObject::OnLink(); + PhysicsObject::OnLink(); shared_ptr<Space> space = GetSpace(); dSpaceID spaceId = 0; @@ -237,7 +237,6 @@ void ODESpace::DestroySpaceObjects() { - shared_ptr<Scene> scene = GetScene(); if (scene.get() == 0) { return; @@ -245,7 +244,7 @@ TLeafList objects; const bool recursive = true; - scene->ListChildrenSupportingClass<ODEObject>(objects, recursive); + scene->ListChildrenSupportingClass<PhysicsObject>(objects, recursive); bool globalSpace = IsGlobalSpace(); shared_ptr<Space> self = shared_static_cast<Space>(GetSelf().lock()); @@ -256,7 +255,7 @@ ++iter ) { - shared_ptr<ODEObject> object = shared_static_cast<ODEObject>(*iter); + shared_ptr<PhysicsObject> object = shared_static_cast<PhysicsObject>(*iter); if (object == self) { continue; @@ -273,12 +272,12 @@ (parentSpace == mODESpace) ) { - object->DestroyODEObject(); + object->DestroyPhysicsObject(); } } } -void ODESpace::DestroyODEObject() +void ODESpace::DestroyPhysicsObject() { if (! mODESpace) { Modified: branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.h 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.h 2009-11-19 10:10:50 UTC (rev 106) @@ -41,7 +41,7 @@ dSpaceID GetODESpace() const; dJointGroupID GetODEJointGroup() const; void Collide(); - virtual void DestroyODEObject(); + virtual void DestroyPhysicsObject(); virtual dSpaceID GetParentSpaceID(); bool IsGlobalSpace(); void DisableInnerCollision(bool disable); Modified: branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeworld.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeworld.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/odeworld.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -122,7 +122,7 @@ shared_ptr<Space> space = GetSpace(); if (space.get() != 0) { - space->DestroyODEObject(); + space->DestroyPhysicsObject(); } if (mODEWorld == 0) Added: branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.cpp (rev 0) +++ branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -0,0 +1,167 @@ +/* -*- 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: odeobject.cpp 3 2008-11-21 02:38:08Z hedayat $ + + 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/physicsobject.h> +#include <oxygen/physicsserver/space.h> +#include <oxygen/physicsserver/world.h> +#include <oxygen/sceneserver/scene.h> +#include <zeitgeist/logserver/logserver.h> + +using namespace oxygen; +using namespace boost; + +PhysicsObject::PhysicsObject() : BaseNode() +{ +} + +PhysicsObject::~PhysicsObject() +{ +} + +void PhysicsObject::OnUnlink() +{ + DestroyPhysicsObject(); +} + +/** returns the world node */ +shared_ptr<World> PhysicsObject::GetWorld() +{ + shared_ptr<Scene> scene = GetScene(); + if (scene.get() == 0) + { + GetLog()->Error() << "(ODEObject) ERROR: found no Scene node\n"; + return shared_ptr<World>(); + } + + shared_ptr<World> worldNode = shared_dynamic_cast<World> + (scene->GetChildOfClass("World")); + if (worldNode.get() == 0) + { + GetLog()->Error() << "(ODEObject) ERROR: found no World node\n"; + } + + return worldNode; +} + +shared_ptr<Space> PhysicsObject::GetSpace() +{ + // try to find the nearest parent space object + weak_ptr<Space> parentSpace = FindParentSupportingClass<Space>(); + if (! parentSpace.expired()) + { + return parentSpace.lock(); + } + + // return the global space instance + shared_ptr<Scene> scene = GetScene(); + if (scene.get() == 0) + { + GetLog()->Error() << "(ODEObject) ERROR: found no Scene node\n"; + return shared_ptr<Space>(); + } + + shared_ptr<Space> spaceNode = shared_dynamic_cast<Space> + (scene->GetChildOfClass("Space")); + if (spaceNode.get() == 0) + { + GetLog()->Error() << "(ODEObject) ERROR: found no Space node\n"; + } + + return spaceNode; +} + +dWorldID PhysicsObject::GetWorldID() +{ + shared_ptr<World> world = GetWorld(); + if (world.get() == 0) + { + return 0; + } + + dWorldID worldId = world->GetODEWorld(); + if (worldId == 0) + { + GetLog()->Error() + << "(ODEObject) ERROR: World returned empty ODE handle\n"; + } + + return worldId; +} + +dSpaceID PhysicsObject::FindSpaceID() +{ + shared_ptr<Space> space = GetSpace(); + if (space.get() == 0) + { + return 0; + } + + dSpaceID spaceId = space->GetODESpace(); + + if (spaceId == 0) + { + GetLog()->Error() + << "(ODEObject) ERROR: Space returned empty ODE handle\n"; + } + + return spaceId; +} + +dSpaceID PhysicsObject::GetParentSpaceID() +{ + return 0; +} + +void PhysicsObject::ConvertRotationMatrix(const salt::Matrix& rot, dMatrix3& matrix) +{ + matrix[0] = rot.m[0]; + matrix[1] = rot.m[4]; + matrix[2] = rot.m[8]; + matrix[3] = 0; + matrix[4] = rot.m[1]; + matrix[5] = rot.m[5]; + matrix[6] = rot.m[9]; + matrix[7] = 0; + matrix[8] = rot.m[2]; + matrix[9] = rot.m[6]; + matrix[10] = rot.m[10]; + matrix[11] = 0; +} + +void PhysicsObject::ConvertRotationMatrix(const dReal* matrix, salt::Matrix& rot) const +{ + rot.m[0] = matrix[0] ; + rot.m[4] = matrix[1] ; + rot.m[8] = matrix[2]; + rot.m[12] = matrix[3]; + rot.m[1] = matrix[4]; + rot.m[5] = matrix[5]; + rot.m[9] = matrix[6]; + rot.m[13] = matrix[7]; + rot.m[2] = matrix[8]; + rot.m[6] = matrix[9]; + rot.m[10] = matrix[10] ; + rot.m[14] = matrix[11]; + rot.m[3] = 0.0; + rot.m[7] = 0.0; + rot.m[11] = 0.0; + rot.m[15] = 1.0; +} Added: branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.h (rev 0) +++ branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.h 2009-11-19 10:10:50 UTC (rev 106) @@ -0,0 +1,83 @@ +/* -*- 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: odeobject.h 56 2009-03-17 18:03:47Z hedayat $ + $Id: odeobject.h 56 2009-03-17 18:03:47Z hedayat $ + + 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_PHYSICSOBJECT_H +#define OXYGEN_PHYSICSOBJECT_H + +#include <oxygen/oxygen_defines.h> +#include <oxygen/sceneserver/basenode.h> +#include <oxygen/physicsserver/ode/odewrapper.h> + +namespace oxygen +{ +class Space; +class World; + +/** ODEObject is the base of all classes encapsulating ODE concepts + */ +class OXYGEN_API PhysicsObject : public BaseNode +{ +public: + // + // Functions + // + PhysicsObject(); + virtual ~PhysicsObject(); + + /** This rountine is called, before the hierarchy object is + removed from the parent. It can be overridden to support + custom 'unlink' behavior. + */ + virtual void OnUnlink(); + + /** returns the ODE world handle */ + dWorldID GetWorldID(); + + /** returns the nearest parent space ODE handle */ + dSpaceID FindSpaceID(); + + /** returns the ODE handle ID of the containing parent space */ + virtual dSpaceID GetParentSpaceID(); + + /** destroy the managed ODE object */ + virtual void DestroyPhysicsObject(){}; + +protected: + /** returns the world node */ + boost::shared_ptr<World> GetWorld(); + + /** finds the nearest parent space node */ + boost::shared_ptr<Space> GetSpace(); + + /** converts the rotation part of a salt::Matrix to an ODE + dMatrix3 */ + void ConvertRotationMatrix(const salt::Matrix& rot, dMatrix3& matrix); + + /** coverts the ODE dMatrix3 to the rotation part of a salt::Matrix */ + void ConvertRotationMatrix(const dReal* matrix, salt::Matrix& rot) const; +}; + +DECLARE_ABSTRACTCLASS(PhysicsObject); + +} //namespace oxygen + +#endif //OXYGEN_PHYSICSOBJECT_H Added: branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject_c.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject_c.cpp (rev 0) +++ branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject_c.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -0,0 +1,29 @@ +/* -*- mode: c++ -*- + + this file is part of rcssserver3D + Fri May 9 2003 + Copyright (C) 2003 Koblenz University + $Id: odeobject_c.cpp 3 2008-11-21 02:38:08Z hedayat $ + + 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/physicsobject.h> + +using namespace oxygen; + +void CLASS(PhysicsObject)::DefineClass() +{ + DEFINE_BASECLASS(oxygen/BaseNode); +} Modified: branches/multiphys/spark/lib/oxygen/physicsserver/space.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/space.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/space.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -19,9 +19,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "space.h" -#include "world.h" -#include "collider.h" +#include <oxygen/physicsserver/space.h> +#include <oxygen/physicsserver/ode/odespace.h> +#include <oxygen/physicsserver/collider.h> +#include <oxygen/physicsserver/world.h> #include <oxygen/sceneserver/scene.h> #include <zeitgeist/logserver/logserver.h> @@ -37,8 +38,9 @@ space->HandleCollide(obj1, obj2); } -Space::Space() : ODEObject(), mODESpace(0), mODEContactGroup(0) +Space::Space() : PhysicsObject(), mODESpace(0) { + mSpaceImp = shared_ptr<ODESpace>(new ODESpace()); } Space::~Space() @@ -47,12 +49,12 @@ dSpaceID Space::GetODESpace() const { - return mODESpace; + return mSpaceImp->GetODESpace(); } dJointGroupID Space::GetODEJointGroup() const { - return mODEContactGroup; + return mSpaceImp->GetODEJointGroup(); } void Space::Collide() @@ -182,13 +184,13 @@ void Space::OnUnlink() { - DisableInnerCollision(false); - ODEObject::OnUnlink(); + mSpaceImp->DisableInnerCollision(false); + PhysicsObject::OnUnlink(); } void Space::OnLink() { - ODEObject::OnLink(); + PhysicsObject::OnLink(); shared_ptr<Space> space = GetSpace(); dSpaceID spaceId = 0; @@ -199,136 +201,49 @@ } mODESpace = dHashSpaceCreate(spaceId); + + shared_ptr<ODESpace> odespace = shared_static_cast<ODESpace>(mSpaceImp); + odespace->mODESpace = mODESpace; } dSpaceID Space::GetParentSpaceID() { - if (mODESpace == 0) - { - return 0; - } - - return dGeomGetSpace((dGeomID)mODESpace); + return mSpaceImp->GetParentSpaceID(); } bool Space::IsGlobalSpace() { - return - ( - (mODESpace != 0) && - (GetParentSpaceID() == 0) - ); + return mSpaceImp->IsGlobalSpace(); } bool Space::ConstructInternal() { - // create a joint group for the contacts - mODEContactGroup = dJointGroupCreate(0); - - return (mODEContactGroup != 0); + return mSpaceImp->ConstructInternal(); } void Space::PostPhysicsUpdateInternal() { - // remove all contact joints - dJointGroupEmpty (mODEContactGroup); + mSpaceImp->PostPhysicsUpdateInternal(); } -void -Space::DestroySpaceObjects() +void Space::DestroySpaceObjects() { - shared_ptr<Scene> scene = GetScene(); - if (scene.get() == 0) - { - return; - } - - TLeafList objects; - const bool recursive = true; - scene->ListChildrenSupportingClass<ODEObject>(objects, recursive); - - bool globalSpace = IsGlobalSpace(); - shared_ptr<Space> self = shared_static_cast<Space>(GetSelf().lock()); - - for ( - TLeafList::iterator iter = objects.begin(); - iter != objects.end(); - ++iter - ) - { - shared_ptr<ODEObject> object = shared_static_cast<ODEObject>(*iter); - if (object == self) - { - continue; - } - - // destroy objects registered to this space; the top level - // space object also destroy any other ODE object - const dSpaceID parentSpace = object->GetParentSpaceID(); - if ( - ( - (globalSpace) && - (parentSpace == 0) - ) || - (parentSpace == mODESpace) - ) - { - object->DestroyODEObject(); - } - } + mSpaceImp->scene = GetScene(); + + mSpaceImp->DestroySpaceObjects(); } -void -Space::DestroyODEObject() +void Space::DestroyPhysicsObject() { - if (! mODESpace) - { - return; - } - - // make sure that all objects registered to this space are destroyed - // before this space. Any other order provokes a segfault in ODE. - DestroySpaceObjects(); - - if (mODEContactGroup) - { - dJointGroupDestroy(mODEContactGroup); - mODEContactGroup = 0; - } - - // release the ODE space - dSpaceDestroy(mODESpace); - mODESpace = 0; + mSpaceImp->DestroyPhysicsObject(); } void Space::DisableInnerCollision(bool disable) { - if (mODESpace == 0) - { - //assert(false); - return; - } - - if (disable) - { - gDisabledInnerCollisionSet.insert(mODESpace); - return; - } - - TSpaceIdSet::iterator iter = gDisabledInnerCollisionSet.find(mODESpace); - if (iter == gDisabledInnerCollisionSet.end()) - { - return; - } - - gDisabledInnerCollisionSet.erase(iter); + mSpaceImp->DisableInnerCollision(disable); } bool Space::GetDisableInnerCollision() const { - TSpaceIdSet::const_iterator iter - = gDisabledInnerCollisionSet.find(mODESpace); - - return (iter != gDisabledInnerCollisionSet.end()); + return mSpaceImp->GetDisableInnerCollision(); } - Modified: branches/multiphys/spark/lib/oxygen/physicsserver/space.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/space.h 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/space.h 2009-11-19 10:10:50 UTC (rev 106) @@ -22,7 +22,7 @@ #ifndef OXYGEN_SPACE_H #define OXYGEN_SPACE_H -#include <oxygen/physicsserver/ode/odeobject.h> +#include <oxygen/physicsserver/physicsobject.h> #include <set> #include <oxygen/oxygen_defines.h> @@ -31,13 +31,14 @@ class Transform; class Body; class Collider; +class SpaceInt; /** Space encapsulates an ODE space object. A space is a non-placeable geometry object ('geom') that can contain other geoms. It is similar to the rigid body concept of the `world', except that it applies to collision instead of dynamics. */ -class OXYGEN_API Space : public ODEObject +class OXYGEN_API Space : public PhysicsObject { public: typedef std::set<dSpaceID> TSpaceIdSet; @@ -61,7 +62,7 @@ void Collide(); /** destroy the managed ODE object */ - virtual void DestroyODEObject(); + virtual void DestroyPhysicsObject(); /** returns the ODE handle ID of the containing parent space */ virtual dSpaceID GetParentSpaceID(); @@ -115,12 +116,11 @@ // Members // private: + boost::shared_ptr<SpaceInt> mSpaceImp; + /** the managed ODE space */ dSpaceID mODESpace; - /** the ODE group for all created contact joints */ - dJointGroupID mODEContactGroup; - private: /** set of spaces with disabled inner collision */ static TSpaceIdSet gDisabledInnerCollisionSet; Modified: branches/multiphys/spark/lib/oxygen/physicsserver/space_c.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/space_c.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/space_c.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -38,6 +38,6 @@ void CLASS(Space)::DefineClass() { - DEFINE_BASECLASS(oxygen/ODEObject); + DEFINE_BASECLASS(oxygen/PhysicsObject); DEFINE_FUNCTION(disableInnerCollision); } Modified: branches/multiphys/spark/lib/oxygen/physicsserver/world.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/world.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/world.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -28,7 +28,7 @@ using namespace oxygen; using namespace salt; -World::World() : ODEObject() +World::World() : PhysicsObject() { mWorldImp = shared_ptr<ODEWorld>(new ODEWorld()); } Modified: branches/multiphys/spark/lib/oxygen/physicsserver/world.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/world.h 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/world.h 2009-11-19 10:10:50 UTC (rev 106) @@ -23,7 +23,7 @@ #define OXYGEN_WORLD_H #include <oxygen/oxygen_defines.h> -#include <oxygen/physicsserver/ode/odeobject.h> +#include <oxygen/physicsserver/physicsobject.h> namespace oxygen { @@ -38,7 +38,7 @@ time, thus one reason to use separate worlds is to simulate systems at different rates. */ -class OXYGEN_API World : public ODEObject +class OXYGEN_API World : public PhysicsObject { // // Functions Modified: branches/multiphys/spark/lib/oxygen/physicsserver/world_c.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/world_c.cpp 2009-11-19 06:56:32 UTC (rev 105) +++ branches/multiphys/spark/lib/oxygen/physicsserver/world_c.cpp 2009-11-19 10:10:50 UTC (rev 106) @@ -127,7 +127,7 @@ void CLASS(World)::DefineClass() { - DEFINE_BASECLASS(oxygen/ODEObject); + DEFINE_BASECLASS(oxygen/PhysicsObject); DEFINE_FUNCTION(setGravity); DEFINE_FUNCTION(setERP); DEFINE_FUNCTION(getERP); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |