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 2 of 2

Thread: gluCylinder in a specific direction

  1. #1
    Junior Member Regular Contributor
    Join Date
    Aug 2000
    Location
    Los Angeles, CA, USA
    Posts
    116

    gluCylinder in a specific direction

    Hi,

    I want to draw a cylinder with top pt at (1., 1., 1.) and an axis pointing to (2., 2., 2.). Could someone help me to finish the following code? Bascially I have the problem with the rotation part? The cylinder should be correctly shown even after the model is rotated. Thanks very much for your help.

    glPushMatrix();
    glTranslated(1., 1., 1.);
    glRotate(?, ?, ?);
    gluCylinder(pQuarObj, .0, 1., 1., 100, 100);
    glPopMatrix();

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2002
    Location
    Espoo, Finland
    Posts
    599

    Re: gluCylinder in a specific direction

    Damn, I stink at this kind of math, but since nobody else is answering, I'll give it a try.

    So you have to rotate cylinder's original axis (0, 0, 1) to a new one, in your case (1, 1, 1). You get the axis around which to rotate by calculating a cross product between these two. The angle is simply the angle between the two vectors, which is
    arcCos(dot(a1, a2)/(|a1|*|a2|).

    Then just use glRotatef(angle, axis[0], axis[1], axis[2]). Use at own risk.

    -Ilkka

Posting Permissions

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