~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/gameengine/Physics/Sumo/SumoPhysicsController.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * @file $Id: SumoPhysicsController.cpp,v 1.9 2004/05/06 02:13:07 kester Exp $
 
2
 * @file $Id: SumoPhysicsController.cpp,v 1.15 2005/03/25 16:31:05 sirdude Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
35
35
#include "SM_Object.h"
36
36
#include "MT_Quaternion.h"
37
37
 
38
 
#ifdef HAVE_CONFIG_H
39
 
#include <config.h>
40
 
#endif
41
38
 
42
39
SumoPhysicsController::SumoPhysicsController(
43
40
                                class SM_Scene* sumoScene,
54
51
{
55
52
        if (m_sumoObj)
56
53
        {
57
 
                //m_sumoObj->setClientObject(this);
 
54
 
 
55
                PHY__Vector3 pos1;
 
56
                getPosition(pos1);
 
57
                MT_Point3 pos(pos1);
 
58
                
 
59
                //temp debugging check
 
60
                //assert(pos.length() < 100000.f);
 
61
 
 
62
                //need this to do the upcast after the solid/sumo collision callback
 
63
                m_sumoObj->setPhysicsClientObject(this);
58
64
                //if it is a dyna, register for a callback
59
65
                m_sumoObj->registerCallback(*this);
60
66
        }
78
84
        if (m_sumoObj)
79
85
        {
80
86
                const SM_ShapeProps *shapeprops = m_sumoObj->getShapeProps();
81
 
                return shapeprops->m_mass;
 
87
                if(shapeprops!=NULL) return shapeprops->m_mass;
82
88
        }
83
89
        return 0.f;
84
90
}
85
91
 
86
 
bool SumoPhysicsController::SynchronizeMotionStates(float time)
 
92
bool SumoPhysicsController::SynchronizeMotionStates(float)
87
93
{
88
 
 
89
94
        if (m_bFirstTime)
90
95
        {
91
 
                setSumoTransform(false);
 
96
                setSumoTransform(!m_bFirstTime);
92
97
                m_bFirstTime = false;
93
98
        }
94
 
 
95
 
        if (!m_bDyna)
96
 
        {
97
 
                if (m_sumoObj)
98
 
                {
99
 
                        MT_Point3 pos;
100
 
                        GetWorldPosition(pos);
101
 
 
102
 
                        m_sumoObj->setPosition(pos);
103
 
                        if (m_bDyna)
104
 
                        {
105
 
                                m_sumoObj->setScaling(MT_Vector3(1,1,1));
106
 
                        } else
107
 
                        {
108
 
                                MT_Vector3 scaling;
109
 
                                GetWorldScaling(scaling);
110
 
                                m_sumoObj->setScaling(scaling);
111
 
                        }
112
 
                        MT_Matrix3x3 orn;
113
 
                        GetWorldOrientation(orn);
114
 
                        m_sumoObj->setOrientation(orn.getRotation());
115
 
                        m_sumoObj->calcXform();
116
 
                }
117
 
        }
118
 
        return false; // physics object are not part of
119
 
                                 // hierarchy, or ignore it ??
 
99
        return false;
120
100
}
121
101
 
122
102
 
131
111
 
132
112
}
133
113
 
 
114
void SumoPhysicsController::getPosition(PHY__Vector3&   pos) const
 
115
{
 
116
        assert(m_sumoObj);
 
117
 
 
118
        pos[0] = m_sumoObj->getPosition()[0];
 
119
        pos[1] = m_sumoObj->getPosition()[0];
 
120
        pos[2] = m_sumoObj->getPosition()[0];
 
121
 
 
122
        //m_MotionState->getWorldPosition(pos[0],pos[1],pos[2]);
 
123
}
 
124
 
