How to get Object3D radian?

Started by .jayderyu, January 31, 2009, 12:21:09 PM

Previous topic - Next topic

.jayderyu

Pretty simple question. How do I get the Object3D rotation radian value.

EgonOlsen

You mean you want to extract the angles from the rotation matrix? In that case, this might help: http://www.jpct.net/forum2/index.php/topic,576.0.html

paulscode

I assume you are talking about determining what an Object3D's rotations are at a given point in time.  Generally, one would work with the rotation matrix preferably, but it should also be possible to get back some actual rotation angles (not necessarily the ones that were used to get the object into it's current orientation, since there are multiple possible ways to rotate an object to get it into any particular orientation). 

I see that Ego beat me to it :D, the method in that thread looks like what you are after.  I also recall a short discussion about this here.  Similar related topics have popped up in a few other threads as well, but I always seem to have trouble finding old threads. Here is one.

C3R14L.K1L4

Unless you are like me, trying to get maximum performance. If so, we can live without some trigonometric functions (which are rather heavy on hardware, unless done using lookup tables ;)) so, why don't you store the rotation's values (and modifications) on three hashtables for instance (one for each rotation)? Hashtable's access is quite fast...

paulscode

I not sure that a hashtable would work unless you stored some kind of "order of rotations" history.  Problem is that the order you do the rotations in affects the object's orientation.  Consider the situation where you rotated pi/4 around the y-axis, then pi/2 around the x-axis, then pi/4 around the y-axis again.  The orientation would be quite different than if you had just rotated pi/2 around the y-axis then pi/2 around the x-axis.

In any case, it is probably best to just use the rotation matrix to accomplish whatever you are trying to do if possible, rather than retrieving rotation angles.

C3R14L.K1L4

No, I was thinking about the actual (total) rotation angles, like yaw, roll and pitch. For instance, each time I want to rotate an object around the three axis, I set the identity to zero and rotate the object to the value stored on the related hashtable.
It's just that on limited hardware, doing sins and cousines ;) to get the actual angles might drop the framerate, but now that I think, recalculating the rotation matrix may also do the same thing. (It actually depends on jPCT's implementation, CPU / GPU routines and the graphics driver).

fireside

I was wondering about something like this for the lookat function we discussed a short time ago.  How would you break up the rotation to make a slower turn and still end up at the final destination?
click here->Fireside 7 Games<-

EgonOlsen

Quote from: fireside on February 01, 2009, 04:44:42 AM
I was wondering about something like this for the lookat function we discussed a short time ago.  How would you break up the rotation to make a slower turn and still end up at the final destination?
I used to use matrix interpolation for this. The Matrix-class has an interpolate-method. As long as the matrices are not completely different, this works just fine.

.jayderyu

thanks, i'm currently using Egon reference. It works well. Though another issue has some up.


 // create the box
 box = primitiveFactory:getBox(1.0, 1.01);
 box:translate(10, -100, 0);
 box:rotateX(math.pi / 2);
 box:rotateZ(math.pi / 1.333);
 box:setRotationMatrix(luajava.newInstance("com.threed.jpct.Matrix")); // <-- problem & fix line
 ....

The aforementioned problem&fix line above is the problem. There is a rotation and graphic problem
1. Graphic problem. With the line commented out the box looks fine along the Z camera view.(2d view only no rotate around.)
2. With the line in place the box doesn't isn't orientated right.

1fix. with the line comment out the rotation update doesn't work. I just get an endless super fast rotation.(ref 1 above)
2fix. with the line in the rotation works great.(ref 2 above)

here is the rotation update

 // update
 r = playerBody:getRotation();
 angle = _JPCTLib:deriveAngles(player:getRotationMatrix());

 //  Phys2d unfortunatly just adds the total radian making finding the difference unrealist.
 // so setting the radian of angle within 2pi range is forced.
 if(r > (math.pi * 2)) then r = r - (math.pi * 2) end;
 if(r < 0) then r = r + (math.pi * 2) end;
 playerBody:setRotation(r);

 // update the rotation
 shift = r - pAngle.z;
 if(shift ~= 0) then
   player:rotateZ(shift);
 end;


Any suggestions as to why and how to fix it would be helpful.

I also noticed that if I create the new Matrix imidiatly rotating along the Z by 1.333 for orientation doesn't work.

EgonOlsen

Seems to me that someone else is playing around with the box's matrix. By adding the commented line, you create a new matrix, so that the "somebody else" is working on an actually dead reference, hence to rotation and such. But i don't know enough about your code to really comment on this.

.jayderyu