Jump to content
  • Advertisement
Sign in to follow this  
rmdeboer82

[3D] World to camera transformation

This topic is 4826 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've read several docs on university sites (and black art of 3D programing, lamothe), but i can't get the whole picture. This is what I know: *The camera is translated to the world origin. To put it in another way: the world is translated to the camera position with the old world camera position as the new world origin. All world coordinates go through the same translation so the camera view/output screen will be the same as if the camera wasn't moved to the origin. *When both coordinate systems have the same origin, somehow a rotation on the world coordinates is done so it fits in/corresponds to camera/screen display. *The viewplane (a.k.a. the outputscreen) has a Z-axis corresponding to the lookat point (lefthanded, the further the more postive). *Both other vectors of the viewplane are perpendicular to the Z-axis (derived from the lookat point and eye position). *In fact, all changes are done on world coordinates. What I want to know: *What's the purpose of view up vector? does it use the world's Y-axis? how is it set up? *Is world's Y-axis involved at the rotation when both systems are in the origin? *How can I imagine the x,y & z angles at the origin? *Are pitch, roll and yaw the same as the angles? *The screen can be turned (like the wings of a plane) keeping the same lookat point, what results does it have on the system? *For the ones with black art of 3D programing, on page 790 (fig 13-5), which lines should be dashed/dotted to indicate it's behind another normal line? Thanks in advance. Good illustrations are welcome too.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
So you have a scene and a camera is also in that scene. So far I have not introduced a coordinate system, so there are no coordinates to speak of. There are just objects in space.

Now, I want to represent the positions of objects with coordinates, so I arbitrarily pick a point in the scene and pick three orthonormal basis vectors attached to that point, and call this a frame. I can not express other points in the scene relative to that frame. I call this frame the world space frame.

Now, I can just as well pick the point the camera is situated and attach three orthonormal vectors to that point, and call that a frame--the view frame.

Now we have two frames that exist in the same space, thus we can relate them. In particular, we can change coordinates relative to one frame and make them relative to another frame. This doesn't physically move anything, we are just changing the frame its coordinates representation. For example, I can measure a pencil in meters or centimeters or milimeters. The pencil's length does not change, but its quantity relative to the coordinate system (just 1D in this case) does change based on the coordinate system I use (units of measure).

In the same way, in the world to view transform you say, I don't want to use the world frame--I want to instead make all the coordinates of my points relative to the view frame instead. The world to view transform does this change for you.

The theory behind the change of coordinates matrix is covered in any linear algebra textbook, but it is a linear transformation and thus has a matrix representation.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

"I can not express other points in the scene relative to that frame. I call this frame the world space frame."

Should be, "I can now express..."

Share this post


Link to post
Share on other sites
thank you,

i'm interested in what happens next. more of how to imagine/interpret the things coming next, like rotations etc.

i'm familiar with linear algebra (final thing to get it working), so matrix calculations isn't the problem.

Share this post


Link to post
Share on other sites
As far i know, there are two types of cameras we can use.

1. it is based on simple transformation and then rotation step we dont need x y or z of camera

2. second is calld Eulerian or UVN camera model which actually uses x y z coordinates of its own and here we need an up vector to compute the x y z coordinates of camera model.

viewplan is not our output screen. it is just a 2D plan on which we project our 3D image but it comes after camera transformation. this operation is done in Viewing Transformation.

if you want to read about UVN camera model here is a usefull link
http://graphics.idav.ucdavis.edu/education/GraphicsNotes/Camera-Transform/Camera-Transform.html

Share this post


Link to post
Share on other sites
Quote:
Original post by Tauqeer
viewplan is not our output screen. it is just a 2D plan on which we project our 3D image but it comes after camera transformation. this operation is done in Viewing Transformation.


but it does have the same contents isn't it? it must be rendered before it's on the output screen.

what's the intention/meaning of the up-vector? why is it used? once you've got you can derive the U and V vectors of the UVN-viewplane, that's what i know. i've read the up-vector points to an vector parallel to the y-axis or it's the y-axis itself, that axis indicates the up direction in the world coordinate system.

