Dependent Rotations

Hi ppl I am having problems with objects rotation, what I wanted was that when object A rotated object B also rotated in the same way, for example if object A was to rotate 90

Couldn't you just apply the same transform to B? Or is the B update not aware of that transform?

Not really sure on the question, so this answer may be way off …



Alric said:

Couldn't you just apply the same transform to B? Or is the B update not aware of that transform?

At first i thought it would be like that BUT the rotation component in the modelview matrix is not how much the object has to rotate but the rotation to the origin, so to know how much he has really rotated I must compare it to is last matrix.

theprism said:

Not really sure on the question, so this answer may be way off ...



I wanted to do something like that but I only know how to extract quaternion from the matrix, not angles, and then I dont know how to extract non Euler angles from quaternions...

so this is what I am doing at the moment

        Vector3f xrO = new Vector3f(matrixOld[0], matrixOld[1], matrixOld[2]);
        Vector3f yrO = new Vector3f(matrixOld[4], matrixOld[5], matrixOld[6]);
        Vector3f zrO = new Vector3f(matrixOld[8], matrixOld[9], matrixOld[10]);
        Vector3f xO = xrO.normalize();
        Vector3f yO = yrO.normalize();
        Vector3f zO = zrO.normalize();
        Quaternion orientationOld = new Quaternion();
        orientationOld.fromAxes(xO, yO, zO);

        Vector3f xrN = new Vector3f(matrixNew[0], matrixNew[1], matrixNew[2]);
        Vector3f yrN = new Vector3f(matrixNew[4], matrixNew[5], matrixNew[6]);
        Vector3f zrN = new Vector3f(matrixNew[8], matrixNew[9], matrixNew[10]);
        Vector3f xN = xrN.normalize();
        Vector3f yN = yrN.normalize();
        Vector3f zN = zrN.normalize();
        Quaternion orientationOld = new Quaternion();
        orientationOld.fromAxes(xrN, yrN, zrN);

       Quaternion orientation = new Quaternion();
       orientation = orientationN.subtract(orientationO);
       //This part is needed cause the modelview matrix from the AR library is not using the same orientation that jme
       Quaternion z180 = new Quaternion();
        z180.fromAngleAxis((float) Math.PI, Vector3f.UNIT_Z);
        //end part


Ahh, in that case multiply degress using FastMath.DEG_TO_RAD

fromAngles(320* FastMath.DEG_TO_RAD,  180 * FastMath.DEG_TO_RAD, 20* FastMath.DEG_TO_RAD)

Can I do such a thing ? I thought Euler angles were a lot more complex than normal angles :S

If both nodes have different initial positions then, as you suggested, you’ll need to keep track of the previous position (i.e. in your update method).

Assuming that your source node is rotated by the only means of its local rotation, and given:

Node source;

Node target;

Quaternion sourcePreviousOrientation;

First you need to find out the quaternion that represents the rotation from the previous to the current rotation.

Given quaternions q1 and q2 representing two orientations, the quaternion q’ = q^(-1) * q2 is the rotation that will rotate from the q1 orientation to the q2 orientation ( I think the same principle is used in SLERP, but jME implementation of SLERP is overkill for your needs, but think of it if you need to smoothly interpolate between your source model’s orientation and target model’s orientation.

To do such calculation:

Quaternion sourceCurrentOrientation = source.getLocalRotation();

Quaternion rotation = sourcePreviousOrientation.inverse().mult(sourceCurrentOrientation);

And now you can rotate your target node:

target.getLocalRotation().multLocal (rotation);

However, doing it this way will likely accumulate error. You’d rather store and use both node’s initial positions, and refer to them in your calculations. I leave this up to you to think of ;).

Hope it helps. I never did this so the maths could be wrong.

Well I tried your way and it didnt work lol BUT I went and studied more about SLERP and used it to interpolate and it worked like a charm :wink: thanks for the cool tip, I guess like you said this is over kill, but this is project is more a proof of concept then a real game.

Just to complete the thread, can you post your solution ??

I haven't posted it yet cause that like a charm become false when i tried to apply the rotation to an object that had a rotation of more then 180

I knocked you up an example of what i was suggesting

I really dont think that it would solve my problems cause I really need to use the quaternion :s, I have made a video where you can see my problem.

explanation: The moving marker is the one from each I get the model view matrix, the other markers are part of a border that gives me the rotation quaternion to use when the marker is occlude.

As you can see I am having strange problems, one of them is the differences between the alignments, when it is not facing the same way as the border it will rotate :S, the other is harder to understand, if you look closely when I occluded the model the first time  (facing the same way as the border) the model will start hovering the marker instead of rotating normally, I think this is due to the centrer of the other quaternion being different from the centrer of the marker… but I really dont know.

Any clues on how I can correct this ?

I think the solution jjmontes gave must be the right one BUT i am getting really strange problems… I am aplying to the objects node the movement that the board made, but it is moving in a strange way like if it had acceleration …

Lets see if I can explain using this drwaing, the blacks squares are the game board and  I always have its center (black dot) so when I dont have the "blue square" information I wanted to be able to move and rotate him using the center position.

What I am trying now is to have a node that moves and rotates using the boards centrer and when I dont have the "blue square" info I just attach it to that node and it would move with it, like in the planet and moon example.
But I aint getting it to work right :S I am having problems with both the rotation and translation...

I first wanted to correct the translation part, and what is happening is that the model also rotates a litle to that side and stretches... any idea of what may be doing this ?

Sorry. I have seen the video and read your last post but I still can't get what your problem is.

In the video I can see that the model follows the marker position and rotation quite correctly.

What are you trying to achieve, when you hide the marker under the rubber?

jjmontes said:

In the video I can see that the model follows the marker position and rotation quite correctly.

What are you trying to achieve, when you hide the marker under the rubber?

Yap when the camera detects the marker it will track it easily, my problem is when it gets obfuscated or gets out of the view of the camera, I would like to be able to keep track of the model 3d positions even when the camera didnt detect them. So the use of the rubber is to force this kind of problem.

In the video the marker with the model is the blue marker( in the drawing) and the other markers are the black ones.
The data I recieve form the AR part is in the form of a model view matrix and I can get one from the "blue marker" and a different one from the board (they all together form a type of big marker so by detecting one marker I can know the positions of entire board).

The problem am I having with the movement of the obfuscated model is that when I move the camera, he will gradually strechs diagonally that way, for example if I move the camera to the left it would do:

    |||                    ///             
    |||        ->        ///           
__|||___        __///__     

This is a college project where me and my partner are trying to implement a game engine for turn based games using Augmented Reality, and in the end it will be freely distributed ,so any help or tip would be really appreciated ;)

Hi. I have the same problem, Im doing a project with jME and Augmented Reality too, but I cant aproach the correct orientation and traslation of the models.

Here is a related problem.

I think they are problems with the same technology but different aspects, I only have problems with obfuscated markers not with the ones that are detected.

Sorry uipe.

Still, I struggle to understand the problem. It is my understanding that when you occlude the model marker, you still can detect the board. As the board is assumed to be static, I think all you need is to update the camera, and leave the model at its last known position. and orientation…  :?

no problem jjmontes I know its hard tu understand, and bvelieve me its even harder to try to explain… But no moving the camera its a big no no :S cause i would lose the reference :S tomorrow I will try to do a better diagram :wink:

And I have been getting some improvements with moving and rotating the "board node".