I do have a question - how do I project my vertices to screen space via a projection matrix? Currently all my rotations, scaling, translations, and transformations are done via matrices but my projection is done separately. I would like to do it via a matrix.

I know the projection matrix is this:

1 0 0 0

0 1 0 0

0 0 1 0

0 0 1/D 0

But can I use this concatenate function with it and if I can then where are the screen coords at in the final matrix??

Code:

void MatMult(double m1[4][4],double m2[4][4],double r[4][4])
}
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
for (int k=0;k<4;k++)
{
r[i][j]+=m1[i][k]*m2[k][j];
}
}
}
}

I know I can unroll the inner loop but I didn't cuz the huge line of code would not fit well in this window.

And here is my Viewtransform code:

Code:

//Transforms world vertexes to view vertexes
void ViewTransform(vertex *vtxs,int numvtxs)
{
for (int i=0;i<numvtxs;i++)
{
double x=vtxs[i].world.x;
double y=vtxs[i].world.y;
double z=vtxs[i].world.z;
double vx=x*matrix[0][0]+y*matrix[0][1]+z*matrix[0][2]+matrix[0][3];
double vy=y*matrix[1][0]+y*matrix[1][1]+z*matrix[1][2]+matrix[1][3];
double vz=z*matrix[2][0]+y*matrix[2][1]+z*matrix[2][2]+matrix[2][3];
vtxs[i].view.x=vx;
vtxs[i].view.y=vy;
vtxs[i].view.z=vz;
}
}

Then my project function:

Code:

void Project(vertex *vtxs, int numvtxs,double vdist,int cx,int cy)
{
for (int i=0;i<numvtxs;i++)
{
double vx=vtxs[i].view.x;
double vy=vtxs[i].view.y;
double vz=vtxs[i].view.z;
double sx=vx*vdist/vz+cx;
double sy=vy*vdist/vz+cy;
vtxs[i].screen.x=sx;
vtxs[i].screen.y=sy;
}
}

But I want to project via the projection matrix using my concatenate or MatMult() function if possible. Note, I know DirectX and OpenGL do this for you but I want to know whats going on underneath it all - this is from my small DOS 3D engine written in DJGPP or 32-bit C.