Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Quaternion lookat

  1. #1

    Quaternion lookat

    Hi! Anybody here knows about an algorithm for quaternion that orients it to look to a given vector ? (eventually with the up vector too)
    Something like:

    lookAt( target, up:TVector):TQuaternion

    Thanks
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  2. #2

    Quaternion lookat

    If no one gets a better idea and you?¢_Tre not too lazy you could snap matrix to quaternion conversion code onto gluLookAt.
    Mesa?¢_~s gluLookAt looks likes this:
    Code:
    void GLAPIENTRY
    gluLookAt&#40;GLdouble eyex, GLdouble eyey, GLdouble eyez,
    	  GLdouble centerx, GLdouble centery, GLdouble centerz,
    	  GLdouble upx, GLdouble upy, GLdouble upz&#41;
    &#123;
       GLdouble m&#91;16&#93;;
       GLdouble x&#91;3&#93;, y&#91;3&#93;, z&#91;3&#93;;
       GLdouble mag;
    
       /* Make rotation matrix */
    
       /* Z vector */
       z&#91;0&#93; = eyex - centerx;
       z&#91;1&#93; = eyey - centery;
       z&#91;2&#93; = eyez - centerz;
       mag = sqrt&#40;z&#91;0&#93; * z&#91;0&#93; + z&#91;1&#93; * z&#91;1&#93; + z&#91;2&#93; * z&#91;2&#93;&#41;;
       if &#40;mag&#41; &#123;			/* mpichler, 19950515 */
          z&#91;0&#93; /= mag;
          z&#91;1&#93; /= mag;
          z&#91;2&#93; /= mag;
       &#125;
    
       /* Y vector */
       y&#91;0&#93; = upx;
       y&#91;1&#93; = upy;
       y&#91;2&#93; = upz;
    
       /* X vector = Y cross Z */
       x&#91;0&#93; = y&#91;1&#93; * z&#91;2&#93; - y&#91;2&#93; * z&#91;1&#93;;
       x&#91;1&#93; = -y&#91;0&#93; * z&#91;2&#93; + y&#91;2&#93; * z&#91;0&#93;;
       x&#91;2&#93; = y&#91;0&#93; * z&#91;1&#93; - y&#91;1&#93; * z&#91;0&#93;;
    
       /* Recompute Y = Z cross X */
       y&#91;0&#93; = z&#91;1&#93; * x&#91;2&#93; - z&#91;2&#93; * x&#91;1&#93;;
       y&#91;1&#93; = -z&#91;0&#93; * x&#91;2&#93; + z&#91;2&#93; * x&#91;0&#93;;
       y&#91;2&#93; = z&#91;0&#93; * x&#91;1&#93; - z&#91;1&#93; * x&#91;0&#93;;
    
       /* mpichler, 19950515 */
       /* cross product gives area of parallelogram, which is < 1.0 for
        * non-perpendicular unit-length vectors; so normalize x, y here
        */
    
       mag = sqrt&#40;x&#91;0&#93; * x&#91;0&#93; + x&#91;1&#93; * x&#91;1&#93; + x&#91;2&#93; * x&#91;2&#93;&#41;;
       if &#40;mag&#41; &#123;
          x&#91;0&#93; /= mag;
          x&#91;1&#93; /= mag;
          x&#91;2&#93; /= mag;
       &#125;
    
       mag = sqrt&#40;y&#91;0&#93; * y&#91;0&#93; + y&#91;1&#93; * y&#91;1&#93; + y&#91;2&#93; * y&#91;2&#93;&#41;;
       if &#40;mag&#41; &#123;
          y&#91;0&#93; /= mag;
          y&#91;1&#93; /= mag;
          y&#91;2&#93; /= mag;
       &#125;
    
    #define M&#40;row,col&#41;  m&#91;col*4+row&#93;
       M&#40;0, 0&#41; = x&#91;0&#93;;
       M&#40;0, 1&#41; = x&#91;1&#93;;
       M&#40;0, 2&#41; = x&#91;2&#93;;
    
       M&#40;0, 3&#41; = 0.0;
       M&#40;1, 0&#41; = y&#91;0&#93;;
       M&#40;1, 1&#41; = y&#91;1&#93;;
       M&#40;1, 2&#41; = y&#91;2&#93;;
       M&#40;1, 3&#41; = 0.0;
       M&#40;2, 0&#41; = z&#91;0&#93;;
       M&#40;2, 1&#41; = z&#91;1&#93;;
       M&#40;2, 2&#41; = z&#91;2&#93;;
       M&#40;2, 3&#41; = 0.0;
       M&#40;3, 0&#41; = 0.0;
       M&#40;3, 1&#41; = 0.0;
       M&#40;3, 2&#41; = 0.0;
       M&#40;3, 3&#41; = 1.0;
    #undef M
       glMultMatrixd&#40;m&#41;;
    
       /* Translate Eye to Origin */
       glTranslated&#40;-eyex, -eyey, -eyez&#41;;
    
    &#125;

  3. #3

    Quaternion lookat

    Sssh... if we give him the answer he might win the dog fight competition. :lol:

  4. #4

    Quaternion lookat

    Quote Originally Posted by Sly
    Sssh... if we give him the answer he might win the dog fight competition. :lol:
    :lol: :lol:
    Just becouse i ask about quaternions, that are expecially useful with airplane models, that doesn't mean it's about the dog fight compo..
    Well, in this case, it is :mrgreen:

    Btw my entry is going on greatly.. just wait and see
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  5. #5

    Quaternion lookat

    Quote Originally Posted by Paulius
    If no one gets a better idea and you?¢_Tre not too lazy you could snap matrix to quaternion conversion code onto gluLookAt.
    Mesa?¢_~s gluLookAt looks likes this:
    Umm that could be an idea.. but i'm way too lazy Also i'm not that good with matrices and i could make some bug..
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Quaternion lookat

    :lol:
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #7

    Quaternion lookat

    ok.. apart from jokes :mrgreen:
    Any clue ? I need it quite a lot..

    Thanks
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  8. #8

    Quaternion lookat

    Nicola,
    If you are using JEDI-SDL, in the OpenGL directory you should find Mike Lischke's excellent Geometry.pas file which has all sorts of 3D functions including Quaternions.

    IHTH.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  9. #9

    Quaternion lookat

    Quote Originally Posted by savage
    Nicola,
    If you are using JEDI-SDL, in the OpenGL directory you should find Mike Lischke's excellent Geometry.pas file which has all sorts of 3D functions including Quaternions.

    IHTH.
    I've already looked there, but there is not a big support for quaternions. There are only basic functions.

    I'm assembling a unit that is more complete, so btw if you want to use it on JEDI-SDL just ask. It's based on FastGEO for vectors and the like (but it can easily be changed)
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  10. #10

    Quaternion lookat

    I've spotted this article.
    It tells something about how to obtain axis angle representation of the rotation of a given vector to another. It doesn't uses the up vector, but it can still be useful..

    I tryed and implemented this:
    [pascal]
    v:=mul(a.position, b.position); // cross product
    b.orientation.x:=v.x;
    b.orientation.y:=v.y;
    b.orientation.z:=v.z;
    b.orientation.w:= magnitude(a.position) * magnitude(b.position) + dotproduct( unitvector(b.position), unitvector(a.position));
    Q_normed(b.orientation);
    [/pascal]
    It should orient b to a but it doesn't work..
    Anyone interested in helping ?
    Thanks
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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