PDA

View Full Version : Projection & Rasterization



Josejulio Ma
07-01-2010, 09:41 AM
I am trying to do a simple raster (only shapes, no light, no colors) for an occlusion test. I give 3 points (on the screen coordinates) to the raster and it draws the polygon.
So, before i need to process my 3d polygons vertices on object coordinates and convert them to screen coordinates, i google'd, search and stuff and came up with an algorithm that is similar to the gluProject (which i found on mesa source).

gluProject documentation: http://www.opengl.org/sdk/docs/man/xhtml/gluProject.xml

x y z w
v = (object.x, object.y, object.z, 1.0)
P = Projection Matrix
M = ModelView Matrix
Viewport = (0, 0, 512, 512)

v' = P x M x v
v' = v' / v.w // We divide every xyzw by w, this step is not in the gluProject documentation.

screen.x = Viewport(0) + Viewport(2) * (v'.x + 1) * 0.5
screen.y = Viewport(1) + Viewport(3) * (v'.y + 1) * 0.5
screen.z = (v'(2) + 1) * 0.5

---

Well, after that, my problem is the following:

When i have an scenario like: [_] is a polygon and C is a camera, and > is the frustum
_____
[ ]
[ ]
[ ] > C
[ ]
[_____]

Everything is ok, the screen values are inside and the triangles get draw. But if i rotate along Up Axis, the polygon starts to disappear, the points get outside the screen, for instance: A point starts poping out for the right, and tends to get positive, and grow bigger bigger (no big problem), but it gets to a point where it is on the LEFT side of the screen... Am not sure what is really happening or how to fix it. Any help would be really usefull.

Some screens:

This is when i start moving and things are good.
http://dl.dropbox.com/u/7600660/good.png

This is when i rotate the camera and things get screw up: http://dl.dropbox.com/u/7600660/bad.png
Notice that the points get to the left side.

Hope i made myself clear, thanks and sorry for the big rant.