From: <a-...@us...> - 2009-12-03 09:04:33
|
Revision: 113 http://simspark.svn.sourceforge.net/simspark/?rev=113&view=rev Author: a-held Date: 2009-12-03 09:04:19 +0000 (Thu, 03 Dec 2009) Log Message: ----------- completed bridge pattern for PhysicsObject class nearly done with RigidBody changed some return types and parameters to engine-independent types Modified Paths: -------------- branches/multiphys/spark/lib/oxygen/physicsserver/collider.cpp branches/multiphys/spark/lib/oxygen/physicsserver/collider.h branches/multiphys/spark/lib/oxygen/physicsserver/contactjointhandler.cpp branches/multiphys/spark/lib/oxygen/physicsserver/int/physicsobjectint.h branches/multiphys/spark/lib/oxygen/physicsserver/int/rigidbodyint.h branches/multiphys/spark/lib/oxygen/physicsserver/joint.cpp branches/multiphys/spark/lib/oxygen/physicsserver/joint.h branches/multiphys/spark/lib/oxygen/physicsserver/ode/odephysicsobject.cpp branches/multiphys/spark/lib/oxygen/physicsserver/ode/odephysicsobject.h branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderigidbody.cpp branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderigidbody.h branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.cpp branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.cpp branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.h branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.h branches/multiphys/spark/lib/oxygen/physicsserver/rigidbody.cpp branches/multiphys/spark/lib/oxygen/physicsserver/rigidbody.h branches/multiphys/spark/lib/oxygen/physicsserver/space.cpp branches/multiphys/spark/lib/oxygen/physicsserver/space.h branches/multiphys/spark/plugin/collisionperceptor/touchperceptorhandler.cpp Modified: branches/multiphys/spark/lib/oxygen/physicsserver/collider.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/collider.cpp 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/collider.cpp 2009-12-03 09:04:19 UTC (rev 113) @@ -62,7 +62,7 @@ // our parent is an ODE transform geom that encapsulates // this geom, so register ourself to it. This geom must // not directly register to a space or a body. - dGeomTransformSetGeom(tcParent->GetODEGeom(), mODEGeom); + dGeomTransformSetGeom((dGeomID) tcParent->GetGeomID(), mODEGeom); return; } @@ -126,9 +126,9 @@ } } -dGeomID Collider::GetODEGeom() +long Collider::GetGeomID() { - return mODEGeom; + return (long) mODEGeom; } bool Collider::AddCollisionHandler(const std::string& handlerName) @@ -175,21 +175,21 @@ } } -shared_ptr<Collider> Collider::GetCollider(dGeomID id) +shared_ptr<Collider> Collider::GetCollider(long geomID) { - if (id == 0) + if (geomID == 0) { return shared_ptr<Collider>(); } Collider* collPtr = - static_cast<Collider*>(dGeomGetData(id)); + static_cast<Collider*>(dGeomGetData((dGeomID) geomID)); if (collPtr == 0) { // we cannot use the logserver here - cerr << "ERROR: (Collider) no Collider found for dGeomID " - << id << "\n"; + cerr << "ERROR: (Collider) no Collider found for GeomID " + << geomID << "\n"; return shared_ptr<Collider>(); } @@ -199,8 +199,8 @@ if (collider.get() == 0) { // we cannot use the logserver here - cerr << "ERROR: (Collider) got no shared_ptr for dGeomID " - << id << "\n"; + cerr << "ERROR: (Collider) got no shared_ptr for GeomID " + << geomID << "\n"; } return collider; @@ -209,7 +209,7 @@ void Collider::SetRotation(const Matrix& rot) { dMatrix3 m; - ConvertRotationMatrix(rot,m); + ConvertRotationMatrix(rot,(int&) m); dGeomSetRotation(mODEGeom,m); } @@ -255,7 +255,7 @@ return dCollide ( mODEGeom, - collider->GetODEGeom(), + (dGeomID) collider->GetGeomID(), 1, /* ask for at most one collision point */ &contact, sizeof(contact) Modified: branches/multiphys/spark/lib/oxygen/physicsserver/collider.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/collider.h 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/collider.h 2009-12-03 09:04:19 UTC (rev 113) @@ -94,10 +94,10 @@ bool AddCollisionHandler(const std::string& handlerName); /** returns the Collider corresponding to the given ODE geom */ - static boost::shared_ptr<Collider> GetCollider(dGeomID id); + static boost::shared_ptr<Collider> GetCollider(long geomID); /** returns the ID of managed ODE geom */ - dGeomID GetODEGeom(); + long GetGeomID(); /** sets the relative position of the managed geom directly. If the geom is connected to a body, the position of the body will Modified: branches/multiphys/spark/lib/oxygen/physicsserver/contactjointhandler.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/contactjointhandler.cpp 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/contactjointhandler.cpp 2009-12-03 09:04:19 UTC (rev 113) @@ -163,8 +163,8 @@ // to create a contact joint it we must have at least one body to // attach it to. - dBodyID myBody = dGeomGetBody(mCollider->GetODEGeom()); - dBodyID collideeBody = dGeomGetBody(collidee->GetODEGeom()); + dBodyID myBody = dGeomGetBody((dGeomID) mCollider->GetGeomID()); + dBodyID collideeBody = dGeomGetBody((dGeomID) collidee->GetGeomID()); if ( (myBody == 0) && Modified: branches/multiphys/spark/lib/oxygen/physicsserver/int/physicsobjectint.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/int/physicsobjectint.h 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/int/physicsobjectint.h 2009-12-03 09:04:19 UTC (rev 113) @@ -35,8 +35,8 @@ { public: - virtual void ConvertRotationMatrix(const salt::Matrix& rot, dMatrix3& matrix) = 0; - virtual void ConvertRotationMatrix(const dReal* matrix, salt::Matrix& rot) const = 0; + virtual void ConvertRotationMatrix(const salt::Matrix& rot, int& matrix) = 0; + virtual void ConvertRotationMatrix(const void* matrix, salt::Matrix& rot) const = 0; protected: PhysicsObjectInt(){ Modified: branches/multiphys/spark/lib/oxygen/physicsserver/int/rigidbodyint.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/int/rigidbodyint.h 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/int/rigidbodyint.h 2009-12-03 09:04:19 UTC (rev 113) @@ -43,7 +43,7 @@ virtual void SetMass(float mass) = 0; virtual void SetMassParameters(const dMass& mass) = 0; virtual float GetMass() const = 0; - virtual void GetMassParameters(dMass& mass) const = 0; + virtual void GetMassParameters(float& mass) const = 0; virtual void SetSphere(float density, float radius) = 0; virtual void AddSphere(float density, float radius, const salt::Matrix& matrix) = 0; virtual void SetSphereTotal(float total_mass, float radius) = 0; @@ -84,6 +84,17 @@ virtual bool GetMassTransformed() = 0; virtual void SetMassTransformed(bool f) = 0; + /** Here, we have to cheat with the preprocessor, since a static method + is required, and the bridge pattern requires member variables to + be used (so we cannot use the bridge pattern) + */ + static RigidBody* GetBodyPointer(long bodyID){ + //if ODE is used (currently not checked since ODE is the only supported engine) + return static_cast<RigidBody*>(dBodyGetData( (dBodyID) bodyID)); + //if another engine is used + //do something else + } + protected: RigidBodyInt() : ODEBody(), mBodyID(0), mMassTrans(0,0,0), mMassTransformed(false){ }; Modified: branches/multiphys/spark/lib/oxygen/physicsserver/joint.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/joint.cpp 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/joint.cpp 2009-12-03 09:04:19 UTC (rev 113) @@ -47,21 +47,21 @@ dJointSetData(mODEJoint, this); } -shared_ptr<Joint> Joint::GetJoint(dJointID id) +shared_ptr<Joint> Joint::GetJoint(long jointID) { - if (id == 0) + if (jointID == 0) { return shared_ptr<Joint>(); } Joint* jointPtr = - static_cast<Joint*>(dJointGetData(id)); + static_cast<Joint*>(dJointGetData((dJointID) jointID)); if (jointPtr == 0) { // we cannot use the logserver here cerr << "ERROR: (Joint) no joint found for dJointID " - << id << "\n"; + << jointID << "\n"; return shared_ptr<Joint>(); } @@ -72,7 +72,7 @@ { // we cannot use the logserver here cerr << "ERROR: (Joint) got no shared_ptr for dJointID " - << id << "\n"; + << jointID << "\n"; } return joint; @@ -165,7 +165,8 @@ boost::shared_ptr<RigidBody> Joint::GetBody(EBodyIndex idx) { - return RigidBody::GetBody(dJointGetBody(mODEJoint, idx)); + long bodyID = (long) dJointGetBody(mODEJoint, idx); + return RigidBody::GetBody(bodyID); } bool Joint::AreConnected (shared_ptr<RigidBody> body1, shared_ptr<RigidBody> body2) Modified: branches/multiphys/spark/lib/oxygen/physicsserver/joint.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/joint.h 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/joint.h 2009-12-03 09:04:19 UTC (rev 113) @@ -91,8 +91,8 @@ */ boost::shared_ptr<RigidBody> GetBody(EBodyIndex idx); - /** returns the Joint node corresponding to the given ODE joint */ - static boost::shared_ptr<Joint> GetJoint(dJointID id); + /** returns the Joint node corresponding to the given joint */ + static boost::shared_ptr<Joint> GetJoint(long jointID); /** returns the type of the managed ODE joint, possible return values are dJointTypeNone, dJointTypeBall, dJointTypeHinge, Modified: branches/multiphys/spark/lib/oxygen/physicsserver/ode/odephysicsobject.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/ode/odephysicsobject.cpp 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/odephysicsobject.cpp 2009-12-03 09:04:19 UTC (rev 113) @@ -33,36 +33,40 @@ { } -void ODEPhysicsObject::ConvertRotationMatrix(const salt::Matrix& rot, dMatrix3& matrix) +void ODEPhysicsObject::ConvertRotationMatrix(const salt::Matrix& rot, int& 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; + dMatrix3& odeMatrix = (dMatrix3&) matrix; + + odeMatrix[0] = rot.m[0]; + odeMatrix[1] = rot.m[4]; + odeMatrix[2] = rot.m[8]; + odeMatrix[3] = 0; + odeMatrix[4] = rot.m[1]; + odeMatrix[5] = rot.m[5]; + odeMatrix[6] = rot.m[9]; + odeMatrix[7] = 0; + odeMatrix[8] = rot.m[2]; + odeMatrix[9] = rot.m[6]; + odeMatrix[10] = rot.m[10]; + odeMatrix[11] = 0; } -void ODEPhysicsObject::ConvertRotationMatrix(const dReal* matrix, salt::Matrix& rot) const +void ODEPhysicsObject::ConvertRotationMatrix(const void* 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]; + dReal* odeMatrix = (dReal*) matrix; + + rot.m[0] = odeMatrix[0]; + rot.m[4] = odeMatrix[1]; + rot.m[8] = odeMatrix[2]; + rot.m[12] = odeMatrix[3]; + rot.m[1] = odeMatrix[4]; + rot.m[5] = odeMatrix[5]; + rot.m[9] = odeMatrix[6]; + rot.m[13] = odeMatrix[7]; + rot.m[2] = odeMatrix[8]; + rot.m[6] = odeMatrix[9]; + rot.m[10] = odeMatrix[10]; + rot.m[14] = odeMatrix[11]; rot.m[3] = 0.0; rot.m[7] = 0.0; rot.m[11] = 0.0; Modified: branches/multiphys/spark/lib/oxygen/physicsserver/ode/odephysicsobject.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/ode/odephysicsobject.h 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/odephysicsobject.h 2009-12-03 09:04:19 UTC (rev 113) @@ -34,8 +34,8 @@ { public: ODEPhysicsObject(); - void ConvertRotationMatrix(const salt::Matrix& rot, dMatrix3& matrix); - void ConvertRotationMatrix(const dReal* matrix, salt::Matrix& rot) const; + void ConvertRotationMatrix(const salt::Matrix& rot, int& matrix); + void ConvertRotationMatrix(const void* matrix, salt::Matrix& rot) const; }; } //namespace oxygen Modified: branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderigidbody.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderigidbody.cpp 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderigidbody.cpp 2009-12-03 09:04:19 UTC (rev 113) @@ -35,10 +35,9 @@ ODERigidBody::ODERigidBody() : RigidBodyInt(){ } -long ODERigidBody::GetBodyID() -{ +long ODERigidBody::GetBodyID(){ return mBodyID; -} +} salt::Vector3f ODERigidBody::GetMassTrans(){ return mMassTrans; @@ -58,17 +57,17 @@ void ODERigidBody::Enable() { - dBodyEnable((dBodyID)mBodyID); + dBodyEnable((dBodyID) mBodyID); } void ODERigidBody::Disable() { - dBodyDisable((dBodyID)mBodyID); + dBodyDisable((dBodyID) mBodyID); } bool ODERigidBody::IsEnabled() const { - return (dBodyIsEnabled((dBodyID)mBodyID) != 0); + return (dBodyIsEnabled((dBodyID) mBodyID) != 0); } void ODERigidBody::UseGravity(bool f) @@ -76,59 +75,52 @@ if (f == true) { // body is affected by gravity - dBodySetGravityMode((dBodyID)mBodyID, 1); + dBodySetGravityMode((dBodyID) mBodyID, 1); } else { // body is not affected by gravity - dBodySetGravityMode((dBodyID)mBodyID, 0); + dBodySetGravityMode((dBodyID) mBodyID, 0); } } -bool ODERigidBody::UsesGravity() const -{ - return (dBodyGetGravityMode((dBodyID)mBodyID) != 0); +bool ODERigidBody::UsesGravity() const{ + return (dBodyGetGravityMode((dBodyID) mBodyID) != 0); } void ODERigidBody::CreateBody(long world) { - if (mBodyID != 0) - { - return; - } - // create the managed body - mBodyID = (long) dBodyCreate( (dWorldID) world); + mBodyID = (long) dBodyCreate((dWorldID) world); } -void ODERigidBody::DestroyPhysicsObject() -{ +void ODERigidBody::DestroyPhysicsObject(){ if (mBodyID == 0) { return; } - dBodyDestroy((dBodyID)mBodyID); + dBodyDestroy((dBodyID) mBodyID); mBodyID = 0; } void ODERigidBody::BodySetData(RigidBody* rb) { - dBodySetData((dBodyID)mBodyID, rb); + dBodySetData((dBodyID) mBodyID, rb); } void ODERigidBody::SetMass(float mass) { dMass ODEMass; - dBodyGetMass((dBodyID)mBodyID, &ODEMass); + dBodyGetMass((dBodyID) mBodyID, &ODEMass); dMassAdjust(&ODEMass, mass); - dBodySetMass((dBodyID)mBodyID, &ODEMass); + dBodySetMass((dBodyID) mBodyID, &ODEMass); } float ODERigidBody::GetMass() const { dMass m; - dBodyGetMass((dBodyID)mBodyID, &m); + dBodyGetMass((dBodyID) mBodyID, &m); return m.mass; } @@ -137,7 +129,7 @@ dMass transMass(mass); dMatrix3 rot; - ConvertRotationMatrix(matrix, rot); + ConvertRotationMatrix(matrix,(int&) rot); dMassRotate(&transMass,rot); const Vector3f& trans(matrix.Pos()); @@ -146,7 +138,7 @@ dMassTranslate(&transMass,mMassTrans[0],mMassTrans[1],mMassTrans[2]); dMass bodyMass; - dBodyGetMass((dBodyID)mBodyID, &bodyMass); + dBodyGetMass((dBodyID) mBodyID, &bodyMass); dMassAdd(&bodyMass, &transMass); /** ODE currently requires that the center mass is always in the @@ -156,7 +148,7 @@ dMassTranslate(&bodyMass, -trans2[0], -trans2[1], -trans2[2]); bodyMass.c[0] = bodyMass.c[1] = bodyMass.c[2] = 0.0f; - dBodySetMass((dBodyID)mBodyID, (const dMass*)&bodyMass); + dBodySetMass((dBodyID) mBodyID, (const dMass*)&bodyMass); // Move body so mass is at right position again SetPosition(GetPosition() + trans2); @@ -167,14 +159,16 @@ mMassTransformed = true; } -void ODERigidBody::GetMassParameters(dMass& mass) const +void ODERigidBody::GetMassParameters(float& mass) const { - dBodyGetMass((dBodyID)mBodyID, &mass); + dMass& odeMass = (dMass&) mass; + dBodyGetMass((dBodyID) mBodyID, &odeMass); + mass = (float&) odeMass; } void ODERigidBody::SetMassParameters(const dMass& mass) { - dBodySetMass((dBodyID)mBodyID, &mass); + dBodySetMass((dBodyID) mBodyID, &mass); } void ODERigidBody::PrepareSphere(dMass& mass, float density, float radius) const @@ -186,7 +180,7 @@ { dMass ODEMass; PrepareSphere(ODEMass, density, radius); - dBodySetMass((dBodyID)mBodyID, &ODEMass); + dBodySetMass((dBodyID) mBodyID, &ODEMass); } void ODERigidBody::AddSphere(float density, float radius, const Matrix& matrix) @@ -205,7 +199,7 @@ { dMass ODEMass; PrepareSphereTotal(ODEMass, total_mass, radius); - dBodySetMass((dBodyID)mBodyID, &ODEMass); + dBodySetMass((dBodyID) mBodyID, &ODEMass); } void ODERigidBody::AddSphereTotal(float total_mass, float radius, const Matrix& matrix) @@ -224,7 +218,7 @@ { dMass ODEMass; PrepareBox(ODEMass, density, size); - dBodySetMass((dBodyID)mBodyID, &ODEMass); + dBodySetMass((dBodyID) mBodyID, &ODEMass); } void ODERigidBody::AddBox(float density, const Vector3f& size, const Matrix& matrix) @@ -243,7 +237,7 @@ { dMass ODEMass; PrepareBoxTotal(ODEMass, total_mass, size); - dBodySetMass((dBodyID)mBodyID, &ODEMass); + dBodySetMass((dBodyID) mBodyID, &ODEMass); } void ODERigidBody::AddBoxTotal(float total_mass, const Vector3f& size, const Matrix& matrix) @@ -265,7 +259,7 @@ { dMass ODEMass; PrepareCylinder(ODEMass, density, radius, length); - dBodySetMass((dBodyID)mBodyID, &ODEMass); + dBodySetMass((dBodyID) mBodyID, &ODEMass); } void ODERigidBody::AddCylinder (float density, float radius, float length, const Matrix& matrix) @@ -287,7 +281,7 @@ { dMass ODEMass; PrepareCylinderTotal(ODEMass, total_mass, radius, length); - dBodySetMass((dBodyID)mBodyID, &ODEMass); + dBodySetMass((dBodyID) mBodyID, &ODEMass); } void ODERigidBody::AddCylinderTotal(float total_mass, float radius, float length, const Matrix& matrix) @@ -309,7 +303,7 @@ { dMass ODEMass; PrepareCapsule(ODEMass, density, radius, length); - dBodySetMass((dBodyID)mBodyID, &ODEMass); + dBodySetMass((dBodyID) mBodyID, &ODEMass); } void ODERigidBody::AddCapsule (float density, float radius, float length, const Matrix& matrix) @@ -331,7 +325,7 @@ { dMass ODEMass; PrepareCapsuleTotal(ODEMass, total_mass, radius, length); - dBodySetMass((dBodyID)mBodyID, &ODEMass); + dBodySetMass((dBodyID) mBodyID, &ODEMass); } void ODERigidBody::AddCapsuleTotal(float total_mass, float radius, float length, const salt::Matrix& matrix) @@ -343,25 +337,25 @@ Vector3f ODERigidBody::GetVelocity() const { - const dReal* vel = dBodyGetLinearVel((dBodyID)mBodyID); + const dReal* vel = dBodyGetLinearVel((dBodyID) mBodyID); return Vector3f(vel[0], vel[1], vel[2]); } void ODERigidBody::SetVelocity(const Vector3f& vel) { - dBodySetLinearVel((dBodyID)mBodyID, vel[0], vel[1], vel[2]); + dBodySetLinearVel((dBodyID) mBodyID, vel[0], vel[1], vel[2]); } void ODERigidBody::SetRotation(const Matrix& rot) { dMatrix3 m; - ConvertRotationMatrix(rot,m); - dBodySetRotation((dBodyID)mBodyID,m); + ConvertRotationMatrix(rot,(int&) m); + dBodySetRotation((dBodyID) mBodyID,m); } salt::Matrix ODERigidBody::GetRotation() const { - const dReal* m = dBodyGetRotation((dBodyID)mBodyID); + const dReal* m = dBodyGetRotation((dBodyID) mBodyID); salt::Matrix rot; ConvertRotationMatrix(m,rot); return rot; @@ -369,19 +363,19 @@ Vector3f ODERigidBody::GetAngularVelocity() const { - const dReal* vel = dBodyGetAngularVel((dBodyID)mBodyID); + const dReal* vel = dBodyGetAngularVel((dBodyID) mBodyID); return Vector3f(vel[0], vel[1], vel[2]); } void ODERigidBody::SetAngularVelocity(const Vector3f& vel) { - dBodySetAngularVel((dBodyID)mBodyID, vel[0], vel[1], vel[2]); + dBodySetAngularVel((dBodyID) mBodyID, vel[0], vel[1], vel[2]); } salt::Matrix ODERigidBody::GetSynchronisationMatrix() { - const dReal* pos = dBodyGetPosition((dBodyID)mBodyID); - const dReal* rot = dBodyGetRotation((dBodyID)mBodyID); + const dReal* pos = dBodyGetPosition((dBodyID) mBodyID); + const dReal* rot = dBodyGetRotation((dBodyID) mBodyID); Matrix mat; mat.m[0] = rot[0]; @@ -414,29 +408,29 @@ void ODERigidBody::AddForce(const Vector3f& force) { - dBodyAddForce((dBodyID)mBodyID, force.x(), force.y(), force.z()); + dBodyAddForce((dBodyID) mBodyID, force.x(), force.y(), force.z()); } void ODERigidBody::AddTorque(const Vector3f& torque) { - dBodyAddTorque((dBodyID)mBodyID, torque.x(), torque.y(), torque.z()); + dBodyAddTorque((dBodyID) mBodyID, torque.x(), torque.y(), torque.z()); } void ODERigidBody::SetPosition(const Vector3f& pos) { - dBodySetPosition((dBodyID)mBodyID, pos.x(), pos.y(), pos.z()); + dBodySetPosition((dBodyID) mBodyID, pos.x(), pos.y(), pos.z()); // the parent node will be updated in the next physics cycle } Vector3f ODERigidBody::GetPosition() const { - const dReal* pos = dBodyGetPosition((dBodyID)mBodyID); + const dReal* pos = dBodyGetPosition((dBodyID) mBodyID); return Vector3f(pos[0], pos[1], pos[2]); } void ODERigidBody::TranslateMass(const Vector3f& v) { dMass m; - dBodyGetMass((dBodyID)mBodyID, &m); + dBodyGetMass((dBodyID) mBodyID, &m); dMassTranslate(&m,v[0],v[1],v[2]); } Modified: branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderigidbody.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderigidbody.h 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/oderigidbody.h 2009-12-03 09:04:19 UTC (rev 113) @@ -40,7 +40,7 @@ void SetMass(float mass); void SetMassParameters(const dMass& mass); float GetMass() const; - void GetMassParameters(dMass& mass) const; + void GetMassParameters(float& mass) const; void AddMass(const dMass& mass, const salt::Matrix& matrix); void SetSphere(float density, float radius); void AddSphere(float density, float radius, const salt::Matrix& matrix); Modified: branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.cpp 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/ode/odespace.cpp 2009-12-03 09:04:19 UTC (rev 113) @@ -112,23 +112,9 @@ const dSpaceID s1 = dGeomGetSpace(obj1); const dSpaceID s2 = dGeomGetSpace(obj2); - // NOTICE: this should not happen since it is checked in Collide(dSpaceID) -// if ( -// (s1 == s2) && -// (gDisabledInnerCollisionSet.find(s1) != gDisabledInnerCollisionSet.end()) -// ) -// { -// return; -// } - - - // if obj1 and obj2 are in the same space, and - // obj1 is in obj2's "mNotCollideWithSet" or ojb2 is in obj1's - // reject the collision - // get shared pointers to the two corresponding Collider nodes first - shared_ptr<Collider> collider = Collider::GetCollider(obj1); - shared_ptr<Collider> collidee = Collider::GetCollider(obj2); + shared_ptr<Collider> collider = Collider::GetCollider((long) obj1); + shared_ptr<Collider> collidee = Collider::GetCollider((long) obj2); if ( (collider.get() == 0) || Modified: branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.cpp 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.cpp 2009-12-03 09:04:19 UTC (rev 113) @@ -135,12 +135,12 @@ return 0; } -void PhysicsObject::ConvertRotationMatrix(const salt::Matrix& rot, dMatrix3& matrix) +void PhysicsObject::ConvertRotationMatrix(const salt::Matrix& rot, int& matrix) { mPhysicsObjectImp->ConvertRotationMatrix(rot, matrix); } -void PhysicsObject::ConvertRotationMatrix(const dReal* matrix, salt::Matrix& rot) const +void PhysicsObject::ConvertRotationMatrix(const void* matrix, salt::Matrix& rot) const { mPhysicsObjectImp->ConvertRotationMatrix(matrix, rot); } Modified: branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.h 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/physicsobject.h 2009-12-03 09:04:19 UTC (rev 113) @@ -25,7 +25,6 @@ #include <oxygen/oxygen_defines.h> #include <oxygen/sceneserver/basenode.h> -#include <oxygen/physicsserver/ode/odewrapper.h> namespace oxygen { @@ -73,12 +72,15 @@ /** 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); + /** converts the rotation part of a salt::Matrix to an + engine-specific matrix, currently used for ODE's dMatrix3 + */ + void ConvertRotationMatrix(const salt::Matrix& rot, int& matrix); - /** coverts the ODE dMatrix3 to the rotation part of a salt::Matrix */ - void ConvertRotationMatrix(const dReal* matrix, salt::Matrix& rot) const; + /** coverts an engine-specific to the rotation part of a salt::Matrix, + currently used for ODE's dMatrix3 + */ + void ConvertRotationMatrix(const void* matrix, salt::Matrix& rot) const; private: boost::shared_ptr<PhysicsObjectInt> mPhysicsObjectImp; Modified: branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.h 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.h 2009-12-03 09:04:19 UTC (rev 113) @@ -25,7 +25,6 @@ #include <zeitgeist/class.h> #include <zeitgeist/leaf.h> #include <oxygen/oxygen_defines.h> -#include <oxygen/physicsserver/ode/odewrapper.h> namespace oxygen { Modified: branches/multiphys/spark/lib/oxygen/physicsserver/rigidbody.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/rigidbody.cpp 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/rigidbody.cpp 2009-12-03 09:04:19 UTC (rev 113) @@ -30,7 +30,7 @@ using namespace salt; using namespace std; -RigidBody::RigidBody() : Body(), mODEBody(0), mMassTrans(0,0,0), mMassTransformed(false) +RigidBody::RigidBody() : Body() { mRigidBodyImp = boost::shared_ptr<ODERigidBody>(new ODERigidBody()); } @@ -86,8 +86,6 @@ mRigidBodyImp->CreateBody(world); - mODEBody = (dBodyID) mRigidBodyImp->GetBodyID(); - if (mRigidBodyImp->GetBodyID() == 0) { GetLog()->Error() @@ -138,7 +136,7 @@ mRigidBodyImp->AddMass(mass, matrix); } -void RigidBody::GetMassParameters(dMass& mass) const +void RigidBody::GetMassParameters(float& mass) const { mRigidBodyImp->GetMassParameters(mass); } @@ -273,6 +271,7 @@ // Check whether mass/body has been translated if (mRigidBodyImp->GetMassTransformed()) { + Vector3f massTrans = mRigidBodyImp->GetMassTrans(); weak_ptr<Node> parent = GetParent(); // Update colliders (only those encapsulated in transform colliders) @@ -286,7 +285,7 @@ if (collider.get()) { Vector3f pos = collider->GetPosition(); - pos = pos + mMassTrans; + pos = pos + massTrans; collider->SetLocalPosition(pos); } } @@ -298,7 +297,7 @@ { shared_ptr<Transform> transform = shared_dynamic_cast<Transform>(*iter); Matrix worldTransform = transform->GetWorldTransform(); - worldTransform.Pos() = worldTransform.Pos() + mMassTrans; + worldTransform.Pos() = worldTransform.Pos() + massTrans; transform->SetWorldTransform(worldTransform); } @@ -313,7 +312,7 @@ SynchronizeParent(); } -shared_ptr<RigidBody> RigidBody::GetBody(dBodyID id) +shared_ptr<RigidBody> RigidBody::GetBody(long id) { long bodyID = (long) id; if (bodyID == 0) @@ -321,8 +320,7 @@ return shared_ptr<RigidBody>(); } - RigidBody* bodyPtr = - static_cast<RigidBody*>(dBodyGetData( (dBodyID) bodyID)); + RigidBody* bodyPtr = RigidBodyInt::GetBodyPointer(bodyID); if (bodyPtr == 0) { Modified: branches/multiphys/spark/lib/oxygen/physicsserver/rigidbody.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/rigidbody.h 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/rigidbody.h 2009-12-03 09:04:19 UTC (rev 113) @@ -84,7 +84,7 @@ float GetMass() const; /** returns the ODE mass parameters of this body */ - void GetMassParameters(dMass& mass) const; + void GetMassParameters(float& mass) const; /** adds the given ode mass to this body. The given matrix is applied to the mass center @@ -218,7 +218,7 @@ void SetAngularVelocity(const salt::Vector3f& vel); /** returns the Body node corresponding to the given ODE body */ - static boost::shared_ptr<RigidBody> GetBody(dBodyID id); + static boost::shared_ptr<RigidBody> GetBody(long id); /** applies a force to the managed ODE body */ void AddForce(const salt::Vector3f& force); @@ -266,15 +266,6 @@ // protected: boost::shared_ptr<RigidBodyInt> mRigidBodyImp; - - /** the managed ode body */ - dBodyID mODEBody; - - /** the total mass translation */ - salt::Vector3f mMassTrans; - - /** flag whether mass has been transformed */ - bool mMassTransformed; }; DECLARE_CLASS(RigidBody); Modified: branches/multiphys/spark/lib/oxygen/physicsserver/space.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/space.cpp 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/space.cpp 2009-12-03 09:04:19 UTC (rev 113) @@ -35,7 +35,7 @@ void Space::collisionNearCallback (void *data, dGeomID obj1, dGeomID obj2) { Space *space = (Space*)data; - space->HandleCollide(obj1, obj2); + space->HandleCollide((long) obj1, (long) obj2); } Space::Space() : PhysicsObject(), mODESpace(0) @@ -89,24 +89,27 @@ } } -void Space::HandleCollide(dGeomID obj1, dGeomID obj2) +void Space::HandleCollide(long obj1, long obj2) { //mSpaceImp->HandleCollide(obj1, obj2); + + dGeomID geom1 = (dGeomID) obj1; + dGeomID geom2 = (dGeomID) obj2; if ( - (dGeomIsSpace (obj1)) || - (dGeomIsSpace (obj2)) + (dGeomIsSpace (geom1)) || + (dGeomIsSpace (geom2)) ) { // colliding a space with something - HandleSpaceCollide(obj1, obj2); + HandleSpaceCollide(geom1, geom2); return; } // colliding two non-space geoms; reject collisions // between bodies that are connected with joints - const dBodyID b1 = dGeomGetBody(obj1); - const dBodyID b2 = dGeomGetBody(obj2); + const dBodyID b1 = dGeomGetBody(geom1); + const dBodyID b2 = dGeomGetBody(geom2); if ( (b1) && (b2) && @@ -118,23 +121,9 @@ // if obj1 and obj2 are in a space that disabled inner collision, // reject the collision - const dSpaceID s1 = dGeomGetSpace(obj1); - const dSpaceID s2 = dGeomGetSpace(obj2); + const dSpaceID s1 = dGeomGetSpace(geom1); + const dSpaceID s2 = dGeomGetSpace(geom2); - // NOTICE: this should not happen since it is checked in Collide(dSpaceID) -// if ( -// (s1 == s2) && -// (gDisabledInnerCollisionSet.find(s1) != gDisabledInnerCollisionSet.end()) -// ) -// { -// return; -// } - - - // if obj1 and obj2 are in the same space, and - // obj1 is in obj2's "mNotCollideWithSet" or ojb2 is in obj1's - // reject the collision - // get shared pointers to the two corresponding Collider nodes first shared_ptr<Collider> collider = Collider::GetCollider(obj1); shared_ptr<Collider> collidee = Collider::GetCollider(obj2); @@ -169,7 +158,7 @@ static const int nContacts = 4; static dContact contacts[nContacts]; - int n = dCollide (obj1, obj2, nContacts, + int n = dCollide (geom1, geom2, nContacts, &contacts[0].geom, sizeof(dContact)); if (n == 0) Modified: branches/multiphys/spark/lib/oxygen/physicsserver/space.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/space.h 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/lib/oxygen/physicsserver/space.h 2009-12-03 09:04:19 UTC (rev 113) @@ -95,7 +95,7 @@ geoms. It will look up and notify the corresponding colliders for a potential collision. */ - void HandleCollide(dGeomID obj1, dGeomID obj2); + void HandleCollide(long obj1, long obj2); /** handle the collision between two geoms from which at least one is a space geom Modified: branches/multiphys/spark/plugin/collisionperceptor/touchperceptorhandler.cpp =================================================================== --- branches/multiphys/spark/plugin/collisionperceptor/touchperceptorhandler.cpp 2009-12-02 10:06:02 UTC (rev 112) +++ branches/multiphys/spark/plugin/collisionperceptor/touchperceptorhandler.cpp 2009-12-03 09:04:19 UTC (rev 113) @@ -65,8 +65,8 @@ // to create a contact joint it we must have at least one body to // attach it to. - dBodyID myBody = dGeomGetBody(mCollider->GetODEGeom()); - dBodyID collideeBody = dGeomGetBody(collidee->GetODEGeom()); + dBodyID myBody = dGeomGetBody((dGeomID) mCollider->GetGeomID()); + dBodyID collideeBody = dGeomGetBody((dGeomID) collidee->GetGeomID()); if (myBody == 0 && collideeBody == 0) return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |