PDA

View Full Version : extrude along an arbitrary vector?



wmelgaard
06-03-2017, 09:20 AM
I have arbitrary orthogonal vectors float X[3], Y[3], Z[3];
where X is the vector that I want to extrude a polygon that is in Y, Z coordinates.
For example, I have a polygon (-.25,3; 2,3; 2,2.5; .25,2.5; .25,-2.5, 2,-2.5, 2,-3; -.25,-3)
which I want to extrude along the arbitrary (not global) X axis with a length L
The origin of this extrusion is at (x, y, z), where (x, y, z) are in global coordinates.

Presumably, all that I need is the appropriate glRotate command, but I can't figure out how to get that directly from the X, Y & Z vectors.

GClements
06-03-2017, 01:10 PM
Presumably, all that I need is the appropriate glRotate command, but I can't figure out how to get that directly from the X, Y & Z vectors.
glRotate() generates an orthonormal matrix, but there's no requirement that X,Y,Z are orthonormal.

You probably want glMultMatrix(), with X, Y, Z and the origin forming the columns and the fourth row being [0,0,0,1].

Translation along the X axis by distance L corresponds to following that with glTranslate(L,0,0).

wmelgaard
06-03-2017, 09:20 PM
That works
For my example, polygon in Y-Z plane, extruding in X; origin at GLfloat x,y,z:

GLfloat matrix[16];
glPushMatrix();
glTranslatef(x, y, z);
matrix[0] = Y[0]; matrix[1] = Y[1]; matrix[2] = Y[2]; matrix[3] = 0.0;
matrix[4] = Z[0]; matrix[5] = Z[1]; matrix[6] = Z[2]; matrix[7] = 0.0;
matrix[8] = X[0]; matrix[9] = X[1]; matrix[10] = X[2]; matrix[11] = 0.0;
matrix[12] = 0; matrix[13] = 0; matrix[14] = 0; matrix[15] = 1.0;
glMultMatrix(matrix);
glBegin(GL_QUAD_STRIP);
...(sides of polygon)
glEnd();
glPopMatrix();
Thank you very much.


glRotate() generates an orthonormal matrix, but there's no requirement that X,Y,Z are orthonormal.

You probably want glMultMatrix(), with X, Y, Z and the origin forming the columns and the fourth row being [0,0,0,1].

Translation along the X axis by distance L corresponds to following that with glTranslate(L,0,0).