# Rotation

Ok… are my brains flown through my ears? Not yet, but…

Here’s what I need. Imagine I have 4 points. By default we assume that X and Y coordinates are like they always are id 2d space (colored black), with a [0;0] at the position as is displayed in the picture. Because of all 4 points are part of Node structure and they all are their children, each of them has a coordinate in space  as a shift from Node’s origin coordinates (or origin point), and this gives that their world coordinates may be completely different.

The task is to define, that I want p3 to become a new local zero point for all this Node (so that p3 will be at local [0;0]), and then to rotate all the Node’s content (all the points) by some degree that way, that if the direction up was before Y, after rotating it will become Y’ (blue), so that if I increase Y by 10 (for example), it will not put it directly UP, but like it’s drawn.

Reading tutorials and forum I understand that this somehow should be done by setLocalRotation or something like that, but then there’s a quaternions and stuff, that desperately trying to squeeze my brains out

Help!

P.S. and also is there a good source to understand that is LocalTransform and WorldTransfrom? I have an unstoppable feeling that the solution is in this “transform/translate/rotate” things…

If i understand correctly, p1,p2, p3 are nodes, aren't they?

if p1 and p2 are children of p3, using the rotate method on p3 will rotate p1 and p2 "around" p3.

to apply a rotation using angle, you can create a Quaternion with a float[3] array representing the yaw roll pitch in radians

btw the rotate method can directly take yaw roll and pitch as parameters.

here are some readings about this

http://www.jmonkeyengine.com/wiki/doku.php/jme3:beginner:hello_node

http://www.jmonkeyengine.com/wiki/doku.php/rotate

nehon said:

If i understand correctly, p1,p2, p3 are nodes, aren't they?
if p1 and p2 are children of p3, using the rotate method on p3 will rotate p1 and p2 "around" p3.
to apply a rotation using angle, you can create a Quaternion with a float[3] array representing the yaw roll pitch in radians
btw the rotate method can directly take yaw roll and pitch as parameters.

here are some readings about this
http://www.jmonkeyengine.com/wiki/doku.php/jme3:beginner:hello_node
http://www.jmonkeyengine.com/wiki/doku.php/rotate

Heh, this articles were the first ones that I read :)
Actually p1,p2 and many others can be like p2 is a child of p1 and etc, but they all are children of The Node (let's name it so, with capital letter). Imagine it like they are apples (p1, p2..) lying in a box (Node). The box is located somewhere (x1,y1,z1) and I am stanging somewhere else (x2;y2;z2) and we are both not standing in the middle of the space-time continuum (0;0;0) :) Then there's an arrow on the apple box with an arrow up. The task is to rotate the box, and all the apples in it so that this arrow will point at me (put the box on one side), but do it so, that for apples, relative to the box, the direction "UP" will remain the same (arrow, or my new blue coordinates).

Let me show it on my project.

The blue box is the center of "object".  This center can be anywhere in x;y;z. Wireframe nodes are "objects" sides. All this sides, as well as colorful nodes with all vertexes are children of "object's" Node. The idea is that blue box is like the center of mass for all "object" sides. And the task I want to achieve now is to create the second side of the "object" (top one. Let's assume that on the screenshow we have a front one) identical to what we have already, with the difference that it should be facing up, and the up direction (height, or Z) should also be rotated. :|

If I understand the tutorials correctly, if I would be able to tell to all "object's" sides (which, again, are the part of a Node, that their center is the blue box, then later on I would just have to place the blue box wherever I want in the world coordinates, and all the sides, all the points, all rotations and etc will "follow" this blue box, saving and drawing everything correctly.

Something like that :)

uh…that's pretty contagious, my brain is bleeding through my ears too

Did you try to attach everything to the blue box node an rotate it?

For me your blue box is the same thing as the pivot node in the tutorial.

Maybe i don't get it.

nehon said:

uh...that's pretty contagious, my brain is bleeding through my ears too :p

Did you try to attach everything to the blue box node an rotate it?
For me your blue box is the same thing as the pivot node in the tutorial.
Maybe i don't get it.

Well, it sure is, actually from the logic point of view... but when I try to make some .rotate, some weird thing happens.. I will experiment a bit more today, maybe I will figure out something.. :|

Just for testing. Imagine if I have something like this:

```Node side = new Node(); Node triangle = new Node(); Node points = new Node(); triangle.addChildren(points); side.addChildren(triangle); rootNode.addChildren(side); points.addChildren(some geometry/spatial); side.scale(20); ```

The question is - will, in result, "some geometry" be 20 times larger? Because in my case it seems that it won't and the size of all objects remains unchanged :(
The same with translation and rotation..

And one more thing. If I do something like Node.rotate(quaternion), this will rotate the object, but for this node the direction up will remain the same. What I want to achieve is not to rotate an object, but to "tell" an object, that his new local coordinate system is also rotated (take a look at the blue coordinate system on my first screen).

If it's possible, this will give me a lot of benefits. Like if I define to myself that the direction up is Y (height values for the terrain) and then rotate "the terrain" by 45 degrees  over X, and with this operation for this terrain it's local coordinate system will also rotate, then I won't have to bother myself there is the right direction if I want to make some hill of this terrain a bit higher - I just increase it's local Y a bit.

Is this possible in JME3?

The problem with scaling is solved. It was my failure that I have hardcoded the generation of spatials via defined coordinates for each point. So this is closed.

But the question about rotating and defining a local coordinate system is still opened.