www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: alex on May 07, 2009, 11:18:09 am

Title: How to reset direction of object
Post by: alex on May 07, 2009, 11:18:09 am
I want to reset  objects which  are rotated ,but I can't get the direction when these objects are Loaded.
these objects has been roteted (by rotateX()),i try to get original direction of these(by getOrigin() ),bescause of i didn't use setOrigin() giving these a original direction ,i can't get the direction i needed .
 how can i get the direction ?
thanks.
Title: Re: How to reset direction of object
Post by: alex on May 07, 2009, 11:29:42 am
Incidentally , my ultimate goal is Making the world back to the initial state,Namely,back to the state object loaded.
now ,i have reseted the camera in  world.
Title: Re: How to reset direction of object
Post by: fireside on May 07, 2009, 12:12:07 pm
You can save the rotation matrix by object.getRotationMatrix()  and reset by object.setRotationMatrix(saved_matrix).
Title: Re: How to reset direction of object
Post by: paulscode on May 07, 2009, 01:36:47 pm
Yes, as fireside suggests, save the rotation matrix.  One thing I would add is that you might need to clone the rotation matrix to save it (depending on what jPCT does behind the scenes, I don't know if this is necessary):

Code: [Select]
Matrix savedMatrix = object.getRotationMatrix().cloneMatrix();
And then to reset, do the same:

Code: [Select]
object.setRotationMatrix( savedMatrix.cloneMatrix() );
Egon, is this necessary, or does jPCT automatically clone the matrix in these methods rather than using the actual instance passed to them?
Title: Re: How to reset direction of object
Post by: fireside on May 08, 2009, 06:21:00 am
Also, it's necessary to set the scale to 1 before using that function and resetting the scale after rotation, so you need getScale to do that.  It's in the function def.
Title: Re: How to reset direction of object
Post by: EgonOlsen on May 09, 2009, 06:10:37 pm
Egon, is this necessary, or does jPCT automatically clone the matrix in these methods rather than using the actual instance passed to them?
Yes, it is. The methods work with the direct references...yes , it's bug prone that way, but when calling these methods very often, it's too slow otherwise.