Skip to main content
gamedev.net
🔒 Locked

Question about local coordinates

Started by peter_b Dec 18, 2004 at 11:16 AM 3 replies 400+ views
Original Post
peter_b
peter_b
Hello I often see cameras and other stuff's 3d orientation represented by something that looks like this:

float m_pitch, m_yaw, m_roll;
		vector3d_t m_pos;
		vector3d_t m_dir, m_right, m_up;

I dont quite get what this is doing, i imagine it is some kind of local coordinate system. But how does it work? is the m_pos ready to be used as a world position? Or does it need to be converted to the "real" world coordinate system first? And what is the advantage to using this approach from just using: float m_xpos, m_ypos, m_zpos; float m_xrot, m_yrot, m_zrot; To represent a world orientation? Thanks in advance
Shields up! Rrrrred alert!
mdias
mdias
vector3d_t is a struct, something like this:
struct vector3d_t {   float x, y, z;};


then you can access it's member variables like this:
vecor3d_t pos;pos.x = 0.0f;pos.y = 1.0f;pos.z = 2.0f;// orfloat x = pos.x;float y = pos.y;float z = pos.z;
peter_b
peter_b
uhm yes..
But why does it define its own up, right and direction vectors? That looks like a local coordinate system to me or something to me.
Shields up! Rrrrred alert!
Zakwayda
Zakwayda
Hi,

It is a local coordinate system. m_pos is the origin of the system in world coordinates, and m_right, m_up and m_dir are the three axes of the local coordinate system.

The Euler angles are actually redundant - a local system can be uniquely defined by:

1. A position and three axes, as we see here, or

2. A position and a 3x3 matrix whose rows or columns are the three axes, or

3. A position and an axis/angle pair, or

4. A position and a quaternion, or

5. A 4x4 (or 4x3/3x4) matrix which represents both the orientation and the translation.

'Hope that helps.

[Edit: Actually, representing an orientation with a 3x3 matrix is also partly redundant. But, it doesn't suffer from some of the ambiguities that Euler angles suffer from.]
JohnBolton
JohnBolton
You are right -- the orientation data is redundant. You don't need both Euler angles and an orientation matrix since either can be derived from the other. The reason for having both is that either representation is likely to be queried many times. So, a simple optimization is to calculate both when the orientation changes, rather than calculating one of them every time it is queried.

m_pos is the camera's location in world space (normally).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.