134
125
void SumoPhysicsController::GetWorldPosition(MT_Point3& pos)
135
126
{
 
127
//      assert(m_sumoObj);
 
128
 
 
129
//      pos[0] = m_sumoObj->getPosition()[0];
 
130
//      pos[1] = m_sumoObj->getPosition()[0];
 
131
//      pos[2] = m_sumoObj->getPosition()[0];
 
132
 
136
133
        float worldpos[3];
137
134
        m_MotionState->getWorldPosition(worldpos[0],worldpos[1],worldpos[2]);
138
135
        pos[0]=worldpos[0];
200
197
 
201
198
void            SumoPhysicsController::setScaling(float scaleX,float scaleY,float scaleZ)
202
199
{
203
 
        m_sumoObj->setScaling(MT_Vector3(scaleX,scaleY,scaleZ));
 
200
        if (!m_bDyna)
 
201
                m_sumoObj->setScaling(MT_Vector3(scaleX,scaleY,scaleZ));
204
202
}
205
203
        
206
204
        // physics methods
262
260
        }
263
261
}
264
262
 
265
 
void SumoPhysicsController::resolveCombinedVelocities(
266
 
                const MT_Vector3 & lin_vel,
267
 
                const MT_Vector3 & ang_vel
268
 
        )
 
263
void            SumoPhysicsController::resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ)
269
264
{
270
265
        if (m_sumoObj)
271
 
                m_sumoObj->resolveCombinedVelocities(lin_vel, ang_vel);
 
266
                m_sumoObj->resolveCombinedVelocities(MT_Vector3(linvelX,linvelY,linvelZ),MT_Vector3(angVelX,angVelY,angVelZ));
272
267
}
273
268
 
274
269
 
 
270
 
 
271
 
275
272
void            SumoPhysicsController::applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ)
276
273
{
277
274
        if (m_sumoObj)
396
393
        m_sumoScene->add(* (m_sumoObj));
397
394
}
398
395
 
399
 
void                    SumoPhysicsController::SetSimulatedTime(float time)
 
396
void                    SumoPhysicsController::SetSimulatedTime(float)
400
397
{
401
398
}
402
399
        
403
400
        
404
 
void    SumoPhysicsController::WriteMotionStateToDynamics(bool nondynaonly)
 
401
void    SumoPhysicsController::WriteMotionStateToDynamics(bool)
405
402
{
406
403
 
407
404
}
410
407
 
411
408
void SumoPhysicsController::do_me()
412
409
{
 
410
        MT_assert(m_sumoObj);
413
411
        const MT_Point3& pos = m_sumoObj->getPosition();
414
412
        const MT_Quaternion& orn = m_sumoObj->getOrientation();
415
413
 
 
414
        MT_assert(m_MotionState);
416
415
        m_MotionState->setWorldPosition(pos[0],pos[1],pos[2]);
417
416
        m_MotionState->setWorldOrientation(orn[0],orn[1],orn[2],orn[3]);
418
417
}
444
443
                }
445
444
        }
446
445
}
 
446
 
 
447
 
 
448
        // clientinfo for raycasts for example
 
449
void*                           SumoPhysicsController::getNewClientInfo()
 
450
{
 
451
        if (m_sumoObj)
 
452
                return m_sumoObj->getClientObject();
 
453
        return 0;
 
454
 
 
455
}
 
456
void                            SumoPhysicsController::setNewClientInfo(void* clientinfo)
 
457
{
 
458
        if (m_sumoObj)
 
459
        {
 
460
                SM_ClientObject* clOb = static_cast<SM_ClientObject*> (clientinfo);
 
461
                m_sumoObj->setClientObject(clOb);
 
462
        }
 
463
 
 
464
}
 
465
 
 
466
void    SumoPhysicsController::calcXform()
 
467
{
 
468
        if (m_sumoObj)
 
469
                m_sumoObj->calcXform();
 
470
}
 
471
 
 
472
void SumoPhysicsController::SetMargin(float margin) 
 
473
{
 
474
        if (m_sumoObj)
 
475
                m_sumoObj->setMargin(margin);
 
476
}
 
477
 
 
478
float SumoPhysicsController::GetMargin() const
 
479
{
 
480
        if (m_sumoObj)
 
481
                m_sumoObj->getMargin();
 
482
        return 0.f;
 
483
}
 
484
 
 
485
float SumoPhysicsController::GetRadius() const 
 
486
{
 
487
        if (m_sumoObj && m_sumoObj->getShapeProps())
 
488
        {
 
489
                return m_sumoObj->getShapeProps()->m_radius;
 
490
        }
 
491
        return 0.f;
 
492
 
 
493
}