Commit 2c203d84 authored by Rogerborg's avatar Rogerborg

https://sourceforge.net/tracker2/index.php?func=detail&aid=2498791&group_id=74339&atid=540678

Expose the collision result position in ISceneNodeAnimatorCollisionResponse, to give more information to the user app.  Thanks again to garritg.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2120 dfc29bdd-3216-0410-991c-e03cc46cb475
parent a4171705
......@@ -28,7 +28,7 @@ namespace scene
\param animator: Collision response animator in which the collision occurred. You can call
this animator's methods to find the node, collisionPoint and/or collision triangle.
\retval true if the collision was handled in the animator. The animator's target
node will *not* be moved to the collision point, but will instead move directly
node will *not* be stopped at the collision point, but will instead move fully
to the location that triggered the collision check.
\retval false if the collision was not handled in the animator. The animator's
target node will be moved to the collision position.
......@@ -141,6 +141,13 @@ namespace scene
//! Returns the last triangle that caused a collision
virtual const core::triangle3df & getCollisionTriangle() const = 0;
//! Returns the position that the target node will be moved to, unless the collision is consumed in a callback).
/**
If you have a collision callback registered, and it consumes the collision, then the
node will ignore the collision and will not stop at this position. Instead, it will
move fully to the position that caused the collision to occur. */
virtual const core::vector3df & getCollisionResultPosition(void) const = 0;
//! Sets a callback interface which will be called if a collision occurs.
/** \param callback: collision callback handler that will be called when a collision
occurs. Set this to 0 to disable the callback.
......
......@@ -151,13 +151,14 @@ void CSceneNodeAnimatorCollisionResponse::animateNode(ISceneNode* node, u32 time
u32 diff = timeMs - LastTime;
LastTime = timeMs;
core::vector3df pos = Object->getPosition();
core::vector3df vel = pos - LastPosition;
CollisionResultPosition = Object->getPosition();
core::vector3df vel = CollisionResultPosition - LastPosition;
FallingVelocity += Gravity * (f32)diff * 0.001f;
CollisionTriangle = RefTriangle;
CollisionPoint = core::vector3df();
CollisionResultPosition = core::vector3df();
core::vector3df force = vel + FallingVelocity;
......@@ -168,13 +169,14 @@ void CSceneNodeAnimatorCollisionResponse::animateNode(ISceneNode* node, u32 time
// TODO: divide SlidingSpeed by frame time
bool f = false;
pos = SceneManager->getSceneCollisionManager()->getCollisionResultPosition(
CollisionResultPosition
= SceneManager->getSceneCollisionManager()->getCollisionResultPosition(
World, LastPosition-Translation,
Radius, vel, CollisionTriangle, CollisionPoint, f, SlidingSpeed, FallingVelocity);
CollisionOccurred = (CollisionTriangle != RefTriangle);
pos += Translation;
CollisionResultPosition += Translation;
if (f)//CollisionTriangle == RefTriangle)
{
......@@ -192,7 +194,7 @@ void CSceneNodeAnimatorCollisionResponse::animateNode(ISceneNode* node, u32 time
collisionConsumed = CollisionCallback->onCollision(*this);
if(!collisionConsumed)
Object->setPosition(pos);
Object->setPosition(CollisionResultPosition);
}
// move camera target
......
......@@ -104,6 +104,8 @@ namespace scene
//! Returns the last triangle that caused a collision.
virtual const core::triangle3df & getCollisionTriangle() const { return CollisionTriangle; }
virtual const core::vector3df & getCollisionResultPosition(void) const { return CollisionResultPosition; }
//! Sets a callback interface which will be called if a collision occurs.
/** \param callback: collision callback handler that will be called when a collision
occurs. Set this to 0 to disable the callback.
......@@ -134,6 +136,7 @@ namespace scene
bool CollisionOccurred;
core::vector3df CollisionPoint;
core::triangle3df CollisionTriangle;
core::vector3df CollisionResultPosition;
ICollisionCallback* CollisionCallback;
};
......
......@@ -24,12 +24,21 @@ public:
if(collisionPoint != ExpectedCollisionPoint)
{
logTestString("*** Error: expected %f %f %f\n",
logTestString("*** Error: collision point, expected %f %f %f\n",
ExpectedCollisionPoint.X, ExpectedCollisionPoint.Y, ExpectedCollisionPoint.Z);
expectedCollisionCallbackPositions = false;
assert(false);
}
const vector3df & nodePosition = animator.getCollisionResultPosition();
if(nodePosition != ExpectedNodePosition)
{
logTestString("*** Error: result position, expected %f %f %f\n",
ExpectedNodePosition.X, ExpectedNodePosition.Y, ExpectedNodePosition.Z);
expectedCollisionCallbackPositions = false;
assert(false);
}
if(animator.getTargetNode() != ExpectedTarget)
{
logTestString("*** Error: wrong node\n");
......@@ -40,10 +49,14 @@ public:
return ConsumeNextCollision;
}
void setNextExpectedCollision(ISceneNode* target, const vector3df& point, bool consume)
void setNextExpectedCollision(ISceneNode* target,
const vector3df& expectedPoint,
const vector3df& expectedPosition,
bool consume)
{
ExpectedTarget = target;
ExpectedCollisionPoint = point;
ExpectedCollisionPoint = expectedPoint;
ExpectedNodePosition = expectedPosition;
ConsumeNextCollision = consume;
}
......@@ -51,6 +64,7 @@ private:
ISceneNode * ExpectedTarget;
vector3df ExpectedCollisionPoint;
vector3df ExpectedNodePosition;
bool ConsumeNextCollision;
};
......@@ -108,7 +122,10 @@ bool collisionResponseAnimator(void)
// Try to move both nodes to the right of the wall.
// This one should be stopped by its animator.
testNode1->setPosition(vector3df(50, 0,0));
collisionCallback.setNextExpectedCollision(testNode1, vector3df(-5.005f, 0, 0), false);
collisionCallback.setNextExpectedCollision(testNode1,
vector3df(-5.005f, 0, 0),
vector3df(-15.005f, 0, 0),
false);
// Whereas this one, by forcing the animator to update its target node, should be
// able to pass through the wall. (In <=1.6 it was stopped by the wall even if
......@@ -141,7 +158,10 @@ bool collisionResponseAnimator(void)
testNode2->setPosition(vector3df(-50, 0, 0));
// We'll consume this collision, so the node will actually move all the way through.
collisionCallback.setNextExpectedCollision(testNode2, vector3df(5.005f, 0, 0), true);
collisionCallback.setNextExpectedCollision(testNode2,
vector3df(5.005f, 0, 0),
vector3df(15.005f, 0, 0),
true);
device->run();
smgr->drawAll();
......@@ -154,7 +174,10 @@ bool collisionResponseAnimator(void)
}
// Now we'll try to move it back to the right and allow it to be stopped.
collisionCallback.setNextExpectedCollision(testNode2, vector3df(-5.005f, 0, 0), false);
collisionCallback.setNextExpectedCollision(testNode2,
vector3df(-5.005f, 0, 0),
vector3df(-15.005f, 0, 0),
false);
testNode2->setPosition(vector3df(50, 0, 0));
device->run();
......
Test suite pass at GMT Thu Jan 22 09:54:41 2009
Test suite pass at GMT Thu Jan 22 10:10:45 2009
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