Accessing CollisionResponseAnimator functions

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
aguilmet
Posts: 8
Joined: Sun Feb 18, 2007 8:08 pm

Accessing CollisionResponseAnimator functions

Post 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!
fakin
Posts: 14
Joined: Wed Jan 24, 2007 9:02 pm
Location: zagreb, croatia

Post 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.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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
aguilmet
Posts: 8
Joined: Sun Feb 18, 2007 8:08 pm

Post 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!
Post Reply