Code to locally rotate and translate scene nodes

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Code to locally rotate and translate scene nodes

Post by lazerblade »

These functions are based on some some of my code for doing local
transformations. The functions are cleaned up a bit and some bugs are
fixed.

I've directed at least 3-4 people to this code and it was what they needed.
Everybody needs to do local transformations at some point, and it took me
two weeks just to get the buggy version of these functions working.

So for all you n00bs who are having trouble with this, this is your lucky
day!

Enjoy!

Code: Select all


/*
  ==========
    rotateNode -- rotate a scene node locally
  ==========
*/
void rotateNode(irr::scene::ISceneNode *node, irr::core::vector3df rot)
{
    irr::core::matrix4 m;

    m = node->getAbsoluteTransformation();

    irr::core::matrix4 n;
    n.setRotationDegrees(rot);

    m *= n;

    node->setRotation(m.getRotationDegrees());
    node->updateAbsolutePosition();
}


/*
  ==========
    translateNode -- translate a scene node locally
  ==========
*/
void translateNode(ISceneNode *node, vector3df vel)
{
    irr::core::matrix4 m;

    vector3df rot = node->getRotation();
    m.setRotationDegrees(rot);

    m.transformVect(vel);
    node->setPosition(node->getPosition() + vel);
    node->updateAbsolutePosition();
}

Last edited by lazerblade on Fri Nov 19, 2010 4:21 pm, edited 2 times in total.
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: Code to locally rotate and translate scene nodes

Post by shadowslair »

I think you can clean up just a bit more. This looks unused:
lazerblade wrote:

Code: Select all

vector3df fore = vector3df(0,0,1);
lazerblade wrote:and it took me two weeks just to get the buggy version of these functions working.
Lol! :D
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

Yea thanks, that was left over from trying various methods and debugging.

Fixed.
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
Post Reply