Hi, everyone!
I am a student of Computer Science, and i’m currently occupied with the following task.
I’m doing some 3D visualization, and i’m supposed to do it both using OpenGL and my own -made graphical routines.
What i’m trying to do is: i’m trying to write my own 3d routines the way that everything would look similar to OpenGL.
So, i made transformation routines, as well as manipulations with my own Model-view and Projection matrixes, - it’s quite clear to me how it works in OpenGL, and i stumbled over a triangle visualization routine.
So, the problem is:
I’ve got 3 vertexes: v1,v2,v3, ModelView matrix: M, and Projection matrix P.
v’1=P*(Mv1);
v’2=P(Mv2);
v’3=P(M*v3);
After making these calculations, new coordinates are given in the canonical view volume (x=-1…1 y=-1…1 z=-1…1).
So, i should clip everything, that is out of this cube of visibility. And i’m completely lost - i don’t know how to do that, because i don’t know how OpenGL would do that clipping.
First, i was drawing every point of a triangle (v’1, v’2, v’3) pixel by pixel, checking if a current particular pixel fits a visibility cube, it’s slow, but it works.
But imagine that one vertex of the triangle was BEHIND the camera before the projection. It is projected completely wrong then, and i cannot use the drawing technique i described earlier.
What should i do?
Should i clip my triangle with the frustum planes before applying projection matrix? It’s a complicated task, and it may transform my triangle into quad or even pentagon!
I’m wondering how it is made in OpenGL?
I’d be very pleased, if somebody tells me how to solve this problem, or just gives me any link.
Thanks,
Grigory