Sign in to follow this  

Getting a camera matrix from an object matrix

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

This topic is 4731 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.

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