[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/games/astrododge/src
From: Rivo Laks <rivolaks () hot ! ee>
Date: 2009-08-07 18:06:25
Message-ID: 1249668385.439898.29344.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1008531 by rivol:
Much better simulation time handling.
A constant timestep is always used now which fixes problems with the simulation being dependant
on the framerate.
M +7 -7 gameworld.cpp
M +1 -0 gameworld.h
M +3 -3 ship.cpp
--- trunk/playground/games/astrododge/src/gameworld.cpp #1008530:1008531
@@ -87,6 +87,7 @@
mTime = 0.0f;
mTrackActive = false;
mTrackTime = 0.0f;
+ mAdvanceTime = 0.0f;
}
GameWorld::~GameWorld()
@@ -111,21 +112,20 @@
// ODE doesn't like too big timesteps. If time elapsed is bigger than
// maxtimestep then we'll simulate in multiple iterations.
- const float maxtimestep = 0.040;
- for (float done = 0; done < elapsed; done += maxtimestep) {
- float thisstep = qMin(elapsed - done, maxtimestep);
-
+ const float timestep = 0.040;
+ mAdvanceTime += elapsed;
+ for (; mAdvanceTime >= timestep; mAdvanceTime -= timestep) {
// Clear previous collision contacts
dJointGroupEmpty(mOdeContactGroup);
// Calculate collisions
dSpaceCollide(mOdeSpace, this, &nearCallback);
// Advance the simulation
- dWorldQuickStep(mOdeWorld, thisstep);
+ dWorldQuickStep(mOdeWorld, timestep);
processContactFeedbacks();
for (int i = 0; i < mObjects.count(); i++) {
- mObjects[i]->advance(elapsed);
+ mObjects[i]->advance(timestep);
}
processTrackPoints();
@@ -327,7 +327,7 @@
void GameWorld::slotRotateShip(float dx, float dy, float dz)
{
- mShip->rotvelocity += Vector3f(dx, -dy, dz) * 200;
+ mShip->rotvelocity += Vector3f(dx, -dy, dz) * 50;
}
void GameWorld::applyShipRotation(float elapsed)
--- trunk/playground/games/astrododge/src/gameworld.h #1008530:1008531
@@ -111,6 +111,7 @@
QList<Vector3f> mTrack;
float mTrackTime;
bool mTrackActive;
+ float mAdvanceTime;
dWorldID mOdeWorld;
dSpaceID mOdeSpace;
--- trunk/playground/games/astrododge/src/ship.cpp #1008530:1008531
@@ -22,7 +22,7 @@
Ship::Ship() : GameObject(8)
{
- acceleration = 1000;
+ acceleration = 400;
thrust = 1.0f;
rotvelocity = Vector3f(0, 0, 0);
@@ -54,7 +54,7 @@
dBodySetAngularVel(body, angvel[0] * damp, angvel[1] * damp, angvel[2] * damp);
const dReal* linvel = dBodyGetLinearVel(body);
- const float linDamp = 0.99f;
+ const float linDamp = 0.98f;
dBodySetLinearVel(body, linvel[0]*linDamp, linvel[1]*linDamp, linvel[2]*linDamp);
}
@@ -79,7 +79,7 @@
return;
}
- const int multiplier = 800000;
+ const int multiplier = 400000;
dBodyAddRelForce(body, x*multiplier, y*multiplier, 0);
timeToDodgeReload = 2.0f;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic