Page 1 of 1

setAbsolutePosition()

Posted: Sat Mar 27, 2010 8:11 pm
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

Posted: Tue Mar 30, 2010 10:18 pm
by katze555
any ideas ?????
________
Mexico hotels

Posted: Tue Mar 30, 2010 11:50 pm
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...

Posted: Wed Mar 31, 2010 5:39 am
by Bear_130278
This is a pepper of the func 8)))

Posted: Wed Mar 31, 2010 9:27 am
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

Posted: Wed Mar 31, 2010 11:22 am
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;
}

Posted: Wed Mar 31, 2010 11:35 am
by sash
There is more interesting thing - is how to set absoluteRotation for a node with partent. No one tried yet ? :)

Posted: Wed Mar 31, 2010 11:56 am
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

Posted: Wed Mar 31, 2010 2:04 pm
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

Posted: Wed Mar 31, 2010 2:54 pm
by Acki
:lol: yeah, now I see the need of pParent->getAbsoluteTransformation().inverseRotateVect( v ); :lol:
(updated the code above)

Posted: Wed Mar 31, 2010 4:09 pm
by arras
My be code I posted here can help you somehow:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=35341

Posted: Wed Mar 31, 2010 4:53 pm
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

Posted: Wed Mar 31, 2010 6:38 pm
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