diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp new file mode 100644 index 00000000000..aa49f33bfb2 --- /dev/null +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp @@ -0,0 +1,204 @@ +#pragma warning (disable : 4786) + +#include "KX_SumoPhysicsController.h" +#include "SG_Spatial.h" +#include "SM_Scene.h" +#include "KX_GameObject.h" +#include "KX_MotionState.h" + + + +void KX_SumoPhysicsController::applyImpulse(const MT_Point3& attach, const MT_Vector3& impulse) +{ + SumoPhysicsController::applyImpulse(attach[0],attach[1],attach[2],impulse[0],impulse[1],impulse[2]); +} +void KX_SumoPhysicsController::RelativeTranslate(const MT_Vector3& dloc,bool local) +{ + SumoPhysicsController::RelativeTranslate(dloc[0],dloc[1],dloc[2],local); + +} +void KX_SumoPhysicsController::RelativeRotate(const MT_Matrix3x3& drot,bool local) +{ + double oldmat[12]; + drot.getValue(oldmat); + float newmat[9]; + float *m = &newmat[0]; + double *orgm = &oldmat[0]; + + *m++ = *orgm++;*m++ = *orgm++;*m++ = *orgm++;orgm++; + *m++ = *orgm++;*m++ = *orgm++;*m++ = *orgm++;orgm++; + *m++ = *orgm++;*m++ = *orgm++;*m++ = *orgm++;orgm++; + + SumoPhysicsController::RelativeRotate(newmat,local); +} + +void KX_SumoPhysicsController::SetLinearVelocity(const MT_Vector3& lin_vel,bool local) +{ + SumoPhysicsController::SetLinearVelocity(lin_vel[0],lin_vel[1],lin_vel[2],local); + +} + +void KX_SumoPhysicsController::SetAngularVelocity(const MT_Vector3& ang_vel,bool local) +{ + SumoPhysicsController::SetAngularVelocity(ang_vel[0],ang_vel[1],ang_vel[2],local); +} + +MT_Vector3 KX_SumoPhysicsController::GetVelocity(const MT_Point3& pos) +{ + + float linvel[3]; + SumoPhysicsController::GetVelocity(pos[0],pos[1],pos[2],linvel[0],linvel[1],linvel[2]); + + return MT_Vector3 (linvel); +} + +MT_Vector3 KX_SumoPhysicsController::GetLinearVelocity() +{ + return GetVelocity(MT_Point3(0,0,0)); + +} +void KX_SumoPhysicsController::ApplyTorque(const MT_Vector3& torque,bool local) +{ + SumoPhysicsController::ApplyTorque(torque[0],torque[1],torque[2],local); + +} + +void KX_SumoPhysicsController::ApplyForce(const MT_Vector3& force,bool local) +{ + SumoPhysicsController::ApplyForce(force[0],force[1],force[2],local); +} + +bool KX_SumoPhysicsController::Update(double time) +{ + return SynchronizeMotionStates(time); + +} + +void KX_SumoPhysicsController::SetSimulatedTime(double time) +{ + +} + +void KX_SumoPhysicsController::SetSumoTransform(bool nondynaonly) +{ + SumoPhysicsController::setSumoTransform(nondynaonly); + +} + +void KX_SumoPhysicsController::SuspendDynamics() +{ + SumoPhysicsController::SuspendDynamics(); +} + +void KX_SumoPhysicsController::RestoreDynamics() +{ + SumoPhysicsController::RestoreDynamics(); +} + +SG_Controller* KX_SumoPhysicsController::GetReplica(SG_Node* destnode) +{ + + PHY_IMotionState* motionstate = new KX_MotionState(destnode); + + KX_SumoPhysicsController* physicsreplica = new KX_SumoPhysicsController(*this); + + //parentcontroller is here be able to avoid collisions between parent/child + + PHY_IPhysicsController* parentctrl = NULL; + + if (destnode != destnode->GetRootSGParent()) + { + KX_GameObject* clientgameobj = (KX_GameObject*) destnode->GetRootSGParent()->GetSGClientObject(); + if (clientgameobj) + { + parentctrl = (KX_SumoPhysicsController*)clientgameobj->GetPhysicsController(); + } else + { + // it could be a false node, try the children + NodeList::const_iterator childit; + for ( + childit = destnode->GetSGChildren().begin(); + childit!= destnode->GetSGChildren().end(); + ++childit + ) { + KX_GameObject* clientgameobj = static_cast( (*childit)->GetSGClientObject()); + if (clientgameobj) + { + parentctrl = (KX_SumoPhysicsController*)clientgameobj->GetPhysicsController(); + } + } + } + } + + physicsreplica->PostProcessReplica(motionstate,parentctrl); + + return physicsreplica; +} + + +void KX_SumoPhysicsController::SetObject (SG_IObject* object) +{ + SG_Controller::SetObject(object); + + // cheating here... + KX_GameObject* gameobj = (KX_GameObject*) object->GetSGClientObject(); + gameobj->SetPhysicsController(this); + + +} + + +void KX_SumoPhysicsController::setOrientation(const MT_Quaternion& orn) +{ + SumoPhysicsController::setOrientation( + orn[0],orn[1],orn[2],orn[3]); + +} +void KX_SumoPhysicsController::getOrientation(MT_Quaternion& orn) +{ + + float quat[4]; + + SumoPhysicsController::getOrientation(quat[0],quat[1],quat[2],quat[3]); + + orn = MT_Quaternion(quat); + +} + +void KX_SumoPhysicsController::setPosition(const MT_Point3& pos) +{ + SumoPhysicsController::setPosition(pos[0],pos[1],pos[2]); + +} + +void KX_SumoPhysicsController::setScaling(const MT_Vector3& scaling) +{ + SumoPhysicsController::setScaling(scaling[0],scaling[1],scaling[2]); + +} + +MT_Scalar KX_SumoPhysicsController::GetMass() +{ + return SumoPhysicsController::getMass(); +} + +MT_Vector3 KX_SumoPhysicsController::getReactionForce() +{ + float force[3]; + SumoPhysicsController::getReactionForce(force[0],force[1],force[2]); + return MT_Vector3(force); + +} + +void KX_SumoPhysicsController::setRigidBody(bool rigid) +{ + SumoPhysicsController::setRigidBody(rigid); + +} + + +KX_SumoPhysicsController::~KX_SumoPhysicsController() +{ + + +} diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.h b/source/gameengine/Ketsji/KX_SumoPhysicsController.h new file mode 100644 index 00000000000..523e139fc69 --- /dev/null +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.h @@ -0,0 +1,83 @@ +#ifndef __KX_SUMOPHYSICSCONTROLLER_H +#define __KX_SUMOPHYSICSCONTROLLER_H + +#include "PHY_IPhysicsController.h" +#include "SM_Object.h" // for SM_Callback + +/** + Physics Controller, a special kind of Scene Graph Transformation Controller. + It get's callbacks from Sumo in case a transformation change took place. + Each time the scene graph get's updated, the controller get's a chance + in the 'Update' method to reflect changed. +*/ + +#include "SumoPhysicsController.h" +#include "KX_IPhysicsController.h" + +class KX_SumoPhysicsController : public KX_IPhysicsController, + public SumoPhysicsController + +{ + + +public: + KX_SumoPhysicsController( + class SM_Scene* sumoScene, + DT_SceneHandle solidscene, + class SM_Object* sumoObj, + class PHY_IMotionState* motionstate + ,bool dyna) + : SumoPhysicsController(sumoScene,solidscene,sumoObj,motionstate,dyna), + KX_IPhysicsController(dyna,NULL) + { + }; + virtual ~KX_SumoPhysicsController(); + + void applyImpulse(const MT_Point3& attach, const MT_Vector3& impulse); + virtual void SetObject (SG_IObject* object); + + + void RelativeTranslate(const MT_Vector3& dloc,bool local); + void RelativeRotate(const MT_Matrix3x3& drot,bool local); + void ApplyTorque(const MT_Vector3& torque,bool local); + void ApplyForce(const MT_Vector3& force,bool local); + MT_Vector3 GetLinearVelocity(); + MT_Vector3 GetVelocity(const MT_Point3& pos); + void SetAngularVelocity(const MT_Vector3& ang_vel,bool local); + void SetLinearVelocity(const MT_Vector3& lin_vel,bool local); + + void SuspendDynamics(); + void RestoreDynamics(); + virtual void getOrientation(MT_Quaternion& orn); + virtual void setOrientation(const MT_Quaternion& orn); + + virtual void setPosition(const MT_Point3& pos); + virtual void setScaling(const MT_Vector3& scaling); + virtual MT_Scalar GetMass(); + virtual MT_Vector3 getReactionForce(); + virtual void setRigidBody(bool rigid); + + + virtual SG_Controller* GetReplica(class SG_Node* destnode); + + + void SetSumoTransform(bool nondynaonly); + // todo: remove next line ! + virtual void SetSimulatedTime(double time); + + // call from scene graph to update + virtual bool Update(double time); + + void + SetOption( + int option, + int value + ){ + // intentionally empty + }; + + +}; + +#endif //__KX_SUMOPHYSICSCONTROLLER_H + diff --git a/source/gameengine/Physics/Makefile b/source/gameengine/Physics/Makefile index a3c711e52a2..349c225e7ee 100644 --- a/source/gameengine/Physics/Makefile +++ b/source/gameengine/Physics/Makefile @@ -35,6 +35,6 @@ include nan_definitions.mk SOURCEDIR = source/gameengine/Physics DIR = $(OCGDIR)/gameengine/blphys -DIRS = common Dummy BlOde +DIRS = common Sumo Dummy BlOde include nan_subdirs.mk diff --git a/source/nan_definitions.mk b/source/nan_definitions.mk index fca41aee843..eacd9b9d3a9 100644 --- a/source/nan_definitions.mk +++ b/source/nan_definitions.mk @@ -55,8 +55,8 @@ all debug:: export NAN_MESA ?= /usr/src/Mesa-3.1 export NAN_MOTO ?= $(LCGDIR)/moto export NAN_SOLID ?= $(SRCHOME)/sumo/SOLID-3.0 - export NAN_SUMO ?= $(SRCHOME)/sumo - export NAN_FUZZICS ?= $(SRCHOME)/sumo/Fuzzics + export NAN_SUMO ?= $(SRCHOME)/gameengine/Physics/Sumo + export NAN_FUZZICS ?= $(SRCHOME)/gameengine/Physics/Sumo/Fuzzics export NAN_ODE ?= $(SRCHOME)/ode export NAN_OPENSSL ?= $(LCGDIR)/openssl export NAN_BLENKEY ?= $(LCGDIR)/blenkey