setAbsolutePosition()

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
katze555
Posts: 28
Joined: Tue Mar 23, 2010 7:13 pm

setAbsolutePosition()

Post by katze555 »

i want to set the absolute position of a node which has a parent. Anyone has a function for this?

When searching u find this:

Code: Select all

static void setAbsolutePosition(ISceneNode *pNode,vector3df& pos )
{   
   if ( !pNode )
      return;

     ISceneNode *pParent =  pNode->getParent();

     if ( !pParent )
       pNode->setPosition( pos );
     else
     {
         vector3df v( pos - pParent->getAbsolutePosition() );
             pParent->getAbsoluteTransformation().inverseRotateVect( v );
            pNode->setPosition( v );
      } // end else
            pNode->updateAbsolutePosition();
} 

but it does not work
________
Cavalier
Last edited by katze555 on Thu Feb 24, 2011 7:41 am, edited 1 time in total.
katze555
Posts: 28
Joined: Tue Mar 23, 2010 7:13 pm

Post by katze555 »

any ideas ?????
________
Mexico hotels
Last edited by katze555 on Thu Feb 24, 2011 7:42 am, edited 1 time in total.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

the function should work, at least it does for me...
maybe call updateAbsolutePosition on the nodes before calling the function... ;)

but I'm not sure what this pParent->getAbsoluteTransformation().inverseRotateVect(v); call is for, I think you should remove it...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post by Bear_130278 »

This is a pepper of the func 8)))
Do you like VODKA???
Image
Image
katze555
Posts: 28
Joined: Tue Mar 23, 2010 7:13 pm

Post by katze555 »

Acki wrote: but I'm not sure what this pParent->getAbsoluteTransformation().inverseRotateVect(v); call is for, I think you should remove it...
if i remove this, then the function does nothing at all, this is the line the function is all about. u said it worked for u? could u post your example code were it worked?
________
MAZDA NAVAJO SPECIFICATIONS
Last edited by katze555 on Thu Feb 24, 2011 7:42 am, edited 1 time in total.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Code: Select all

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

void setAbsolutePosition(ISceneNode *pNode, vector3df pos){
  if(!pNode) return;
  ISceneNode *pParent =  pNode->getParent();

  if(!pParent)
    pNode->setPosition(pos);
  else{
    pParent->updateAbsolutePosition();
    vector3df v(pos - pParent->getAbsolutePosition());
    pParent->getAbsoluteTransformation().inverseRotateVect( v );
    pNode->setPosition(v);
  }
  pNode->updateAbsolutePosition();
}

int main(){
	IrrlichtDevice *device = createDevice(EDT_DIRECT3D9);
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

  ISceneNode* n1 = smgr->addCubeSceneNode(10);
  n1->setPosition(vector3df(10,0,50));
  n1->setRotation(vector3df(0,45,0));

  ISceneNode* n2 = smgr->addCubeSceneNode(10);
  n2->setParent(n1);

  setAbsolutePosition(n2, vector3df(10,15,50));

  smgr->addCameraSceneNodeFPS();
	while(device->run()){
		driver->beginScene(true, true, video::SColor(0,222,220,220));
		smgr->drawAll();
		driver->endScene();
	}
	device->drop();
	return 0;
}
Last edited by Acki on Wed Mar 31, 2010 2:52 pm, edited 1 time in total.
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
sash
Competition winner
Posts: 35
Joined: Thu Nov 05, 2009 8:46 am
Location: Novosibirsk

Post by sash »

There is more interesting thing - is how to set absoluteRotation for a node with partent. No one tried yet ? :)
katze555
Posts: 28
Joined: Tue Mar 23, 2010 7:13 pm

Post by katze555 »

sash wrote:There is more interesting thing - is how to set absoluteRotation for a node with partent. No one tried yet ? :)
i got that in this threat: http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=37898
________
Hero Honda Cbz History
Last edited by katze555 on Thu Feb 24, 2011 7:42 am, edited 1 time in total.
katze555
Posts: 28
Joined: Tue Mar 23, 2010 7:13 pm

Post by katze555 »

well, i tried your code, Acki, and it didnt work for me. i rotated the parent and the child always had a different position, i cannot imagine thats its working correct on your machine... this function must be incorrect!! we need a correct setAbsolutePosition() function!!
________
Gift cards
Last edited by katze555 on Thu Feb 24, 2011 7:42 am, edited 1 time in total.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

:lol: yeah, now I see the need of pParent->getAbsoluteTransformation().inverseRotateVect( v ); :lol:
(updated the code above)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

My be code I posted here can help you somehow:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=35341
katze555
Posts: 28
Joined: Tue Mar 23, 2010 7:13 pm

Post by katze555 »

ok, now the code works.... the only problem i guess is the scale, my parent is scaled and so it doesnt work. if i remove the scaling it works perfectly.
________
Genetically Modified Food
Last edited by katze555 on Thu Feb 24, 2011 7:42 am, edited 1 time in total.
katze555
Posts: 28
Joined: Tue Mar 23, 2010 7:13 pm

Post by katze555 »

yeeeah, it f****** works 100%, i used arra's solution, it works perfectly.... after almost a week i finally got it!!! now noone can stop me anymore!!
________
ACTROS
Post Reply