Hi everyone, wondering if you would please be able to help me on a few things,
I've got a Zbuffering assignment which I'm almost there on, but a few things are giving me problems/errors and I'd hugely appreciate if anyone could find the solution for me. I'll put each question, and then the relevant code I currently have for that section,
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1. "Initialise the z buffer before every frame. You should initialise all the values of zbuf to zero at the start of DrawImage so that the z buffer is initialised at the start of every frame."
I currently have the zbuffer array declared as
double zbuf[WINDOWWIDTH][WINDOWHEIGHT]
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void DrawImage( )
{
zbuf == 0;
POLYGON polyTempP, polyTempQ, polyTempQT; // Temporary polygons for copying transformed, projected / clipped
// versions of scene polys before drawing them.
int iCurrentPoly; // Current polygon in process
TRANSFORM object_transformation=BuildTrans(m_dThetaX,m_dThetaY,m_dThetaZ,m_vDisp);
VECTOR view_in_object_coordinates=MOnV(InverseRotationOnly(object_transformation),m_vDisp);
if ( m_iNumOfPolys <= 0 )
DrawSquare(Default_Colour ); // This draws the square you see, replace with Trapezium, and later Polygon
else
m_iOurFrameCount++; // Increment frame counter if we have a polygon to draw
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2. "add a z parameter to drawtrapezium. This will need to be a double. The formal parameter ( call it current_z) needs to be added to the function definition and to the prototype. Where the function is called in drawpolygon use the actual parameter
poly->vert[0].z
i.e. the z coordinate of polygon vertex zero. This is a 1/z value, calculated in project and copied through my versions of the clipping functions – beware if you are using your own clipping function."
And also included in the same section,
3. "add the test within drawtrapezium. Just before the call to Plotpix put in an if statement comparing current_z to the value of zbuf at the point where you will be plotting. If the current_z value is larger you want to proceed with the Plotpix AND update the zbuf value to be the same as the “winning” value of current_z."
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
void DrawTrapezium(COLOUR c,int current_y,int yfin,INCREMENTEE x)
{
// current_y is the y coord of the trapezium top and is used as a
//running total through the routine
// x_left and x_right are the x coordinates of the top of the trapezium
//they are passed as pointers so that the values can be
//returned back to the polygon routine at the end to form the top of the next trapezium.
//(A reference could have been used here
//but I am trying to keep this program compatible with C rather than C++)
//Loop around line by line
int current_x;
if (current_y>yfin) return;
while(1)
{
for (current_x= *x.left;current_x<= *x.right;current_x++)
{
Plotpix(current_x,current_y,c.r,c.g,c.b);// This line plots a pixel
}
if (current_y>=yfin) break;
current_y++;
*x.left+=x.slopeleft; *x.right+=x.sloperight;//increment endpoints
}
}
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks a lot in advance to anyone who can assist me with this :-)