Jump to content
  • Advertisement
Sign in to follow this  
Baris YILMAZ

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.

If you intended to correct an error in the post then please contact us.

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.


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();
}

Share this post


Link to post
Share on other sites
Advertisement
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

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!