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
master
cutealien 2016-06-04 19:54:19 +00:00
parent 960be376dd
commit fb49a86eb6
6 changed files with 37 additions and 25 deletions

View File

@ -1,6 +1,15 @@
--------------------------
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)

View File

@ -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.

View File

@ -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 );
@ -385,7 +385,7 @@ void Q3Player::respawn ()
StartPositionCurrent, cam()->getEllipsoidTranslation()))
StartPositionCurrent = 0;
else
++StartPositionCurrent;
++StartPositionCurrent;
}
/*
@ -2021,7 +2021,7 @@ void CQuake3EventHandler::Animate()
wchar_t msg[128];
IVideoDriver * driver = Game->Device->getVideoDriver();
#ifdef _IRR_SCENEMANAGER_DEBUG
#ifdef _IRR_SCENEMANAGER_DEBUG
IAttributes * attr = Game->Device->getSceneManager()->getParameters();
swprintf_irr ( msg, 128,
L"Q3 %s [%ls], FPS:%03d Tri:%.03fm Cull %d/%d nodes (%d,%d,%d)",
@ -2042,8 +2042,8 @@ swprintf_irr ( msg, 128,
driver->getName(),
driver->getFPS (),
(f32) driver->getPrimitiveCountDrawn( 0 ) * ( 1.f / 1000000.f )
);
#endif
);
#endif
Game->Device->setWindowCaption( msg );
swprintf_irr ( msg, 128,

View File

@ -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 );
}

View File

@ -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);

View File

@ -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,20 +188,23 @@ 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 (f)//CollisionTriangle == RefTriangle)
if ( diffSec > 0 ) // don't change the state when there was no time
{
Falling = true;
}
else
{
Falling = false;
FallingVelocity.set(0, 0, 0);
if (f)//CollisionTriangle == RefTriangle)
{
Falling = true;
}
else
{
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;
}