Sign in to follow this  
Baris YILMAZ

Rotate game object

Recommended Posts

Baris YILMAZ    104
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.


[img]http://www.imagedisk.net/di-6II0.png[/img]


Here is my code:

[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;
}

[/code]


[code]

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();
}
[/code]

Share this post


Link to post
Share on other sites
L. Spiro    25638
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 this post


Link to post
Share on other sites
Baris YILMAZ    104
[quote name='YogurtEmperor' timestamp='1313918282' post='4851833']
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
[/quote]


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?)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this