-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTPhysicsController.cpp
executable file
·68 lines (57 loc) · 1.9 KB
/
HTPhysicsController.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "HTPhysicsController.h"
#include <dtUtil/log.h>
HTPhysicsController::HTPhysicsController(dtCore::Base* msgSender) :
dtCore::ODEController(msgSender),
m_MaxPhysicsStep(0),
mPhysicsTimeRemaining(0)
{
}
HTPhysicsController::~HTPhysicsController()
{
}
//To compile: need to make mCollidableContents and Step()
// protected in dtCore/odecontroller.h or use delta3d > 2.2.0
void HTPhysicsController::Iterate(double deltaFrameTime)
{
double stepSize = deltaFrameTime;
// if step size is set, use it instead of the delta frame time
if (GetPhysicsStepSize() > 0.0)
{
stepSize = GetPhysicsStepSize();
}
TransformableVector::const_iterator it;
#if DELTA3D_VER >= 23
for (it = GetRegisteredCollidables().begin();
it != GetRegisteredCollidables().end(); it++)
#else
for (it = mCollidableContents.begin();
it != mCollidableContents.end(); it++ )
#endif
{
(*it)->PrePhysicsStepUpdate();
}
mPhysicsTimeRemaining += deltaFrameTime;
if ((m_MaxPhysicsStep != 0.0) && (mPhysicsTimeRemaining > m_MaxPhysicsStep)) {
//limit the number of steps to avoid big jumps
dtUtil::Log::GetInstance().LogMessage(dtUtil::Log::LOG_DEBUG,__FUNCTION__, __LINE__,"Time step of %f exceeded maximum physics step",mPhysicsTimeRemaining);
mPhysicsTimeRemaining = m_MaxPhysicsStep;
}
//do physics steps, saving the left-over for the next frame
while (mPhysicsTimeRemaining > stepSize)
{
Step(stepSize);
mPhysicsTimeRemaining -= stepSize;
}
//for (it = GetRegisteredCollidables().begin(); //use this for delta3d > 2.2.0
// it != GetRegisteredCollidables().end();
#if DELTA3D_VER >= 23
for (it = GetRegisteredCollidables().begin();
it != GetRegisteredCollidables().end(); it++)
#else
for (it = mCollidableContents.begin();
it != mCollidableContents.end(); it++ )
#endif
{
(*it)->PostPhysicsStepUpdate();
}
}