enable bullet for vc7 too by default (can be switched off easily)
[blender.git] / source / gameengine / Ketsji / KX_OdePhysicsController.cpp
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * The contents of this file may be used under the terms of either the GNU
7  * General Public License Version 2 or later (the "GPL", see
8  * http://www.gnu.org/licenses/gpl.html ), or the Blender License 1.0 or
9  * later (the "BL", see http://www.blender.org/BL/ ) which has to be
10  * bought from the Blender Foundation to become active, in which case the
11  * above mentioned GPL option does not apply.
12  *
13  * The Original Code is Copyright (C) 2002 by NaN Holding BV.
14  * All rights reserved.
15  *
16  * The Original Code is: all of this file.
17  *
18  * Contributor(s): none yet.
19  *
20  * ***** END GPL/BL DUAL LICENSE BLOCK *****
21  */
22 #include "KX_ConvertPhysicsObject.h"
23
24 #ifdef USE_ODE
25
26 #include "KX_OdePhysicsController.h"
27 #include "KX_GameObject.h"
28 #include "KX_MotionState.h"
29
30 #include "MT_assert.h"
31
32 #include "PHY_IPhysicsEnvironment.h"
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 KX_OdePhysicsController::KX_OdePhysicsController(
39                                                                                                  bool dyna,
40                                                                                                  bool fullRigidBody,
41                                                                                                  bool phantom,
42                                                                                                  class PHY_IMotionState* motionstate,
43                                                                                                  struct dxSpace* space,
44                                                                                                  struct dxWorld*        world,
45                                                                                                  float  mass,
46                                                                                                  float  friction,
47                                                                                                  float  restitution,
48                                                                                                  bool   implicitsphere,
49                                                                                                  float  center[3],
50                                                                                                  float  extends[3],
51                                                                                                  float  radius
52                                                                                                  ) 
53 : KX_IPhysicsController(dyna,(PHY_IPhysicsController*)this),
54 ODEPhysicsController(
55 dyna,fullRigidBody,phantom,motionstate,
56 space,world,mass,friction,restitution,
57 implicitsphere,center,extends,radius)
58 {
59 };
60
61
62 bool    KX_OdePhysicsController::Update(double time)
63 {
64         return SynchronizeMotionStates(time);
65 }
66
67 void                    KX_OdePhysicsController::SetObject (SG_IObject* object)
68 {
69         SG_Controller::SetObject(object);
70
71         // cheating here...
72         KX_GameObject* gameobj = (KX_GameObject*)       object->GetSGClientObject();
73         gameobj->SetPhysicsController(this);
74         
75 }
76
77
78
79 void    KX_OdePhysicsController::applyImpulse(const MT_Point3& attach, const MT_Vector3& impulse)
80 {
81         ODEPhysicsController::applyImpulse(attach[0],attach[1],attach[2],impulse[0],impulse[1],impulse[2]);
82 }
83         
84
85
86 void    KX_OdePhysicsController::RelativeTranslate(const MT_Vector3& dloc,bool local)
87 {
88         ODEPhysicsController::RelativeTranslate(dloc[0],dloc[1],dloc[2],local);
89
90 }
91 void    KX_OdePhysicsController::RelativeRotate(const MT_Matrix3x3& drot,bool local)
92 {
93         double oldmat[12];
94         drot.getValue(oldmat);
95         float newmat[9];
96         float *m = &newmat[0];
97         double *orgm = &oldmat[0];
98
99          *m++ = *orgm++;*m++ = *orgm++;*m++ = *orgm++;orgm++;
100          *m++ = *orgm++;*m++ = *orgm++;*m++ = *orgm++;orgm++;
101          *m++ = *orgm++;*m++ = *orgm++;*m++ = *orgm++;orgm++;
102
103          ODEPhysicsController::RelativeRotate(newmat,local);
104
105 }
106
107 void    KX_OdePhysicsController::ApplyTorque(const MT_Vector3& torque,bool local)
108 {
109                 ODEPhysicsController::ApplyTorque(torque[0],torque[1],torque[2],local);
110
111 }
112 void    KX_OdePhysicsController::ApplyForce(const MT_Vector3& force,bool local)
113 {
114                 ODEPhysicsController::ApplyForce(force[0],force[1],force[2],local);
115
116 }
117 MT_Vector3 KX_OdePhysicsController::GetLinearVelocity()
118 {
119         return MT_Vector3(0,0,0);
120 }
121
122 MT_Vector3 KX_OdePhysicsController::GetVelocity(const MT_Point3& pos)
123 {
124         return MT_Vector3(0,0,0);
125 }
126
127 void    KX_OdePhysicsController::SetAngularVelocity(const MT_Vector3& ang_vel,bool local)
128 {
129
130 }
131 void    KX_OdePhysicsController::SetLinearVelocity(const MT_Vector3& lin_vel,bool local)
132 {
133         ODEPhysicsController::SetLinearVelocity(lin_vel[0],lin_vel[1],lin_vel[2],local);
134 }
135
136 void KX_OdePhysicsController::setOrientation(const MT_Quaternion& orn)
137 {
138         ODEPhysicsController::setOrientation(orn[0],orn[1],orn[2],orn[3]);
139 }
140
141 void KX_OdePhysicsController::getOrientation(MT_Quaternion& orn)
142 {
143         float florn[4];
144         florn[0]=orn[0];
145         florn[1]=orn[1];
146         florn[2]=orn[2];
147         florn[3]=orn[3];
148         ODEPhysicsController::getOrientation(florn[0],florn[1],florn[2],florn[3]);
149         orn[0] = florn[0];
150         orn[1] = florn[1];
151         orn[2] = florn[2];
152         orn[3] = florn[3];
153
154
155 }
156
157 void KX_OdePhysicsController::setPosition(const MT_Point3& pos)
158 {
159         ODEPhysicsController::setPosition(pos[0],pos[1],pos[2]);
160 }
161
162 void KX_OdePhysicsController::setScaling(const MT_Vector3& scaling)
163 {
164 }
165
166 MT_Scalar       KX_OdePhysicsController::GetMass()
167 {
168         return ODEPhysicsController::getMass();
169 }
170
171 MT_Vector3      KX_OdePhysicsController::getReactionForce()
172 {
173         return MT_Vector3(0,0,0);
174 }
175 void    KX_OdePhysicsController::setRigidBody(bool rigid)
176 {
177
178 }
179
180 void    KX_OdePhysicsController::SuspendDynamics()
181 {
182         ODEPhysicsController::SuspendDynamics();
183 }
184 void    KX_OdePhysicsController::RestoreDynamics()
185 {
186         ODEPhysicsController::RestoreDynamics();
187 }
188         
189
190 SG_Controller*  KX_OdePhysicsController::GetReplica(class SG_Node* destnode)
191 {
192         PHY_IMotionState* motionstate = new KX_MotionState(destnode);
193         KX_OdePhysicsController* copyctrl = new KX_OdePhysicsController(*this);
194
195         // nlin: copied from KX_SumoPhysicsController.cpp. Not 100% sure what this does....
196         // furthermore, the parentctrl is not used in ODEPhysicsController::PostProcessReplica, but
197         // maybe it can/should be used in the future...
198
199         // begin copy block ------------------------------------------------------------------
200
201         //parentcontroller is here be able to avoid collisions between parent/child
202
203         PHY_IPhysicsController* parentctrl = NULL;
204
205         if (destnode != destnode->GetRootSGParent())
206         {
207                 KX_GameObject* clientgameobj = (KX_GameObject*) destnode->GetRootSGParent()->GetSGClientObject();
208                 if (clientgameobj)
209                 {
210                         parentctrl = (KX_OdePhysicsController*)clientgameobj->GetPhysicsController();
211                 } else
212                 {
213                         // it could be a false node, try the children
214                         NodeList::const_iterator childit;
215                         for (
216                                 childit = destnode->GetSGChildren().begin();
217                         childit!= destnode->GetSGChildren().end();
218                         ++childit
219                                 ) {
220                                 KX_GameObject* clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
221                                 if (clientgameobj)
222                                 {
223                                         parentctrl = (KX_OdePhysicsController*)clientgameobj->GetPhysicsController();
224                                 }
225                         }
226                 }
227         }
228         // end copy block ------------------------------------------------------------------
229
230         copyctrl->PostProcessReplica(motionstate, this);
231
232         return copyctrl;
233         
234 }
235
236 void            KX_OdePhysicsController::resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ)
237 {
238 }
239
240         
241 void    KX_OdePhysicsController::SetSumoTransform(bool nondynaonly)
242 {
243
244 }
245         // todo: remove next line !
246 void    KX_OdePhysicsController::SetSimulatedTime(double time)
247 {
248
249 }
250         
251 #endif //USE_ODE