Sign in to follow this  

Matricies and Projection Transforms

This topic is 2347 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 having some trouble understanding how to use various kinds of transforms, world transforms, view transforms, and projection transforms, and moreover mainly the last of the three. I have a basic grasp that view transforms are used for the essential "camera" for a viewpoint, but am having trouble grasping what world and projection transforms can, and are, used for. I've been crawling over the MSDN and DirectX documentation with still no luck understanding the underlying principles and uses. Can anyone give me some assistance with this? Thanks.

Share this post


Link to post
Share on other sites
I'll try. First I want to make sure you have the correct 10,000 ft view.

Let's start from the beginning: the model to render. Let it be a cube at the origin with points (1, 1, 1), (-1, -1, -1). This model is in model space, or [i]object space[/i].
First we need to put this object in the world. You do that by having a [i]world matrix[/i]. You know matrix ~= functions, this function maps points in object space to objects in [i]world space[/i]. The world matrix typically includes rotations and translations. I strongly suggest to not allow scaling. If you need scaling, at least make sure it's uniform.
So let's think at the matrix as an opaque entity with a rotation component and a translation component. The same cube with two different matrices will result in different points in the world.
This is typically used for "game entities" which needs to move around in the world. By contrast, world geometry is often pre-batched/pre-transformed, so its world matrix is typically [i]identity[/i].

Now that every object is where it wants to be we need to place the camera but we cannot. We can only move the world instead and this is quite the same thing. So we have a camera matrix which maps world-space to "camera space", more properly called [i]eye space[/i]. This matrix is fairly similar to the world matrix.
Because of performance reasons, in the past it was typical to concatenate the world and camera matrix in a single matrix, which was called MODELVIEW. OpenGL had explicit notion of this matrix (math is the same for D3D). MODELVIEW is important when it comes for example to normal transformations (normals need to be mangled differently from points).

At this stage, all our points are "more or less" like they were in the beginning. We placed each object and then "offset" by a camera transform (it's very easy if you think in terms of translations only).

Then it comes the PROJECTION matrix (again this was an explicit OpenGL matrix). Let's think about perspective transform only for now. The perspective projection matrix will scale some points depending their distance from the camera, transforming from eye-space to clip-space. Ok, what this means?

Think at the spaces seen up to now. You can think at them as cubes. Think instead at the view frustum, which gets bigger and bigger as it moves away from the far plane.
[color="#ff0000"][b]Caution[/b]: approximation applies below, for gross explanation purposes. This quite different from what's going on, but I think it's a good analogy without involving the math.[/color]
Think at the two object space cubes. Suppose one ended being near the camera, and the other far. Think clip space coordinates like the relative position of the points wrt the camera-z plane in which they reside. If they are close, they'll end being on the NEAR plane. If far, they'll end in FAR plane. The NEAR plane edges might measure say 10 units in world space while the FAR plane might measure 100 units so the same cube would end up covering different "ratios" of the plane.
This is what the perspective transform does, it somehow "shrinks" the objects as they move away - no surprise here right? - because it must fit a perspective frustum into a cubic system and the only way to do this is to shrink the frustum according to distance, which implies shrinking the objects... This is non-rigid transform.
So, the more you move away, the more you shrink.

Again, for performance reasons, MODELVIEW and PROJECTION were usually concatenated in [i]modelviewprojection [/i]([i][b]MVP[/b][/i]) matrix.

Let's leave out tangent-space for the time being which in my opinion is very interesting but probably not what you need now.
Any problems up to this point?

Share this post


Link to post
Share on other sites
[quote name='Solovus' timestamp='1310443200' post='4834129']
I'm having some trouble understanding how to use various kinds of transforms, world transforms, view transforms, and projection transforms, and moreover mainly the last of the three. I have a basic grasp that view transforms are used for the essential "camera" for a viewpoint, but am having trouble grasping what world and projection transforms can, and are, used for. I've been crawling over the MSDN and DirectX documentation with still no luck understanding the underlying principles and uses. Can anyone give me some assistance with this? Thanks.
[/quote]

World transform is probably the most easy to understand. It is used to "transform an object from object space to world space". That is, when you model a 3d object, you usually create it around origo. Without world transforms all your objects would be located more and less in the same spot and that isn't what you are after. With the world transforms, you can position and orient objects in the 3d space as you like. Remember that each of the object has their own world transform.

View transform practically describes the orientation and location of your camera. I won't go into the math details here, but you can find good examples on the net (and probably DX SDK). Anyway, using the view transform roughly does following: it transforms your 3d geometry from the world space to the view space. In the view space your camera location is 0,0,0 and it is looking always into a fixed direction (ie. forward). So in the sense of the view space, your camera stays still and the world moves around it.

Projection matrix is probably the most difficult part to understand. It does the following : it transforms the views space into a "box". The parts which are outside of the box are outside of the screen and can be clipped efficiently since. If you are familiar with view frustum (kind of a pyramid with bottom and top planes), you can imagine the the projection space as the frustum stretched to the shape of a box. The hard part is usually with clip space is that the vectors aren't 3d but 4d.

I hope this was helpful! Cheers!

Share this post


Link to post
Share on other sites
Thank you both for your replies. I have a much better grasp of these three matrices and their applications. Correct me if I'm wrong about the next few things I say:
1) The world transform, and its associated matrices, are used for rotations, translations, and (typically less so) scaling.
2) It can be used to position models into world space from their localised model space via rotating and translating the model.
3) The view transform represent "camera" or "eye" space. The "camera" never truly moves, but the world moves around it.
4) The projection matrix is analogous to a viewing frustum.

If that's accurate, then I think I've got a good (enough) grasp on these matrices. Thanks guys!

PS: I understand that tangent space is typically used to calculate textures and normals since it is based on vectors u and v and would maintain a constant n. I found a decent article on it, so I think I can go off of that.

Share this post


Link to post
Share on other sites
I would seriously recommend you to take a look at the book Real Time Rendering (third edition currently). It is the most agnostic book on graphics I have ever found, it does not get into the specifics of direct X or OpenGL, it doesn't assume any particular platform, it just tells you what each graphics related concept means and how it works beyond specific implementations, a person completely new to graphics could take a read of it and get much more knowledge than from the best DX cookbook around.

Share this post


Link to post
Share on other sites
[quote name='NEXUSKill' timestamp='1310502090' post='4834486']
I would seriously recommend you to take a look at the book Real Time Rendering (third edition currently). It is the most agnostic book on graphics I have ever found, it does not get into the specifics of direct X or OpenGL, it doesn't assume any particular platform, it just tells you what each graphics related concept means and how it works beyond specific implementations, a person completely new to graphics could take a read of it and get much more knowledge than from the best DX cookbook around.
[/quote]

Hey, thanks I'll look into that. I'm not completely new, it's just that these matrices have always thrown me for a loop.

Share this post


Link to post
Share on other sites

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