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.

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 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 on other sites
When I do that, my camera is looking backwards (opposite the object's forward vector). What could cause that?

Share on other sites
Quote:
 Original post by thedustbustrWhen 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]

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• Forum Statistics

• Total Topics
633295
• Total Posts
3011245
• Who's Online (See full list)

There are no registered users currently online

×