Results 1 to 6 of 6

Thread: Matrix LookAt

  1. #1

    Matrix LookAt

    Anyone know where i could find function that does the LookAt? Meaning, it creates a rotation matrix that points to a specific point in 3D space. There is function like gluLookAt that does this but i need it for my bone editing mode Google has not helped much, other than this:
    http://www.euclideanspace.com/maths/...okat/index.htm
    Code:
    void LookAt(const vector3& dir, const vector3& up, matrix33& m) { 
            vector3 z(dir); 
            z.norm(); 
            vector3 x( up * z ); // x = up cross z 
            x.norm(); 
            vector3 y( z * x ); // y = z cross x 
            m.set_components(x,y,z ); 
    }
    I'll post here if i can get that translated but help or ready source is appreciated

  2. #2

    Matrix LookAt

    for opengl i use this:

    [pascal]
    function lookat(cameraPosition, cameraTarget: tvector4f): tmatrix4x4;
    var zaxis, xaxis, yaxis: tvector4f;
    begin
    cameratarget := multiply(cameratarget,-1);
    zaxis := normalize(sub(cameraTarget, cameraPosition));
    xaxis := normalize(cross(vector4f(0,1,0,0), zaxis));
    yaxis := cross(zaxis, xaxis);

    result := matrix4x4(xaxis.x, yaxis.x, zaxis.x, 0,
    xaxis.y, yaxis.y, zaxis.y, 0,
    xaxis.z, yaxis.z, zaxis.z, 0,
    -dot(xaxis, cameraPosition), -dot(yaxis, cameraPosition), -dot(zaxis, cameraPosition), 1);
    end;
    [/pascal]
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3

    Matrix LookAt

    You can find gluLookAt implementation in Mesa3D source code. http://mesa3d.org/

  4. #4

    Matrix LookAt

    Just be aware that the Up vector is hard coded in the example above... If you want it to be Really flexible, you can replace vector4f(0,1,0,0) with your own Up direction in your engine.
    My site: DelphiTuts.com (coming soon)...

    Download Font Studio 4.21 here.

  5. #5

    Matrix LookAt

    Quote Originally Posted by Nitrogen
    Just be aware that the Up vector is hard coded in the example above... If you want it to be Really flexible, you can replace vector4f(0,1,0,0) with your own Up direction in your engine.
    Oh yes indeed.. i forgot to tell that
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  6. #6

    Matrix LookAt

    Thanks for quick helps, i got the first code and JSoftware's version compiled and i think working well. Good signs is both functions acted about same way in my program. But the problem was not solved with that

    The actual issue is about "modifying bones"... This means that i have a bone tree, i can focus on 1 bone and when i hold mouse the bone should follow the cursor. For this purpose i have already calculated a virtual plane at which cursor hovers at and creates a 3D point. That point is then transformed into last bone's rotation space. Thus far everything works perfectly, but when i try to get bone rotation towards cursor point it misses the target...

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
  •