I have a camera with a CollisionResponseAnimator and I need to change the gravity. How would I access the isFalling and setGravity functions of the SceneNodeAnimatorCollisionResponse class through the camera? Is it even possible? Is something like camera->getAnimators[0]->setGravity(1.0f) starting on the right track?
Thanks very much!
Accessing CollisionResponseAnimator functions
Code: Select all
createCollisionResponseAnimator(selector, camera,
vector3df(30.0f, 60.0f, 30.0f), // ellipsoid radius
vector3df(0,-100,0), // now this is your gravity
vector3df(0.0f, 0.0f, 0.0f),0);
Code: Select all
vector3df gravity = vector3df(0.0f, -1.0f, 0.0f);
Code: Select all
createCollisionResponseAnimator
Why can't you just keep a pointer to the collision animator and then just call setGravity() or isFalling() on it. If you don't want to keep a pointer to that animator, then you can always search for it...
Code: Select all
scene::ISceneNodeAnimator* findSceneNodeAnimator(scene::ISceneNode* node, ESCENE_NODE_ANIMATOR_TYPE type)
{
core::list<ISceneNodeAnimator*>::Iterator begin = node->getAnimators().begin();
core::list<ISceneNodeAnimator*>::Iterator end = node->getAnimators().end();
for (/**/; begin != end; ++begin)
{
scene::ISceneNodeAnimator* animator = *begin;
if (animator->getType() == type)
{
return animator;
}
}
return 0;
}
scene::ISceneNodeAnimatorCollisionResponse* findSceneNodeAnimator_CollisionResponse(scene::ISceneNode* node)
{
return (scene::ISceneNodeAnimatorCollisionResponse*)findSceneNodeAnimator(node, ESNAT_COLLISION_RESPONSE);
}
// use it like this
scene::ISceneNodeAnimatorCollisionResponse* animator =
findSceneNodeAnimator_CollisionResponse(node);
if (animator)
animator->setGravity(core::vector3df(0, 0, 0)); // disable gravity
I got it! Since ISceneNodeAnimatorCollisionResponse is just a subclass of ISceneNodeAnimator I declare the camera animator like this:
ISceneNodeAnimatorCollisionResponse* camanim=blah...
Then just to change the gravity in realtime, I just call camanim->setGravity(blah);
The Camera follows the animator's properties even after you apply it to the camera. I found that this is alot faster than creating a new one and applying it to the camera every time I need to change gravity. I can just change it directly in the animator. Thank you for your help!
ISceneNodeAnimatorCollisionResponse* camanim=blah...
Then just to change the gravity in realtime, I just call camanim->setGravity(blah);
The Camera follows the animator's properties even after you apply it to the camera. I found that this is alot faster than creating a new one and applying it to the camera every time I need to change gravity. I can just change it directly in the animator. Thank you for your help!