Rotate/Move a custom scene node
-
- Posts: 26
- Joined: Fri Jun 19, 2015 6:51 am
Rotate/Move a custom scene node
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 ?
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
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.
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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 26
- Joined: Fri Jun 19, 2015 6:51 am
Re: Rotate/Move a custom scene node
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.
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.
Re: Rotate/Move a custom scene node
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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 26
- Joined: Fri Jun 19, 2015 6:51 am
Re: Rotate/Move a custom scene node
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
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
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.
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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 26
- Joined: Fri Jun 19, 2015 6:51 am
Re: Rotate/Move a custom scene node
For now on I'm using the first solution which is really good because it only takes few lines and is REALLY fluent
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 !
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
You can get the absolute position with getAbsolutePosition().
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 26
- Joined: Fri Jun 19, 2015 6:51 am
Re: Rotate/Move a custom scene node
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
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
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).
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).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 26
- Joined: Fri Jun 19, 2015 6:51 am
Re: Rotate/Move a custom scene node
Yay, it works like a charm!
Thankkk you
Thankkk you