3D projections, line clipping, and transformations

So, for the past few weeks, I’ve been working on implementing projections for arbitrary 3D view volumes
my code, and a win32 executable

This demonstration rotates a solid about in space. However, you will quickly notice that it does not do it correctly. Something goes terribly wrong, and the bugger starts to distort. It does eventually come back to normal, so I’m uncertain what is happening. Perhaps it’s the rotation function, buried deep in the dark pits of hell.

I know it’s a lot of code, but I am at my wits end. I spent 12 straight hours completely rewriting the projection code from a week before (luckily it actually does something now). It’s only parallel (orthogonal) projections at this moment. I do have code for perspective, however I’m fairly certain it is more broken than my bank account. Any advice would be appreciated.

It works now. You were a little off on how you handled your rotation. I modified your rotation function.

void rotate( const real ax, const real ay, const real az){

matrix rot;

long double c2r = (long double)3.1415926435898F / (long double)180;

float cosX = cos(ax * c2r);
float sinX = sin(ax * c2r);

float cosY = cos(ay * c2r);
float sinY = sin(ay * c2r);

float cosZ = cos(az * c2r);
float sinZ = sin(az * c2r);



multMatrix(transMatrix, rot);


multMatrix(transMatrix, rot);


multMatrix(transMatrix, rot);

You have to rotate each axis seperately and rest the matrix after each axis but you have to do the Z plain first. Each axis requires two sin and cos values and you had the wrong fields set for each. There is overlap from one axis to the other.

This is how I’m calling your “rotate” function now.

float test1 = 0;
void display (void)
… your other stuff

rotate( test1, -test1, test1 );
test1 += 20;

works like a charm!


that’s weird. i had decided that it was the rotation function, but everything I found was saying my math was absolutely correct, including my book “Computer Graphics: Principles and Practice” by Foley, van Dam, Feiner, and Hughes.

I don’t know about that book. Perhaps what they were doing doesn’t translate to a 4x4 matrix. There are 2x2, 3x3 matrixes as well. I don’t know.

figured it out, wasn’t normalizing my axis of rotation.