Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Question about the 'w' coordinate Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Blah

July 02, 1999, 01:41 AM

Recently, I have bought a number of 3D books. In some of the general ones (like
Advanced Animation and Rendering Techniques), there is a 4th coordinate called
the 'w' coordinate. However, in some of the more specific programming books (like
the Black Art of 3D Game Programming), I don't believe the w coordinate is used
at all. So I'm wondering...is the w coordinate usually used in 3D games, such as
Unreal and Quake? If someone could also shed some light on the purpose of the
w coordinate (since I am still a bit fuzzy on that), it would be most appreciated.
Thanks in advance!

----Blah

 
john shield

July 02, 1999, 01:41 PM



Blah wrote:
>>Recently, I have bought a number of 3D books. In some of the general ones (like
>>Advanced Animation and Rendering Techniques), there is a 4th coordinate called
>>the 'w' coordinate. However, in some of the more specific programming books (like
>>the Black Art of 3D Game Programming), I don't believe the w coordinate is used
>>at all. So I'm wondering...is the w coordinate usually used in 3D games, such as
>>Unreal and Quake? If someone could also shed some light on the purpose of the
>>w coordinate (since I am still a bit fuzzy on that), it would be most appreciated.
>>Thanks in advance!
>>
>>----Blah

I am more fuzzy than most but i reckon your best bet is to get a book on linear
algebra and study homogenous vector spaces there. I have such a book and am still
stuck.

I use 3x3 matrices for object orientation and a vector for origin.

I used 4x4 matrices before and found it created added complexity and was not
worth the study.

Hope you learn this crap too!!

John shield




 
Michael Herf

July 02, 1999, 02:16 PM

The 'w' coordinate is typically used to do special types of
projective texture mapping. This is when you want a perspective
transformation into texture space, and then another perspective
transformation to the screen. See a 1990 Siggraph paper
by Segal for a good description. Segal uses the technique to
display light gels (including spots), do slide-projector-style textures, etc.

I believe the Advanced OpenGL course on SGI's site has a good description as well.

mike

Blah wrote:
>>Recently, I have bought a number of 3D books. In some of the general ones (like
>>Advanced Animation and Rendering Techniques), there is a 4th coordinate called
>>the 'w' coordinate. However, in some of the more specific programming books (like
>>the Black Art of 3D Game Programming), I don't believe the w coordinate is used
>>at all. So I'm wondering...is the w coordinate usually used in 3D games, such as
>>Unreal and Quake? If someone could also shed some light on the purpose of the
>>w coordinate (since I am still a bit fuzzy on that), it would be most appreciated.
>>Thanks in advance!
>>
>>----Blah

 
SLI9000

July 02, 1999, 09:54 PM



Blah wrote:
>>Recently, I have bought a number of 3D books. In some of the general ones (like
>>Advanced Animation and Rendering Techniques), there is a 4th coordinate called
>>the 'w' coordinate. However, in some of the more specific programming books (like
>>the Black Art of 3D Game Programming), I don't believe the w coordinate is used
>>at all. So I'm wondering...is the w coordinate usually used in 3D games, such as
>>Unreal and Quake? If someone could also shed some light on the purpose of the
>>w coordinate (since I am still a bit fuzzy on that), it would be most appreciated.
>>Thanks in advance!
>>
>>----Blah