i don't see why the up-vector required/necessary (except that it is required for the derivations mentioned earlier). the up-vector doesn't have the same direction as the one in the viewplane pointing upwards.

when one the eye/head is turned left, in the output/cameraview the up-indication of the world coordinates points from the left to the right on the screen/camera, that's what i can imagine.

Share this post


Link to post
Share on other sites
Quote:
what's the intention/meaning of the up-vector? why is it used? once you've got you can derive the U and V vectors of the UVN-viewplane, that's what i know. i've read the up-vector points to an vector parallel to the y-axis or it's the y-axis itself, that axis indicates the up direction in the world coordinate system.
The term 'up vector' can have different meanings, which may be causing some confusion. The 'parallel to the y axis' up vector is the type you would submit to, say, a 'lookat' function to let it know how to align the camera. A more general meaning of 'up vector' would be the local up vector for an object. This vector is one of the three orthonormal basis vectors of the object's local coordinate frame, and can point in any direction, dependent on the orientation of the object.

Don't know if that answered your question at all, but ask if you need clarification.

Share this post


Link to post
Share on other sites
My two cents on the subject:

OpenGL has two matrices to do the camera transform, Direct3D has 3. Not being a D3D man, I'm going to ignore how D3D works completely.

OpenGL has 3 spaces, object space, eye space and clip space. Object space coordinates are the coordinates as fed into OpenGL. Eye space coordinates are the coordinates after being multiplied by the modelview matrix. In this coordinate system the camera is at (0,0,0), looking along the -Z axis (for right handed coordinate systems), with the look-up vector pointing up the Y axis. These coordinates are used for lighting calculations and can be used for texture coordinate generation (maybe other things too but not that I know of). Clip space coordinates are eye space coordinates multiplied by the projection matrix. This has the effect of moving the near plane to Z=-1 (we switch to a left handed system at this point), the far plane to Z=+1, and the other four clip planes to Y=+1/-1 and X=+1/-1. The camera in this coordinate system is at (0,0,-1,0) (homogenous coordinates - yep, that's infinitely far away along the -Z axis), looking along the +Z axis with the up vector along the +Y axis.

So the upshot of all that is that the overall effect of a perspective transform (orthographic transforms are slightly different, but can be thought of as having the camera infinitely far away in object space) is to transform the frustum in object space (which is a pyramid with the end cut off, or alternatively a cuboid with one end shrunk/expanded) to a unit cube in clip space.

Now after that long rambling explanation of how I think it works:

* The view up vector is the vector normally passed to a function like gluLookAt. More specifically it's the vector that when transformed through the view matrix (assuming it's (x y z 0)) produces (0 1 0 0) (with some scaling factor). Vectors with 0 in the w coordinate can be thought of as either directions or points infinitely far away - the effect of the w coordinate being 0 is to make them unaffected by translations. The upshot of that is that in eye/clip coordinates its direction is "up" on your screen. Exactly how you construct a matrix looking in a specific direction according to a vector I'm not exactly sure, but the source code to GLU is available so you can look there if it's not anywhere else.

* I'm not quite sure what you mean by "Is the world's Y-axis involved at the rotation" but I think the answer is as long as the rotation isn't in the XZ plane, i.e. it depends on your choice of rotation. Rotations can be represented as a direction vector and an angle where the rotation is about that vector, meaning any distances parallel to that vector are unaffected.

* I'm not sure what you mean by X, Y and Z angles.

* Pitch, roll and yaw are a specific form of Euler angles. Euler's rotation theorem states that any rotation can be represented by exactly 3 angles. This particular choice of the 3 angles involves rotating about Y, X and then Z (yaw, then pitch, then roll usually).

* Turning the screen is changing roll (if you're using that system). It changes the look up vector by rotating it about the look at vector. Incidentally the look up vector does not have to be perpendicular to the look at vector. If it isn't it will produce an effect like the look up/down parallax effect of Duke Nukem 3D. I don't think I've seen it in any other game. It's weird and pretty undesirable.

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!