Jump to content
  • Advertisement
Sign in to follow this  
thedustbustr

Getting a camera matrix from an object matrix

This topic is 5065 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

I'm working out a bunch of matrix problems in my engine. I want all of my cameras to handle rotation and translation with exactly the same methods as objects- in practice, I want to be able to cast an Object* to a Camera* and be able to pretend there is a camera mounted on the object (think Redeemer in UT2004). Given the object's matrix representing orientation and position in worldspace, how do I find the appropriate matrix to send to OGL to "view" from the object's perspective?

Share this post


Link to post
Share on other sites
Advertisement
Just put inverse of object's matrix into openGL. It's simple : Object's matrix transform from local space to world space. Camera matrix transform from world to local.

not-directly-related:
I done it so: i have "coordinate system" class (contains vector and quaternion), that have methods to get 4x4 matrix for transform to that coordinate system, and to get matrix for transform from that coordinate system. For objects, i use "transform from", and for camera, "transform to". Coordinate systems have overloaded operator * so them work exactly as 4x4 matrices with rotation and translation only, yet inside it's done using quaternion and vector.

Share this post


Link to post
Share on other sites
Quote:
Original post by thedustbustr
When I do that, my camera is looking backwards (opposite the object's forward vector). What could cause that?

In OGL, camera looks in -z direction. If your "forward" is in +z direction, it will be opposite.

If you want to fix it, you need to flip sign of third row of matrix, and also flip sign of either first or second row (otherwise you'll get opposite handness)
It corresponds to turn by 180 degrees around y or x axis respectively.

[Edited by - Dmytry on January 1, 2005 11:10:02 AM]

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!