BGE: New isDynamicSuspended python attribute
[blender.git] / source / gameengine / Physics / common / PHY_IPhysicsController.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file PHY_IPhysicsController.h
29  *  \ingroup phys
30  */
31
32 #ifndef __PHY_IPHYSICSCONTROLLER_H__
33 #define __PHY_IPHYSICSCONTROLLER_H__
34
35 #include <vector>
36 #include "PHY_IController.h"
37
38 class PHY_IMotionState;
39 class PHY_IPhysicsEnvironment;
40
41 class MT_Vector3;
42 class MT_Point3;
43 class MT_Matrix3x3;
44
45 class KX_GameObject;
46 class RAS_MeshObject;
47
48 /**
49  * PHY_IPhysicsController is the abstract simplified Interface to a physical object.
50  * It contains the IMotionState and IDeformableMesh Interfaces.
51  */
52 class PHY_IPhysicsController : public PHY_IController
53 {
54
55         public:
56                 virtual ~PHY_IPhysicsController(){};
57                 /**
58                  * SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
59                  */
60                 virtual bool            SynchronizeMotionStates(float time)=0;
61                 /**
62                  * WriteMotionStateToDynamics ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
63                  */
64                 
65                 virtual void            WriteMotionStateToDynamics(bool nondynaonly)=0;
66                 virtual void            WriteDynamicsToMotionState()=0;
67                 virtual class PHY_IMotionState* GetMotionState() = 0;
68                 // controller replication
69                 virtual void            PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl)=0;
70                 virtual void            SetPhysicsEnvironment(class PHY_IPhysicsEnvironment *env)=0;
71
72                 // kinematic methods
73                 virtual void            RelativeTranslate(const MT_Vector3& dloc,bool local)=0;
74                 virtual void            RelativeRotate(const MT_Matrix3x3&,bool local)=0;
75                 virtual MT_Matrix3x3    GetOrientation()=0;
76                 virtual void            SetOrientation(const MT_Matrix3x3& orn)=0;
77                 virtual void            SetPosition(const MT_Vector3& pos)=0;
78                 virtual void            GetPosition(MT_Vector3& pos) const=0;
79                 virtual void            SetScaling(const MT_Vector3& scale)=0;
80                 virtual void            SetTransform()=0;
81
82                 virtual MT_Scalar       GetMass()=0;
83                 virtual void            SetMass(MT_Scalar newmass)=0;
84
85                 // physics methods
86                 virtual void            ApplyImpulse(const MT_Point3& attach, const MT_Vector3& impulse,bool local)=0;
87                 virtual void            ApplyTorque(const MT_Vector3& torque,bool local)=0;
88                 virtual void            ApplyForce(const MT_Vector3& force,bool local)=0;
89                 virtual void            SetAngularVelocity(const MT_Vector3& ang_vel,bool local)=0;
90                 virtual void            SetLinearVelocity(const MT_Vector3& lin_vel,bool local)=0;
91                 virtual void            ResolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ) = 0;
92
93                 virtual float           GetLinearDamping() const=0;
94                 virtual float           GetAngularDamping() const=0;
95                 virtual void            SetLinearDamping(float damping)=0;
96                 virtual void            SetAngularDamping(float damping)=0;
97                 virtual void            SetDamping(float linear, float angular)=0;
98
99                 virtual void            SuspendDynamics(bool ghost=false)=0;
100                 virtual void            RestoreDynamics()=0;
101
102                 virtual void            SetActive(bool active)=0;
103
104                 // reading out information from physics
105                 virtual MT_Vector3      GetLinearVelocity()=0;
106                 virtual MT_Vector3      GetAngularVelocity()=0;
107                 virtual MT_Vector3      GetVelocity(const MT_Point3& pos)=0;
108                 virtual MT_Vector3      GetLocalInertia()=0;
109
110                 // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted 
111                 virtual void            SetRigidBody(bool rigid)=0;
112
113                 virtual PHY_IPhysicsController* GetReplica() {return 0;}
114                 virtual PHY_IPhysicsController* GetReplicaForSensors() {return 0;}
115
116                 virtual void    CalcXform() =0;
117                 virtual void SetMargin(float margin) =0;
118                 virtual float GetMargin() const=0;
119                 virtual float GetRadius() const=0;
120                 virtual void  SetRadius(float margin) = 0;
121
122                 virtual float GetLinVelocityMin() const=0;
123                 virtual void  SetLinVelocityMin(float val) = 0;
124                 virtual float GetLinVelocityMax() const=0;
125                 virtual void  SetLinVelocityMax(float val) = 0;
126                 
127                 MT_Vector3      GetWorldPosition(MT_Vector3& localpos);
128
129                 // Shape control
130                 virtual void    AddCompoundChild(PHY_IPhysicsController* child) = 0;
131                 virtual void    RemoveCompoundChild(PHY_IPhysicsController* child) = 0;
132
133
134                 virtual bool IsDynamic() = 0;
135                 virtual bool IsCompound() = 0;
136                 virtual bool IsSuspended() const = 0;
137
138                 virtual bool ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj) = 0;
139
140                 /* Method to replicate rigid body joint contraints for group instances. */
141                 virtual void ReplicateConstraints(KX_GameObject *gameobj, std::vector<KX_GameObject*> constobj) = 0;
142
143 #ifdef WITH_CXX_GUARDEDALLOC
144         MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_IPhysicsController")
145 #endif
146 };
147
148 #endif  /* __PHY_IPHYSICSCONTROLLER_H__ */