Author Topic: How to reset direction of object  (Read 4102 times)

Offline alex

  • byte
  • *
  • Posts: 19
    • View Profile
How to reset direction of object
« 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.

Offline alex

  • byte
  • *
  • Posts: 19
    • View Profile
Re: How to reset direction of object
« Reply #1 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.

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: How to reset direction of object
« Reply #2 on: May 07, 2009, 12:12:07 pm »
You can save the rotation matrix by object.getRotationMatrix()  and reset by object.setRotationMatrix(saved_matrix).
« Last Edit: May 07, 2009, 12:18:14 pm by fireside »
click here->Fireside 7 Games<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: How to reset direction of object
« Reply #3 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?

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: How to reset direction of object
« Reply #4 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.
« Last Edit: May 08, 2009, 06:24:58 am by fireside »
click here->Fireside 7 Games<-

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to reset direction of object
« Reply #5 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.