Hi, here is what I think (but it might be wrong like I usually am about this kind of stuff as I'm still kind of new to this confusing 3d stuff)

Here is one case where I think you need the w coord.
Suppose you have tons of vertices and you need to do several (like 10 or something)transformations on each vertex in a loop.
You could do each transform individually (without matrices). But that is time consuming.

So what we'd want to do is do all the 10 transforms in only one matrix multiply in each cycle. This is possible with the w coord (or 4x4 matrices) but not 3x3 matrices.
You could do this with 3x3 matrices if the transforms only consisted of scales and rotations, but not translations (translations occur pretty often though)

For example, suppose you are writing a program that does animation (like games) and you have a file given to you.
You read in all the keyframes for the object, and interpolate between each keyframe using the times (only quaternion, scale, and translate keyframes at this time)
then you store the resulting scale, translate and quaternion, somewhere to be applied to an object.

Then you go thru a loop for each vertex of the object. You would have to:
Translate the object to the origin. (vertex-object.center)
tempvert=vertex
vertex.x = Dot Product of (tempvert, object.xaxis)
vertex.y =Dot Product of (tempvert, object.yaxis)
vertex.z =Dot Product of (tempvert, object.zaxis)
//This is a change of basis to the orthonormal basis defined by xaxis, yaxis and zaxis, you //can change using dot prods b/c it is orthonormal
///and together with the movement to the origin before , it effectively changes vertex to the ///object coordinate system
Translate and scale and rotate the object as said in the keyframes
And finally do the reverse of the above coordinate system change

Yes, but if you have LOTS of vertices, and did this for each loop cycle that would be slow.
So what I think should be done is
first get and identity 4x4 matrix
[1000]
[0100]
[0010]
[0001]

and precompute all the transformations and get Matrix M like this:
M=
[1000] [1000]
[0100] * [0100] *
[0010] [0010]
[0001] [-objectcenter.x, -objectcenter.y -objectcenter.z, 1]

[xaxis.x, yaxis.x, zaxis.x, 0] [1000]
[xaxis.y, yaxis.y, zaxis.y, 0] * [0100]
[xaxis.z, yaxis.z, zaxis.z, 0] [0010]
[0, 0, 0, 1] [keyframetransx, keyframetransy, keyframetransz, 1]

[keyframescalex, 0, 0, 0]
[0, keyvframescaley, 0, 0]
[0, 0, keyframescalez, 0]
[0, 0, 0, 1]
///now the quaternion is a little complicated but
//if you have quaternion W X Y Z then..
/// (e means to the second power)

[1-2ye-2ze, 2xy-2wz, 2xz+2wy, 0] [xaxis.x, xaxis.y, xaxis.z 0]
* [2xy+2wz, 1-2xe-2ze, 2yz-2wx, 0] * [yaxis.x yaxis.y, yaxis.z 0]
[2xz-2wy, 2yz+2wx, 1-2xe-2ye, 0] [zaxis.x zaxis.y, zaxis.z, 0]
[0 ,0, 0, 1] [0,0, 0, 1]

* [1, 0, 0, 0]
[0, 1, 0, 0]
[0, 0, 1, 0]
[ocenterx, ocentery, ocenterz, 1]


NOW you have matrix M. Whew that was long

Now since you got that matrix
enter the loop
and for each vertex you only need to multiply the vertex by M

veretx =[x, y, z, 1] * M (notice you need to put the vertex on the left side in this case)
and it will be equivalent to doing ALL those transforms listed above, but with only one matrix multiplication! (Only possible with 4x4 matrices and w coord if you look at calculation of M).
You would do all this: change to object coords, keyframe trans, keyframe scale, keyframe rotate by quaternion, change back to world coord (or whatever the next coord system up is)
in one matrix multiply per vertex.

Sorry if everyone knew this already but, I just recently figured it out,
(I was doing all the keyframe transforms individually per loop cycle without matrices)

Ok, thanks for reading anyway.































 
SLI9000

July 02, 1999, 11:32 PM

Oh yeah, another use for the w coord...

when you do projection you do it like this right?
suppose u, v is screen space, and x, y, z is a 3-D point.
then u, v= (xk/z, yk/z).
This projection can actually be considered a use of a 4x4 matrix and homogeneous coords:
[x, y, z, 1] is the 3d point from above with w coord of 1 (standard affine subspace)

[1 0 0, 0]
[x, y, z] * [0 1 0, 0]
[0 0 1, 1/k]
[0, 0, 0, 0]

the resulting matrix is [x, y, z, z/k]
But say this is in homogeneous coords. SO you have to homogenize (divide each coord by w)
so you get [xk/z, yk/z, k, 1]
Notice the x, y vals of this
This is exactly the xk/z, and yk/z from above!

 
This thread contains 5 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.