Page 1 of 1

Accessing CollisionResponseAnimator functions

Posted: Wed Feb 21, 2007 3:41 pm
by aguilmet
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!

Posted: Thu Feb 22, 2007 1:44 pm
by fakin

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);
now if you want to change it in real-time i suggest you declare

Code: Select all

vector3df gravity = vector3df(0.0f, -1.0f, 0.0f);
before you create collision response animator, and use 'gravity' vector as a argument for

Code: Select all

createCollisionResponseAnimator
then when you want to change it real-time just make another collision response animator and apply it to camera. in fact you don't even need 'gravity' vector. but you got the point. if that's what you've been asking.

Posted: Thu Feb 22, 2007 4:40 pm
by vitek
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

Posted: Thu Feb 22, 2007 11:45 pm
by aguilmet
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!