Move in the direction your node is pointing? [SOLVED]

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
sephoroph
Posts: 7
Joined: Sat Mar 05, 2011 11:42 pm

Move in the direction your node is pointing? [SOLVED]

Post by sephoroph »

Ok my question is how do you move a node locally instead of globally

This is taken from blender
Image

This is the code i use to move my nodes and its all globally :(

Code: Select all

// declared elsewhere in code.. just throwing this in to show what it is
IAnimatedMeshSceneNode* p;

vector3df pos = p->getPosition();
pos.X++;
p->setPosition(pos);

Thanks in advance!
Last edited by sephoroph on Sat Mar 26, 2011 5:57 pm, edited 1 time in total.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: How do you move in the direction your node is pointing?

Post by randomMesh »

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=43205

Welcome to the forums and please try the search function next time.
"Whoops..."
sephoroph
Posts: 7
Joined: Sat Mar 05, 2011 11:42 pm

Post by sephoroph »

Thanks
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

Code: Select all

vector3df getIrrIn(ISceneNode* node)
{
         matrix4 mat = node->getRelativeTransformation(); 
         vector3df in(mat[8],mat[9],mat[10]); 
         in.normalize(); 
         return in;
}

// move node 'forward' or "in" at speed
float speed = 10.0f;
vector3df in = getIrrIn(node);
vector3df pos = node->getPosition();
node->setPosition(pos + in * speed);

node is now moved 10 units in the direction it was 'looking'
Lunacore
Posts: 18
Joined: Sun May 30, 2010 4:01 pm
Location: Berlin (Germany)

Post by Lunacore »

I use math functions for it:

Code: Select all

   vector3df Pos = Object->getPosition();
   vector3df Rot = Object->getRotation();
   u32 fps = driver->getFPS();

   //Calculate
   Pos.X -= sin(Rot.Y*PI/180)*60/fps; 
   Pos.Z -= cos(Rot.Y*PI/180)*60/fps;

   Object->setPosition(Pos);
   Object->updateAbsolutePosition();     
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

Lunacore wrote:I use math functions for it:

Code: Select all

   vector3df Pos = Object->getPosition();
   vector3df Rot = Object->getRotation();
   u32 fps = driver->getFPS();

   //Calculate
   Pos.X -= sin(Rot.Y*PI/180)*60/fps; 
   Pos.Z -= cos(Rot.Y*PI/180)*60/fps;

   Object->setPosition(Pos);
   Object->updateAbsolutePosition();     
just a tip: i think that

Code: Select all

driver->getFPS()
is only an estimate. not accurate. what about using an animator which passes the time in Ms? you could then multiply or whatever:

Code: Select all

pos.X += movespeedPerMsAbsX * timeMs; 
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

just a tip: i think that

Code: Select all

driver->getFPS()
is only an estimate. not accurate. what about using an animator which passes the time in Ms? you could then multiply or whatever:

Code: Select all

pos.X += movespeedPerMsAbsX * timeMs; 
This is correct, the FPS counter is updated every 1,5 seconds, so it is by no means fit to be used in these kinds of calculations, the animator solution is a much better option
Lunacore
Posts: 18
Joined: Sun May 30, 2010 4:01 pm
Location: Berlin (Germany)

Post by Lunacore »

Ohh, I see in the API
virtual s32 irr::video::IVideoDriver::getFPS ( ) const [pure virtual]

Returns current frames per second value.
This value is updated approximately every 1.5 seconds and is only intended to provide a rough guide to the average frame rate.. It is not suitable for use in performing timing calculations or framerate independent movement
But what did you mean with "using using an animator which passes the time in Ms"? Which animator? o0
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

Lunacore wrote:Ohh, I see in the API
virtual s32 irr::video::IVideoDriver::getFPS ( ) const [pure virtual]

Returns current frames per second value.
This value is updated approximately every 1.5 seconds and is only intended to provide a rough guide to the average frame rate.. It is not suitable for use in performing timing calculations or framerate independent movement
But what did you mean with "using using an animator which passes the time in Ms"? Which animator? o0
i mean

create your own animator and add it to a scene node.

once you define whatever behavior.. well here let me show you really quickly

Code: Select all


//pseudo

class myAnimator : public ISceneNodeAnimator
{

custom_member_type* whatever;

f32 move_speed;

public:

   //these methods are required to animated properly
   animateNode(ISceneNode* node, u32 time_in_ms)
{

//do whatever you want to do to node position and/or rotation here

}

ISceneNodeAnimator* createClone(){return this*};

//you can also multi derive this from IEventReceiver, that is how fps cameras work.

};
now just add it to a ISceneNode

Code: Select all


myAnimator* anim;

IMeshSceneNode* node =IMeshSceneNode(mesh);

node->addAnimator(anim);

//now irrlicht will take care of animating that node in a timely manner.

ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Post by nespa »

take here :

Code: Select all

ISceneNode* Node;
vector3df move(X,Y,Z);
matrix4 matrix;

matrix = Node->getRelativeTransformation();
matrix.transformVect(move);
Node->setPosition(move);
where X,Y,Z are the movements each frame relative to local axis;
Post Reply