# Rotate game object

This topic is 2640 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys!

I'm trying to rotate my object its own local Y axis but it is rotating in world Y axis. If i could made it, then i want to translate the object in direction where it is look at. i have copied my camera class movement logic to my object class, but it is not working as my camera.

Here is my code:

 void Object::setPositionMatrix(){ Math::normalize(&m_Look, &m_Look); Math::cross(&m_Up, &m_Look, &m_Right); Math::normalize(&m_Up, &m_Up); Math::cross(&m_Right, &m_Up, &m_Look); Math::normalize(&m_Right, &m_Right); float x = -Math::dot(&m_Right, &m_Pos); float y = -Math::dot(&m_Up, &m_Pos); float z = -Math::dot(&m_Look, &m_Pos); m_Coord(0, 0) = m_Right.x; m_Coord(0, 1) = m_Up.x; m_Coord(0, 2) = m_Look.x; m_Coord(0, 3) = 0.0f; m_Coord(1, 0) = m_Right.y; m_Coord(1, 1) = m_Up.y; m_Coord(1, 2) = m_Look.y; m_Coord(1, 3) = 0.0f; m_Coord(2, 0) = m_Right.z; m_Coord(2, 1) = m_Up.z; m_Coord(2, 2) = m_Look.z; m_Coord(2, 3) = 0.0f; m_Coord(3, 0) = x; m_Coord(3, 1) = y; m_Coord(3, 2) = z; m_Coord(3, 3) = 1.0f; } 

 void Object::rotateY(float angle){ Math::matrix T; Math::identity(&T); Math::rotation(&T, &m_Up, angle); Math::transformCoord(&m_Right, &m_Right, &T); Math::transformCoord(&m_Look, &m_Look, &T); Math::multiply(&m_Coord, &m_Coord, &T ); setPositionMatrix(); } void Object::walk(float unit){ m_Pos += m_Look * unit; setPositionMatrix(); } 

##### Share on other sites
The matrix for a camera is the inverse of its view direction/position.
You need to create a matrix that represents the object’s orientation, not the inverse of its orientation.

For starters, m_Coord(3, 0) should be set to m_Pos.x, not -Math::dot(&m_Right, &m_Pos);.
All of m_Coord(0, X) should be set to the values in m_Right.

L. Spiro

##### Share on other sites

The matrix for a camera is the inverse of its view direction/position.
You need to create a matrix that represents the object’s orientation, not the inverse of its orientation.

For starters, m_Coord(3, 0) should be set to m_Pos.x, not -Math::dot(&m_Right, &m_Pos);.
All of m_Coord(0, X) should be set to the values in m_Right.

L. Spiro

That's worked! But i have another issue: It's rotating its on local Y axis but does not go to the direction where the object is looking at. Do you have any solution for this, too =)

1. 1
2. 2
Rutin
13
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633261
• Total Posts
3011127
• ### Who's Online (See full list)

There are no registered users currently online

×