node->SetPosition()

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
xtravanta
Posts: 9
Joined: Tue Nov 09, 2010 11:18 am

node->SetPosition()

Post by xtravanta »

Hi,

Iam trying to update the position of my node.. but for some weird reason it doesn't go to the place iam telling it to go to....

example:

Code: Select all



ISceneNode *Spawn = spawnPoint[nr].Node; // the spawnpoint it needs to spawn on..

player[active].Node->setPosition(Spawn->getPosition());


Spawn->getPosition(); // this gives me a good position

but if i set it to the player node it isnt the correct one.. ( weird thing about this ) the position is never the same when it is set

if i check it before i set the new position it is always the same..

printf("%f,%f,%f\n", Spawn.X,Spawn.Y,Spawn.Z);


so maby somebody has a sollution for this..

Thx..
pepeshka
Posts: 29
Joined: Wed Jul 02, 2008 8:42 pm

Post by pepeshka »

get and setPosition() return co-ords relative to the node's parent - do the player node and the spawn node both have the same parent? Have you tried using the absolute positions?
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

this simply sounds like you need to use

Code: Select all

getAbsolutePosition()
xtravanta
Posts: 9
Joined: Tue Nov 09, 2010 11:18 am

Post by xtravanta »

the player node are add manualy like this

Code: Select all

IMesh *mesh = smgr->getMesh("player.obj");
ISceneNode *node = smgr->addMeshSceneNode(mesh);
and the spawn node is added using a .irr file.

Code: Select all

smgr->loadScene("scene.irr");
after this iam looping over all of the nodes to create a meta selector depending on the type of node..

i dont know if the parent node is the same then. :oops:


//edit
getAbsolutePosition() also doesnt work... already tried that..

//edit

getAbsolutePosition() and getPosition() give the same values..
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

It is highly probable they don't have the same parent node, so try and make sure, or else, set all the parent's position to 0,

Getting the absolute positions will return you the positions in world space indeed, but setting the position will set the position relative to the parent of that node, that is, the real position will be the parent's position + the absolute position of the spawning point.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
xtravanta
Posts: 9
Joined: Tue Nov 09, 2010 11:18 am

Post by xtravanta »

Mel wrote:set all the parent's position to 0
uhm.. how ?:P

iam loading it from a irr file and while looping over all of the nodes setting its postion to 0.. this will f*ck up my complete world :) becuase all of the nodes have there own position in the irr file :)

and after setting it to 0 all the nodes will be on the same spot..

or do you mean something else ?
Anthony
Posts: 121
Joined: Sun Jan 09, 2011 12:03 pm

Post by Anthony »

Code: Select all

smgr->addMeshSceneNode( mesh, parentNode, ...more neat initial values to get aquint with :) );

mesh->setParent( parent )
Do you have an IDE with some sort of intellisence, it would be a great help as you can see all overload and default values of functions.

If not, or as second source of information, the source code (F12 in MSVC jumps right to the implementation)gives a lot - if not all - information.

Third or first ;) source of information would be the documentation -> top nav bar -> all options. That will bring you right to the advanced forum. Hmmm, well I haven't been discovered in the advanced forum yet either :oops:


EDIT:
An absolute position is the position of the object you call. They are the coord on the scene.

The other position is the relative. It's the position of the object away from the parent.

Thus:

Code: Select all

PSEUDO
parent->setPosition( 1, 0, 2 );

childOfParent->setPosition( 3, 1, 4 );

childOfParent->getAbsolutePosition(); <- returns vector3df( 4, 1, 6 );

childOfParent->setPosition( -3, 1, 4 );

childOfParent->getAbsolutePosition(); <- returns vector3df( -2, 1, 6 );
No :shock: I am no noob, just checking if your not one too :roll:

Thanks to Niko and all others that made Irrlicht possible.
xtravanta
Posts: 9
Joined: Tue Nov 09, 2010 11:18 am

Post by xtravanta »

uhm.. i'am not getting it to work... is there a way to force it to (0,0,0) on some way ( just temporarly ) untill i know how it works??

Greetzz
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

but if i set it to the player node it isnt the correct one.. ( weird thing about this ) the position is never the same when it is set
Plz elaborate. This may uncover the reason why you can't get it to work.
Post Reply