how to let rotationmartrix only rotate without translation?

Started by Uncle Ray, September 03, 2014, 05:21:49 AM

Previous topic - Next topic

Uncle Ray

I know in fact the setrotationmartix include translation,but i dont need the translation,just need rotate only,
how to solved?Any help will be appreciated.

Uncle Ray

|          |         
|          |      step:1                                                         
|          |
|          |
|        / |
|      /   |
|     /    |→→→→waypoint
|    /     |
|          |
|   ▲    |→→→→→car





|          |         
|          |      step:2
|          |
|          |
|        / |
|      /   |→→→→→→waypoint
|    ▲   |→→→→car(car must rotation,and it's face should be the same as waypoint's)
|    /     |
|          |
|          |

EgonOlsen

The rotation matrix can include a translation, but it's not supposed to. It just can, because it's a 4x4 matrix. Just remove the translational part from the it before setting it.

Uncle Ray

how to removed?example matrix a=A.getrotatematrix.
     ┎                           ┓
     │ a00 a01 a02 a03│
     │ a10 a11 a12 a13│
a= │ a20 a21 a22 a23│
     │ a30 a31 a32 a33│
    ┖                            ┛
a.setrow(3,0,0,0,1)

means:
(a30=0,a31=0,a32=0,a33=1)



i know this is wrong,but how to correct.what is the right code?

EgonOlsen


Uncle Ray

but the fact is thranslation still alive;here is my code

{SimpleVector front=obj_car.getZAxis();
   front.scalarMul(-1);
   Matrix a03=obj_wp[i_check1].getRotationMatrix();
   a03.setRow(3, 0, 0, 0, 1);   
   if(obj_car.checkForCollision(front, 2.5f)==obj_wp[1].getID())      
   {obj_car.setRotationMatrix(a03);}
      
      
      
   
   
   }

the fact is obj_car still translation.......

EgonOlsen

Must be something else then...if that getRotationMatrix() call is the one from Object3D, it doesn't contain any translations anyway. You can check this by simply printing out the matrix. Keep in mind that the outcome of a rotation will also be influenced by the objects rotation pivot as well as any translation or rotation of a parent object.

Uncle Ray

may be the point is the model?
i tried another model,which is the same model like obj_car.
here is really just rotation no more translation,but have a question?



{SimpleVector front=obj_car.getZAxis();
   front.scalarMul(-1);
   Matrix a03=obj_wp[1].getRotationMatrix();
   a03.setRow(3, 0, 0, 0, 1);   
   if(obj_car.checkForCollision(front, 2.5f)==obj_wp[1].getID())     
   {obj_car.setRotationMatrix(a03);}
     
     
     
   
   
   }

question:
1,when i rotate obj_car,obj_wp[1] was rotated too,why?
2.i just want the obj_car and obj_wp[]1 have the same face in the world space,no translation,just rotateisY or rotateYaxis .
Is there a better suggest?


PS:recently,i have asked so many questions, and you always  have the best answer,thanks again, :)

EgonOlsen

It depends on what obj_wp[1] actually is. Is it a SimpleVector or an Object3D? If it's a SimpleVector, there's no reason why it should rotate if you rotate the car. If it's an Object3D, you are getting the matrix of obj_wp[1] and set it into obj_car, which means that both object share the same instance. This isn't what you want, try something like

obj_car.getRotationMatrix().setTo(a03);

instead.

If obj_wp[1]is an Object3D, you can simply use http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#align(com.threed.jpct.Object3D) instead to do the same thing with less code.