Page 1 of 1

Rotate/Move a custom scene node

Posted: Wed Aug 05, 2015 12:14 pm
by BillyCallahan
Hello,

I'm working on triggering the rotation of my custom scene node with a left button click.
For some reasons I don't want to move the camera around it, I want my node to move/rotate (which is the same result for the user).
I tried to use pNode->setPosition() but this is too random as I never know which side will move...Currently I'm changing each vertex's position, but with a big structure it's REALLY slow : I've to modify 14 vertex * 600 custom node each time I move my mouse.

Do you have any solution :) ?

Re: Rotate/Move a custom scene node

Posted: Wed Aug 05, 2015 4:13 pm
by CuteAlien
You want your node to rotated around itself or around the camera? Or around the camera-node but the camera should constantly look at the node (in which case you see no rotation at all unless there are more objects).

I suspect you mean around itself as that's the only one where it can look similar as when the camera would rotate around it.
pNode->setRotation should allow you to do that.

Re: Rotate/Move a custom scene node

Posted: Wed Aug 05, 2015 8:27 pm
by BillyCallahan
Actually not, I want all my nodes to rotate around the barycentre (center of gravity) of the structure.
Imagine a house made of a lot of custom node (all the same for now), you want to see the bottom, then the top. Without moving the camera, you can rotate the structure around the center of gravity but in Irrlicht it means setPosition of each nodes. :D

Re: Rotate/Move a custom scene node

Posted: Wed Aug 05, 2015 9:27 pm
by CuteAlien
Or make them all childs of one node at the center. Then you only need to rotate that node and all it's childs rotate around it.

Re: Rotate/Move a custom scene node

Posted: Thu Aug 06, 2015 7:23 am
by BillyCallahan
It works great :)
Unfortunately my nodes' position is now relative to the barycentre, so when I do customNode->setParent(barycentre) every nodes chnage their position and the (0,0,0) is now the barycentre.
I know that's the purpose of parent/children stuff, but is there a way to disable that and enable it later ?

For now on I just set every node's position to {position - barycentre} so the barycentre is in the middle :)

Re: Rotate/Move a custom scene node

Posted: Thu Aug 06, 2015 8:39 am
by CuteAlien
Once you work with parents/childs that is something you have to live with.

There is another solution as well. Instead of working with parents you can do those calculations yourself. Meaning you work with a matrix for the rotation. Play around with the matrix class - it has functions to set it up easily (setting positions and rotations) and then you change your node-postions by using one of the vector transform functions in the matrix.

Re: Rotate/Move a custom scene node

Posted: Thu Aug 06, 2015 1:32 pm
by BillyCallahan
For now on I'm using the first solution which is really good because it only takes few lines and is REALLY fluent :D
The problem now is trying to select a node, when the node has moved during the rotation, his absolute position did change but his relative didn't. Unfortunately we can't get the absolute position, so when I'm using "getRayFromScreenCoordinates" the user thinks he's pointing at the node but he is not...Working on it !

Re: Rotate/Move a custom scene node

Posted: Thu Aug 06, 2015 1:40 pm
by CuteAlien
You can get the absolute position with getAbsolutePosition().

Re: Rotate/Move a custom scene node

Posted: Thu Aug 06, 2015 1:55 pm
by BillyCallahan
Sorry for the misunderstanding, I need the absolute position of each vertex.
When I launch a Ray i check the intersection with every triangle of my node, in order to do that I need every vertex's absolute position :)

Re: Rotate/Move a custom scene node

Posted: Thu Aug 06, 2015 3:56 pm
by CuteAlien
Transforming local coordinates to global coordinates is pretty simple. Get your local coordinate and then transform it with sceneNode->getAbsoluteTransformation().transformVect(&myLocalVector).
Depending on where you need that you might have to call updateAbsolutePosition() once for the node first (that's otherwise updated in rendering so your positions would be outdated 1 frame).

Re: Rotate/Move a custom scene node

Posted: Fri Aug 07, 2015 7:01 am
by BillyCallahan
Yay, it works like a charm!
Thankkk you :D