Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I will use this as a generic reference, but the more i browser online docs and books, the less i understand about this.

const float vertexPositions[] = {
    0.75f, 0.75f, 0.0f, 1.0f,
    0.75f, -0.75f, 0.0f, 1.0f,
    -0.75f, -0.75f, 0.0f, 1.0f,
};

in this online book there is an example about how to draw the first and classic hello world for OpenGL about making a triangle.

The vertex structure for the triangle is declared as stated in the code above.

The book, as all the other sources about this, stress the point that the Clip Space is a 4D structure that is used to basically decide what will be rasterized and rendered to the screen.

Here I have my questions:

  • i can't imagine something in 4D, i don't think that a human can do that, what is a 4D for this Clip space ?
  • the most human-readable doc that i have read speaks about a camera, which is just an abstraction over the clipping concept, and i get that, the problem is, why not using the concept of a camera in the first place which is a more familiar 3D structure? The only problem with the concept of a camera is that you need to define the prospective in other way and so you basically have to add another statement about what kind of camera you wish to have.
  • How i'm supposed to read this 0.75f, 0.75f, 0.0f, 1.0f ? All i get is that they are all float values and i get the meaning of the first 3 values, what does it mean the last one?
share|improve this question
3  
Chapter 4 explains exactly what the fourth component does. Actually, scratch that; Chapter 1 explains the clip-to-NDC transform in the rasterization section halfway down. –  Nicol Bolas Aug 26 '12 at 14:29
2  
@NicolBolas the author gives his explanation in the first chapter and doesn't put any reference for the next chapters, also he pretends to explain what happens next when commenting some c++ code and the problem is that if he doesn't fully explain everything in the 1 chapter do not makes much sense to put what i'm supposed to know in the first place in the chapter number 4, especially if i need this concepts to decode what's inside the 1 chapter. I'm reading this now, and not just 1 time, now i know that i'm supposed to look further for the answer, i will go trough the various chapters. –  user827992 Aug 26 '12 at 14:39
1  
You don't need to decode anything; it says in chapter 1: The W component is divided into the other 3 components.This was stated in the introduction as well. What is put off until chapter 4 is why OpenGL does this. That's held off until later because it is irrelevant to the task at hand. –  Nicol Bolas Aug 26 '12 at 14:42
3  
It would still be irrelevant information for the issue at hand (ie: rendering a triangle). You're curious about it, but you don't need to understand why it is the way it is to understand that this is how it works. In learning anything, the first step is to understand what it is. Once you understand what's going on, then a discussion can take place about why it is that way. –  Nicol Bolas Aug 26 '12 at 14:52
1  
This answer may help. –  iammilind Oct 21 '12 at 7:39

3 Answers 3

up vote 7 down vote accepted

The magic term is "Homogeneous coordinates" which are used in systems where perspecive is a factor. Check the wiki for an overview, but it's a long course of study to really understand it (which I don't).

share|improve this answer

Read the introduction of books you read, you'll be surprised ;)

http://arcsynthesis.org/gltut/Basics/Intro%20Graphics%20and%20Rendering.html under Rasterization Overview

The "w" value (where the first 3 values are x, y and z) basically says what the dimensions of the clip space are. Because this is 1 scalar value, all 3 dimensions of the clip space are equal (and that's why the clip space is a cube). Every vertex has it's own clip space in which it exists (and basically needs to "fit" in, otherwise it CLIPS :D), there is not 1 "world" that is the clip space(though all clip spaces are in the same "world" I think, even I'm having trouble with this ;P).

So if your vertex has for example the coordinate [1,1,1], if the clip space is 1 then the vertex is in the top right near corner of the screen (when all is default, I don't know if the directions can be altered). But if the vertex has a clip space of 2, then the coordinate [1,1,1] will be somewhere let's say, 3 quarters across the screen to the right, 3 quarters across the screen to the top, and the third dimension you can guess yourself.

I think having let's say a clip space of 5 would mean the locations within that clip space range from -5 to 5 on every dimension, instead of the cube being 5x5x5. But that's probably because simply put: all x y and z coordinates are divided by the clip space dimension, so basically your vertices undergo this:

x = x / w

y = y / w

z = z / w

And that's what makes it all possible. I think the reason this exists is for easy comparisons. If the coordinates have been divided by the clip space dimension, then the coordinate that has 1 or more components with a value higher than 1, exists outside the clip space. So if your clip space is let's say 1024, but the coordinate is [2000,3,-100] then the x(2000) component is outside the clip space (which only ranges from -1024 to 1024).

computingwise it's easy to tell if something is inside the clipspace if all you have to do is (very crudely put ofc): (x/w)<1 && (x/w)>-1 then render. Also, I suppose having all clip spaces of all vertices the same size (so every clip space cube ranging from -1 to 1 in every dimension) makes it easier for whatever comes after the normalisation process, seeing as from that moment on all coordinates are floats ranging from 0 to 1 (disregarding that which has been clipped off).

share|improve this answer
    
The question was why clip-space is as it is, not what clip-space means. That is, what's the point of the divide-by-W. –  Nicol Bolas Jul 21 '13 at 22:06
    
It answers the 3rd question of the 3 bullet points though =) –  grimmeld Jul 22 '13 at 10:32

There is also one more reason that I see and that was not mentioned in the previous answers.

Translation matrices are 4x4 so that you can also translate the object around "the world". Because with a 3x3 matrix you can rotate and scale a 3d coordinate, but you can translate a 3d coordinate only with a 4x4 matrix, from here the need to express the 3d coordinates in a 4d vector.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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