6

I'm trying to learn 3d graphics programming through "Learning Modern 3D Graphics Programming" by Jason L. McKesson.

I have not really looked at other guides, but this guide seems to emphasize the theory and mathematics behind 3d graphics. Right now, I am stuck on this page:

http://www.arcsynthesis.org/gltut/Positioning/Tut04%20Perspective%20Projection.html

I am not exactly sure what he means by camera space, and why it is necessary to project a 3d world onto a 2d surface. This question is kind of vague, so instead of a full explanation, links that might give me a different way of explaining these concepts would be appreciated as well.

1
  • Sorry, I should have made this clearer: I do know why it is necessary to project a 3d world onto a 2d surface. I just didn't know why camera space was necessary or useful to this end. Jan 23, 2012 at 1:00

4 Answers 4

9

Well, it's necessary to project a 3D world onto a 2D surface since your screen is a 2D surface.

3D graphics works in different "coordinate spaces", and these are converted between to get a final scene.

Imagine for example modelling a city. You might define the bottom left corner of the map as (0, 0), and the top right as (1000000, 1000000). You might also say that as a rule, one point will represent a foot of real space. This representation we will call World Space.

To draw your city, you'll want to import some models of buildings, and place them in the world. So you get your model of a building, but when you're making this model, you don't want to have to worry about the size of the world or where it will be - you maybe will say that the building's bottom left corner is at (0, 0) and its top right is at (1, 1). This representation we will call Model Space. In the world though, the building might be placed at (104, 136) and you might want it to be 1000x1000 pixels, so you will need to translate it to (104, 136) and scale it up 1000x. This is converting it from Model Space to World Space.

Finally, Camera Space is how you move around in the world. If you think about it, moving around in the world could be thought of in two ways (at least): You move around the world, or the world moves around you. So to make movement easy, we'll say that the camera is always at the point (0, 0) facing down some axis. Now if you want to move forward 10 pixels, instead you just move everything back 10 pixels. If you want to rotate, rotate the world instead. So to render the building, first we want to transform it from Model Space to World Space. Now, to actually draw it, we want to know where it is relative to the viewer, so we move it from World Space to Camera Space.

. . .

As an aside, if you want to understand this very well, a good exercise is to write a 3D wireframe renderer, separate from OpenGL. Your only drawing function available is DrawLine(x1, y1, x2, y2) which draws a line on the screen from (x1, y1) to (x2, y2).

2
  • That would be quite the challenge. Thanks for your explanation! Jan 23, 2012 at 0:39
  • 1
    It's not as hard as you'd think. The reason that we use transforms is ultimately to do that final projection onto the screen and figure out "where the heck do these points belong". Basically, writing a wireframe renderer would just mean that you do all of the matrix multiplications yourself - the translations, rotations, and then projection. The really hard part of 3D graphics is shading and clipping, but if you are writing a wireframe renderer you won't have to worry about that. And it'll make you really appreciate and understand the math.
    – mindvirus
    Jan 23, 2012 at 0:43
7

why it is necessary to project a 3d world onto a 2d surface

All graphics is just 2D images. 3D graphics is thus a system of producing colors for pixels that convince you that the scene you are looking at is a 3D world rather than a 2D image. The process of converting a 3D world into a 2D image of that world is called rendering.

A projection, for the purposes of rendering, is a way to transform a world from one dimensionality to another. Our destination image is two dimensional, and our initial world is three dimensional. Thus, we need a way to transform this 3D world into a 2D one.

I am not exactly sure what he means by camera space

Before this point, vertex positions were expressed directly in clip space. Recall that the divide-by-W is part of clip space vertex positions. Perspective projection is a way of transforming positions into clip space such that they will appear to be a perspective projection of a 3D world.

This transformation process has well-defined outputs: clip space positions. But what exactly are its input values?

That's camera space.

This is not a space that OpenGL recognizes (unlike clip-space which is explicitly defined by GL); it is purely an arbitrary user construction. However, it can be useful to define a particular camera space based on what we know of our perspective projection. This minimizes the differences between camera space and the perspective form of clip space, and it can simplify our perspective projection logic.

1
  • OK thank you. All of the responses to this question were good, but this answer really explained WHY we need to define a camera space. I'm not sure if I'm understanding this completely correctly, but I think I was having trouble understanding why he uses a camera space because he is not doing anything to move the camera yet, so I was wondered why he was even bothering with this in the first place. Jan 23, 2012 at 1:05
6

Camera space is the coordinate system relative to the camera. So camera space is where geometry ends up immediately before projection.

Commonly you start with coordinates in model space. You know how the model relates to the world so you can map from model space to world space. You then have a camera in the world, and you use knowledge of that to map from world space to camera space. If there were no transform into space relative to the camera, the camera could not move.

Projection is necessary because your world is 3d and your screen is 2d. You project from the 3d world onto the 2d surface of your computer monitor. Even stereoscopy is just two projections instead of one.

I'm not immediately aware of any links better than the one you've already provided.

3
  • Your explanation is helping very much, thank you. This guide does not introduce model spaces or moving cameras until a few chapters later, but what you have said seems make intuitive sense. Jan 23, 2012 at 0:30
  • Also, if I'm understanding you correctly, camera space is BEFORE any projection to a 2d plane? Jan 23, 2012 at 0:36
  • Yes — camera space is the result of the last transform before projection in the flow of a standard polygon renderer.
    – Tommy
    Jan 23, 2012 at 11:26
4

To quickly answer

why it is necessary to project a 3d world onto a 2d surface

think of representing a 3D world (w/e you define in the program) using a 2D medium, for example the screen. However to do that, quite a bit of complex maths is needed, so it depends what deep down the rabbit hole you are willing to go...

Quoting wikipedia (http://en.wikipedia.org/wiki/Graphics_pipeline):

Objects are transformed from 3-D world space coordinates into a 3-D coordinate system based on the position and orientation of a virtual camera. This results in the original 3D scene as seen from the camera’s point of view, defined in what is called eye space or camera space. The normalizing transformation is the mathematical inverse of the viewing transformation, and maps from an arbitrary user-specified coordinate system (u, v, w) to a canonical coordinate system (x, y, z).

1
  • I'm just going as deep as this guide does, and it seems like I'm going quite deep! Jan 23, 2012 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.