wildeyedboyfromfreecloud

02-05-2002, 08:16 AM

Well this is the algorithm i have so far. it is used to draw the limbs of a tree by extruding an ngon along its skeleton. btw i got my tree algorith to work. they look beautiful and have leaves and blow in the wind. i have my local cooridinate system at every branch. and i need my z axis to be aligned with the direction of the branch. i have played with it and gotten to look as if it is aligned only one axis is or axis component is mirrored to what it should be. i'm not sure about the up vector. it seems to me that it could as well be arbitrary but maybe not. and i don't understand why changing the values of the up vector has any effect on the path vector. but it seems to. well assuming i want my path vector to be the z axis. which in fact it may not be under this implimentation. this is the code. i'm assuming this is a very routine operation. please help if you can. i really apreciate all the attention this board has supplied. much more useful than most any others. and i hope one day i will have the leisure to return the favor.

sincerely,

Michael

void extrudedNgon(int n, Point3 pathStart, Point3 pathEnd, float length, float radius, float radius2, float rotAngle)

{

if(n<3) return;

Vector3 path;

Vector3 u;

Vector3 v;

Vector3 up; up.set(0,0,1);

float m[16];

path.set(pathStart.x - pathEnd.x, pathStart.y - pathEnd.y, pathStart.z - pathEnd.z);

u.set(up.cross(path));

path.normalize(); u.normalize();

v.set(path.cross(u));

m[0] = u.x; m[4] = u.y; m[8] = u.z; m[12] = pathStart.x;

m[1] = v.x; m[5] = v.y; m[9] = v.z; m[13] = pathStart.y;

m[2] = path.x; m[6] = path.y; m[10] = path.z; m[14] = pathStart.z;

m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1.0;

glMatrixMode(GL_MODELVIEW);

glPushMatrix();

glMultMatrixf(m);

//@@@@@@@@@@@@@@ draw local coord system @@@@@@@@@@@@@@@@@@@

glDisable(GL_LIGHTING);

glBegin(GL_LINES);

glColor3f(0.0,0.0,1.0);

glVertex3f(0,0,0);

glVertex3f(0,0,length);

glColor3f(0.0,1.0,0.0);

glVertex3f(0,0,0);

glVertex3f(length/2,0,0);

glColor3f(1.0,0.0,0.0);

glVertex3f(0,0,0);

glVertex3f(0,length/2,0);

glColor3f(1.0,1.0,1.0);

glEnd();

//@@@@@@@@@@@@@@ end of draw local coord system @@@@@@@@@@@@@@@@@@@

glEnable(GL_LIGHTING);

// draw a tapered extrude ngon in local coord space along z axis

float angle = rotAngle * PI / 180; // initial angle

float angleInc = 2 * PI / n; // angle increment

glBegin(GL_QUADS);

glVertex3f(radius*cos(angle), radius*sin(angle),0);

glVertex3f(radius2*cos(angle), radius2*sin(angle),length);

for(int k=0;k<n;k++)

{

angle+=angleInc;

Point3 v1; v1.set(radius*cos(angle), radius*sin(angle),0);

Point3 v2; v2.set(radius2*cos(angle), radius2*sin(angle),length);

glVertex3fv(v2.v);

glVertex3fv(v1.v);

glVertex3fv(v1.v);

glVertex3fv(v2.v);

}

glEnd();

glPopMatrix();

}

[This message has been edited by wildeyedboyfromfreecloud (edited 02-05-2002).]

sincerely,

Michael

void extrudedNgon(int n, Point3 pathStart, Point3 pathEnd, float length, float radius, float radius2, float rotAngle)

{

if(n<3) return;

Vector3 path;

Vector3 u;

Vector3 v;

Vector3 up; up.set(0,0,1);

float m[16];

path.set(pathStart.x - pathEnd.x, pathStart.y - pathEnd.y, pathStart.z - pathEnd.z);

u.set(up.cross(path));

path.normalize(); u.normalize();

v.set(path.cross(u));

m[0] = u.x; m[4] = u.y; m[8] = u.z; m[12] = pathStart.x;

m[1] = v.x; m[5] = v.y; m[9] = v.z; m[13] = pathStart.y;

m[2] = path.x; m[6] = path.y; m[10] = path.z; m[14] = pathStart.z;

m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1.0;

glMatrixMode(GL_MODELVIEW);

glPushMatrix();

glMultMatrixf(m);

//@@@@@@@@@@@@@@ draw local coord system @@@@@@@@@@@@@@@@@@@

glDisable(GL_LIGHTING);

glBegin(GL_LINES);

glColor3f(0.0,0.0,1.0);

glVertex3f(0,0,0);

glVertex3f(0,0,length);

glColor3f(0.0,1.0,0.0);

glVertex3f(0,0,0);

glVertex3f(length/2,0,0);

glColor3f(1.0,0.0,0.0);

glVertex3f(0,0,0);

glVertex3f(0,length/2,0);

glColor3f(1.0,1.0,1.0);

glEnd();

//@@@@@@@@@@@@@@ end of draw local coord system @@@@@@@@@@@@@@@@@@@

glEnable(GL_LIGHTING);

// draw a tapered extrude ngon in local coord space along z axis

float angle = rotAngle * PI / 180; // initial angle

float angleInc = 2 * PI / n; // angle increment

glBegin(GL_QUADS);

glVertex3f(radius*cos(angle), radius*sin(angle),0);

glVertex3f(radius2*cos(angle), radius2*sin(angle),length);

for(int k=0;k<n;k++)

{

angle+=angleInc;

Point3 v1; v1.set(radius*cos(angle), radius*sin(angle),0);

Point3 v2; v2.set(radius2*cos(angle), radius2*sin(angle),length);

glVertex3fv(v2.v);

glVertex3fv(v1.v);

glVertex3fv(v1.v);

glVertex3fv(v2.v);

}

glEnd();

glPopMatrix();

}

[This message has been edited by wildeyedboyfromfreecloud (edited 02-05-2002).]