Results 1 to 3 of 3

Thread: aligning vectors?

  1. #1
    Member Contributor
    Join Date
    May 2001
    Posts
    54

    aligning vectors?

    Hello,
    If I have 2 vectors and I want to align one so that it points in the same direction as the other, what would be the best way to do it.

    I read of one method, that finds the rotation axis by taking the cross product of the 2 vectors. Then uses the dot product to find the rotation angle. Then, I imagine, you would need to construct a rotation matrix based on this new axis.
    This is where I get messed up. If anyone has a link to a site that explains rotation matrix construction, or could explain it themselves, I would be most happy..
    Thanks,

    Jeremy

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: aligning vectors?

    If you know the rotation axis and the angle you want to rotate, you can just use glRotate(angle, rotX, rotY, rotZ) where rotX, rotY, rotZ define the rotation axis.

    If you want to know the math involved, the formula for determining the rotation matrix is shown in the back of the Red Book, which you can find online. (Sorry... I don't have a URL offhand, a quick search for Red Book should find it, though.)

    The way you calculate the matrix for rotations about the major axes is pretty straightforward, but about an arbitrary axis it gets a bit more complex. I actually had posted some code here awhile ago that builds a matrix from a call similar to glRotate, so if you really want you can search the forms a bit and find that.

    Edit: Found the recent thread about how to calculate the matrix for an arbitrary rotation.
    http://www.opengl.org/discussion_boa...ML/008020.html


    [This message has been edited by Deiussum (edited 04-19-2002).]
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Member Contributor
    Join Date
    May 2001
    Posts
    54

    Re: aligning vectors?

    thanks,

    The only problem is that I might need to align the vectors before gl is initialized.

    But thanks, I will check in the red book, i can find the link.


    I will also check out the thread you mentioned.
    Jeremy

    [This message has been edited by Jeeeez (edited 04-19-2002).]

Similar Threads

  1. Drawing & aligning textures & view
    By ReturnVoid in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-02-2015, 01:10 AM
  2. Replies: 8
    Last Post: 08-30-2010, 03:29 PM
  3. Problem Aligning Textures
    By cpsmusic in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-20-2006, 12:52 PM
  4. Aligning a frustum view with an ortho view
    By Siwko in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 05-22-2001, 04:52 AM
  5. Aligning the world...
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-15-2000, 08:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean