4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
29 #ifndef __SUMO_PHYSICSCONTROLLER_H
30 #define __SUMO_PHYSICSCONTROLLER_H
32 #include "PHY_IPhysicsController.h"
34 #include "SM_Callback.h"
37 * Sumo Physics Controller, a special kind of a PhysicsController.
38 * A Physics Controller is a special kind of Scene Graph Transformation Controller.
39 * Each time the scene graph get's updated, the controller get's a chance
40 * in the 'Update' method to reflect changes.
42 * Sumo uses the SOLID library for collision detection.
44 class SumoPhysicsController : public PHY_IPhysicsController , public SM_Callback
51 SumoPhysicsController(
52 class SM_Scene* sumoScene,
53 class SM_Object* sumoObj,
54 class PHY_IMotionState* motionstate,
57 virtual ~SumoPhysicsController();
60 * @name Kinematic Methods.
63 virtual void RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local);
65 * @param drot a 3x4 matrix. This will treated as a 3x3 rotation matrix.
66 * @warning RelativeRotate expects a 3x4 matrix. The fourth column is padding.
68 virtual void RelativeRotate(const float drot[12],bool local);
69 virtual void getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal);
70 virtual void setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal);
71 virtual void setPosition(float posX,float posY,float posZ);
72 virtual void getPosition(PHY__Vector3& pos) const;
74 virtual void setScaling(float scaleX,float scaleY,float scaleZ);
78 * @name Physics Methods
81 virtual void ApplyTorque(float torqueX,float torqueY,float torqueZ,bool local);
82 virtual void ApplyForce(float forceX,float forceY,float forceZ,bool local);
83 virtual void SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local);
84 virtual void SetLinearVelocity(float lin_velX,float lin_velY,float lin_velZ,bool local);
85 virtual void resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
86 virtual void applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ);
87 virtual void SetActive(bool active){};
88 virtual void SuspendDynamics();
89 virtual void RestoreDynamics();
94 * reading out information from physics
96 virtual void GetLinearVelocity(float& linvX,float& linvY,float& linvZ);
98 * GetVelocity parameters are in geometric coordinates (Origin is not center of mass!).
100 virtual void GetVelocity(const float posX,const float posY,const float posZ,float& linvX,float& linvY,float& linvZ);
101 virtual float getMass();
102 virtual void getReactionForce(float& forceX,float& forceY,float& forceZ);
103 virtual void setRigidBody(bool rigid);
106 virtual void PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl);
108 // TODO: remove next line !
109 virtual void SetSimulatedTime(float time);
111 virtual void WriteDynamicsToMotionState() {};
112 virtual void WriteMotionStateToDynamics(bool nondynaonly);
115 * call from Scene Graph Node to 'update'.
117 virtual bool SynchronizeMotionStates(float time);
119 virtual void calcXform();
120 virtual void SetMargin(float margin) ;
121 virtual float GetMargin() const;
122 virtual float GetRadius() const ;
125 // clientinfo for raycasts for example
126 virtual void* getNewClientInfo();
127 virtual void setNewClientInfo(void* clientinfo);
129 float getFriction() { return m_friction;}
130 float getRestitution() { return m_restitution;}
135 virtual void do_me();
137 class SM_Object* GetSumoObject ()
142 void GetWorldOrientation(class MT_Matrix3x3& mat);
143 void GetWorldPosition(MT_Point3& pos);
144 void GetWorldScaling(MT_Vector3& scale);
147 // void SetSumoObject(class SM_Object* sumoObj) {
148 // m_sumoObj = sumoObj;
150 // void SetSumoScene(class SM_Scene* sumoScene) {
151 // m_sumoScene = sumoScene;
154 void setSumoTransform(bool nondynaonly);
158 class SM_Object* m_sumoObj;
159 class SM_Scene* m_sumoScene; // needed for replication
167 bool m_suspendDynamics;
170 bool m_bFullRigidBody;
171 bool m_bPhantom; // special flag for objects that are not affected by physics 'resolver'
173 // data to calculate fake velocities for kinematic objects (non-dynas)
175 bool m_bPrevKinematic;
179 class PHY_IMotionState* m_MotionState;
184 #endif //__SUMO_PHYSICSCONTROLLER_H