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.
katze555
Posts: 28 Joined: Tue Mar 23, 2010 7:13 pm
Post
by katze555 » Sat Mar 27, 2010 8:11 pm
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.
Acki
Posts: 3496 Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:
Post
by Acki » Tue Mar 30, 2010 11:50 pm
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...
Bear_130278
Posts: 237 Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation
Post
by Bear_130278 » Wed Mar 31, 2010 5:39 am
This is a pepper of the func
))
Do you like VODKA???
katze555
Posts: 28 Joined: Tue Mar 23, 2010 7:13 pm
Post
by katze555 » Wed Mar 31, 2010 9:27 am
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 » Wed Mar 31, 2010 11:22 am
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.
sash
Competition winner
Posts: 35 Joined: Thu Nov 05, 2009 8:46 am
Location: Novosibirsk
Post
by sash » Wed Mar 31, 2010 11:35 am
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 » Wed Mar 31, 2010 2:04 pm
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 » Wed Mar 31, 2010 2:54 pm
yeah, now I see the need of pParent->getAbsoluteTransformation().inverseRotateVect( v );
(updated the code above)
arras
Posts: 1622 Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:
Post
by arras » Wed Mar 31, 2010 4:09 pm
katze555
Posts: 28 Joined: Tue Mar 23, 2010 7:13 pm
Post
by katze555 » Wed Mar 31, 2010 4:53 pm
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 » Wed Mar 31, 2010 6:38 pm
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