Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: extrude along an arbitrary vector?

  1. #1
    Intern Newbie
    Join Date
    Nov 2013
    Posts
    41

    extrude along an arbitrary vector?

    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.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,404
    Quote Originally Posted by wmelgaard View Post
    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).

  3. #3
    Intern Newbie
    Join Date
    Nov 2013
    Posts
    41
    That works
    For my example, polygon in Y-Z plane, extruding in X; origin at GLfloat x,y,z:
    Code :
    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.

    Quote Originally Posted by GClements View Post
    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •