hi,

i coded a small wireframe engine, but i am having some problems with more complex forms, like toroids.

with simple forms, like cubes and piramids, there are no problem.

but with the toroid, it get distorted at certain angles. i calculate the toroid as follow:

Code:
#define DegToRad 0.017453293f

    //create toroidal object
	toroide=create_object();
	int c=0;
	
	//walk in 45 degrees steps
	for(int j=0;j<360;j+=45)
	{
	    //calculate circle position relative to toroid body
		float xx=sin(j*DegToRad)*20;
		float yy=cos(j*DegToRad)*20;

        //walk in 20 degrees steps
		for(int i=0;i<360;i+=20)
		{
		    //build toroidal face
			float x=sin(i*DegToRad)*100;
			float y=cos(i*DegToRad)*100;
			add_vector(toroide,x,y+yy,xx);
		}
		
		//link the vectors generated in step above, forming a a circular poligon
		for(int i=1;i<=360/20;++i)
		{
			add_line(toroide,c+i,((i==360/20)?c+1:c+i+1));
		}
		c+=360/20;
		
		//generate next toroid face
	}

    //link each face to others faces
	for(int i=1;i<=360/20;++i)
	{
		int s=i;
		//vector 1 is linked to vector 1+(number of vectors in face * face), till form a ring
		for(int j=1;j<=360/20;++j)
		{
			int r=(j==360/20)?i:i+(j*(360/20));
			add_line(toroide,s,r);
			s=r;
		}
	}
the problem, seens to me, is in the xx and yy calculation. but also can be in my vector_to_2d() function.

Code:
void vector_to_2d(float x,float y,float z,DWORD *x0,DWORD *y0)
{
    *x0=(DWORD)((MAX_X/2)+(x*((MAX_Z/2)/((MAX_Z/2)-z))));
    *y0=(DWORD)((MAX_Y/2)+(y*((MAX_Z/2)/((MAX_Z/2)-z))));
}
my MAX_X and MAX_Y are 640 and 480, respectively. as MAX_Z, i tried several values, ending with 500. all values for MAX_Z show the distortion problem, but with 500 the problem is smaller.

i dunno, but maybe the MAX_Z distortion is not related to my main distortion problem, but only a effect of perspective.

below i attach 2 pictures: 1 angle where it look right, and other wrong.

any suggestion in how correct the problem?

jmgk

ps: sorry for my bad english: i fell it is a barrier to describe my problem and my algo :-(