This topic is now archived and is closed to further replies.


Transformation pipeline for software rast

Recommended Posts

I''m writing a wireframe 3d rasterizer...but i''m having a really hard time with putting it all together. Things show up in the wrong place, rotate around arbitrary axis even though i thought i had done everything in the right order. Here''s my pipeline: Model->world rotation Model->world translation World->camera rotation (inverse of camera rot) World->camera translation (inverse of camera position) by the way, I am not using matrices because I do not completely understand them, and that is the whole point of this exercise- to understand basic 3d mathematics. Any ideas would be appreciated. Brian

Share this post

Link to post
Share on other sites
JuNC    236
My suggestion would be work on a matrix math library, get that right and then implement the graphics.

You will save yourself lots of headaches by going with matrices first, it might sound like lots of work but there are plenty of math tutorials around to let you implement all the functions you need (only setup code and multiplication would be required at first).

Share this post

Link to post
Share on other sites
I have a matrix class I put together from pieces on other sites, but I still dont know what order to concatenate etc. How would the matrix math produce a different result...i mean, I''m doing the same operations. thanks though for your opinion...i may try matrices again


Share this post

Link to post
Share on other sites
lunarss    169
Here is a general rundown of what you should do:

1) Transform your model about its local coordinate system. This includes any rotation, scaling, skewing, and translation.

2) Set up a world matrix and a view matrix. Concatenate them. The world matrix describes where in the world coordinate space you want your model to be. Think of the view matrix as describing the camera. Apply the final concatenated world/view matrix to your model.

2a) This is a better way to set up your camera. Say you have 2 points, A and B. A is your camera and B is the object you want to look at. (A) should have a system of orthogonal vectors that describe its orientation IE. Up, Lookat, Right

Here is how you build a view matrix.

Get a new lookat vector for A.
A.Lookat = B.Pos - A.Pos

Normalize A.Lookat

Get a new orthogonal right vector for A.
A.Right = A.Up X A.Lookat

Normalize A.Right.

Get a new orthogonal up vector for A.
A.Up = A.Right X A.Lookat

Normalize A.Up

Your camera's coordinate system is now rotated towards the new point. Now you have to build a matrix with these values. It should look like this for a right handed coordinate system.

A.Right.x A.Up.x A.Lookat.x 0
A.Right.y A.Up.y A.Lookat.y 0
A.Right.z A.Up.z A.Lookat.z 0
-dot(A.Right, B.Pos) -dot(A.Up, B.Pos) -dot(A.Lookat, B.Pos) 1

Concatenate this with your world matrix and apply it to all of your model's coordinates.

3)Perform the perspective projection. Look this up on google since there are many different ways to do it. This is the matrix I've always used (again, for a right-handed coordinate system):

2*zn/w 0 0 0
0 2*zn/h 0 0
0 0 zf/(zn-zf) -1
0 0 zn*zf/(zn-zf) 0


//zn = the z value of the near plane

//zf = the z value of the far plane

//h = the height of your viewing window (ie 600 pixels)

//w = the width of your viewing window (ie 800 pixels)

Now apply that matrix to all of your model's coordinates.

4)After the perspective projection, your coordinates should be in 2-d. Now, if you just want wireframe, use Bresenham's algorithm to draw lines between your x,y points. You're done.

Let me know if I left anything out or forgot something. Its been a while since I've done that stuff. ; )

Keep in mind that there are other steps involved if you want to do texture mapping or other effects. I completely agree with JuNC on getting a math library put together. Make a matrix class, and a vector class. In each of those, overload operators to do matrix/vector multiplications. You'll be very glad that you did, and it will save you a lot of headache in the end. Hope I helped.

[edited by - lunarss on March 18, 2003 2:30:08 PM]

Share this post

Link to post
Share on other sites