# seemingly small problem with extuding an ngon along a path in a local cord system

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;

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 =	   u.x;   m =    u.y;    m =  u.z;     m = pathStart.x;
m =     v.x;   m =    v.y;    m =  v.z;     m = pathStart.y;
m =  path.x;   m = path.y;   m =  path.z;  m = pathStart.z;
m =       0;   m =	  0;   m =  0;       m =		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

for(int k=0;k&lt;n;k++)
{
angle+=angleInc;

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).]

bump