Commit fb49a86e authored by cutealien's avatar cutealien

Several fixes for SceneNodeAnimatorCollisionResponse, based on...

Several fixes for SceneNodeAnimatorCollisionResponse, based on http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=33098&p=290746
Thanks to all people who reported and to JLouisB and kinkreet for the patches:
- Gravity is now fps independent
- Values of gravity now like documented (wasn't 1 unit = 1m before, had been 1m = current frames per second, so maybe 100 units = 1m). 
  Note that jump-values for fps-camera must also change when adapting gravity!
  Several examples got adapted for new ranges
- Pausing timer now pauses animator. Also doesn't reset values anymore with pauses.
- Clones no longer have 1000 times the gravity of original animator.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5305 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 960be376
--------------------------
Changes in 1.9 (not yet released)
- Several fixes for SceneNodeAnimatorCollisionResponse, based on http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=33098&p=290746
Thanks to all people who reported and to JLouisB and kinkreet for the patches:
- Gravity is now fps independent
- Values of gravity now like documented (wasn't 1 unit = 1m before, had been 1m = current frames per second, so maybe 100 units = 1m).
Note that jump-values for fps-camera must also change when adapting gravity!
Several examples got adapted for new ranges.
- Pausing timer now pauses animator. Also doesn't reset values anymore with pauses.
- Clones no longer have 1000 times the gravity of original animator.
should now be fps independentn
- Speedup CTriangleSelector (mainly for animated meshes)
- CTriangleSelector now supports 32-bit meshbuffers. Thanks @Wol101 for reporting and patch-proposal.
- Fix: CTriangleSelector no longer resets it's boundingbox to 0,0,0 (was wrong when a meshbuffer was not around 0)
......
......@@ -119,7 +119,7 @@ int main()
values, the camera will be able to move closer to walls after this. The
next parameter is the direction and speed of gravity. We'll set it to
(0, -10, 0), which approximates to realistic gravity, assuming that our
units are metres. You could set it to (0,0,0) to disable gravity. And the
units are meters. You could set it to (0,0,0) to disable gravity. And the
last value is just a translation: Without this, the ellipsoid with which
collision detection is done would be around the camera, and the camera would
be in the middle of the ellipsoid. But as human beings, we are used to have our
......@@ -132,7 +132,7 @@ int main()
// Set a jump speed of 3 units per second, which gives a fairly realistic jump
// when used with the gravity of (0, -10, 0) in the collision response animator.
scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0, 100.0f, .3f, ID_IsNotPickable, 0, 0, true, 3.f);
smgr->addCameraSceneNodeFPS(0, 100.0f, .3f, ID_IsNotPickable, 0, 0, true, 300.f);
camera->setPosition(core::vector3df(50,50,-60));
camera->setTarget(core::vector3df(-70,30,-60));
......@@ -140,7 +140,7 @@ int main()
{
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(30,50,30),
core::vector3df(0,-10,0), core::vector3df(0,30,0));
core::vector3df(0,-1000,0), core::vector3df(0,30,0));
selector->drop(); // As soon as we're done with the selector, drop it.
camera->addAnimator(anim);
anim->drop(); // And likewise, drop the animator when we're done referring to it.
......
......@@ -316,7 +316,7 @@ void Q3Player::create ( IrrlichtDevice *device, IQ3LevelMesh* mesh, ISceneNode *
keyMap[9].Action = EKA_CROUCH;
keyMap[9].KeyCode = KEY_KEY_C;
camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 0.6f, -1, keyMap, 10, false, 0.6f);
camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 0.6f, -1, keyMap, 10, false, 600.f);
camera->setName ( "First Person Camera" );
//camera->setFOV ( 100.f * core::DEGTORAD );
camera->setFarValue( 20000.f );
......
......@@ -735,10 +735,10 @@ s32 Q3StartPosition ( IQ3LevelMesh* mesh,
*/
vector3df getGravity ( const c8 * surface )
{
if ( 0 == strcmp ( surface, "earth" ) ) return vector3df ( 0.f, -90.f, 0.f );
if ( 0 == strcmp ( surface, "moon" ) ) return vector3df ( 0.f, -6.f / 100.f, 0.f );
if ( 0 == strcmp ( surface, "water" ) ) return vector3df ( 0.1f / 100.f, -2.f / 100.f, 0.f );
if ( 0 == strcmp ( surface, "ice" ) ) return vector3df ( 0.2f / 100.f, -9.f / 100.f, 0.3f / 100.f );
if ( 0 == strcmp ( surface, "earth" ) ) return vector3df ( 0.f, -900.f, 0.f );
if ( 0 == strcmp ( surface, "moon" ) ) return vector3df ( 0.f, -6.f , 0.f );
if ( 0 == strcmp ( surface, "water" ) ) return vector3df ( 0.1f, -2.f, 0.f );
if ( 0 == strcmp ( surface, "ice" ) ) return vector3df ( 0.2f, -9.f, 0.3f );
return vector3df ( 0.f, 0.f, 0.f );
}
......
......@@ -328,14 +328,14 @@ void CDemo::switchToNextScene()
keyMap[8].Action = EKA_JUMP_UP;
keyMap[8].KeyCode = KEY_KEY_J;
camera = sm->addCameraSceneNodeFPS(0, 100.0f, .4f, -1, keyMap, 9, false, 3.f);
camera = sm->addCameraSceneNodeFPS(0, 100.0f, .4f, -1, keyMap, 9, false, 300.f);
camera->setPosition(core::vector3df(108,140,-140));
camera->setFarValue(5000.0f);
scene::ISceneNodeAnimatorCollisionResponse* collider =
sm->createCollisionResponseAnimator(
metaSelector, camera, core::vector3df(25,50,25),
core::vector3df(0, quakeLevelMesh ? -10.f : 0.0f,0),
core::vector3df(0, quakeLevelMesh ? -1000.f : 0.0f,0),
core::vector3df(0,45,0), 0.005f);
camera->addAnimator(collider);
......
......@@ -164,13 +164,13 @@ void CSceneNodeAnimatorCollisionResponse::animateNode(ISceneNode* node, u32 time
FirstUpdate = false;
}
const u32 diff = timeMs - LastTime;
const f32 diffSec = (f32)(timeMs - LastTime)*0.001f;
LastTime = timeMs;
CollisionResultPosition = Object->getPosition();
core::vector3df vel = CollisionResultPosition - LastPosition;
FallingVelocity += Gravity * (f32)diff * 0.001f;
FallingVelocity += Gravity * diffSec;
CollisionTriangle = RefTriangle;
CollisionPoint = core::vector3df();
......@@ -188,12 +188,14 @@ void CSceneNodeAnimatorCollisionResponse::animateNode(ISceneNode* node, u32 time
= SceneManager->getSceneCollisionManager()->getCollisionResultPosition(
World, LastPosition-Translation,
Radius, vel, CollisionTriangle, CollisionPoint, f,
CollisionNode, SlidingSpeed, FallingVelocity);
CollisionNode, SlidingSpeed, FallingVelocity*diffSec);
CollisionOccurred = (CollisionTriangle != RefTriangle);
CollisionResultPosition += Translation;
if ( diffSec > 0 ) // don't change the state when there was no time
{
if (f)//CollisionTriangle == RefTriangle)
{
Falling = true;
......@@ -203,6 +205,7 @@ void CSceneNodeAnimatorCollisionResponse::animateNode(ISceneNode* node, u32 time
Falling = false;
FallingVelocity.set(0, 0, 0);
}
}
bool collisionConsumed = false;
......@@ -269,7 +272,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorCollisionResponse::createClone(ISceneNode*
CSceneNodeAnimatorCollisionResponse * newAnimator =
new CSceneNodeAnimatorCollisionResponse(newManager, World, Object, Radius,
(Gravity * 1000.0f), Translation, SlidingSpeed);
Gravity, Translation, SlidingSpeed);
newAnimator->cloneMembers(this);
return newAnimator;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment