
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. (vertexobject.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)
[12ye2ze, 2xy2wz, 2xz+2wy, 0] [xaxis.x, xaxis.y, xaxis.z 0] * [2xy+2wz, 12xe2ze, 2yz2wx, 0] * [yaxis.x yaxis.y, yaxis.z 0] [2xz2wy, 2yz+2wx, 12xe2ye, 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.
