Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rotate game object

Started by Baris YILMAZ Aug 21, 2011 at 8:07 AM 1 replies 1.4k views
Original Post
Baris YILMAZ
Baris YILMAZ
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.


di-6II0.png


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();
}
L. Spiro
L. Spiro
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
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
Baris YILMAZ
Baris YILMAZ

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 =)
(Türk müsün bu arada?)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.