### Author Topic: how to let rotationmartrix only rotate without translation?  (Read 2268 times)

#### Uncle Ray

• int
• Posts: 81
##### how to let rotationmartrix only rotate without translation?
« on: September 03, 2014, 05:21:49 am »
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

• int
• Posts: 81
##### Re: how to let rotationmartrix only rotate without translation?
« Reply #1 on: September 03, 2014, 07:06:20 am »
|          |
|          |      step:1
|          |
|          |
|        / |
|      /   |
|     /    |→→→→waypoint
|    /     |
|          |
|   ▲    |→→→→→car

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

#### EgonOlsen

• Administrator
• quad
• Posts: 12198
##### Re: how to let rotationmartrix only rotate without translation?
« Reply #2 on: September 03, 2014, 09:23:38 am »
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

• int
• Posts: 81
##### Re: how to let rotationmartrix only rotate without translation?
« Reply #3 on: September 03, 2014, 11:07:31 am »
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

• Administrator
• quad
• Posts: 12198
##### Re: how to let rotationmartrix only rotate without translation?
« Reply #4 on: September 03, 2014, 12:08:52 pm »
No, that's actually correct.

#### Uncle Ray

• int
• Posts: 81
##### Re: how to let rotationmartrix only rotate without translation?
« Reply #5 on: September 03, 2014, 06:48:09 pm »
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

• Administrator
• quad
• Posts: 12198
##### Re: how to let rotationmartrix only rotate without translation?
« Reply #6 on: September 03, 2014, 07:31:30 pm »
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

• int
• Posts: 81
##### Re: how to let rotationmartrix only rotate without translation?
« Reply #7 on: September 03, 2014, 08:12:49 pm »
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

• Administrator
• quad
• Posts: 12198
##### Re: how to let rotationmartrix only rotate without translation?
« Reply #8 on: September 03, 2014, 09:23:54 pm »
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

Code: [Select]
`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.