Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Normilze a Vector

  1. #11

    Normilze a Vector

    From what I can tell, that code gives you the angle between the two vectors. But this angle could be a rotation around any axis, that axis being the cross-product of the two vectors. That axis would most likely not be co-planar with any of the x, y or z axes, making the angle not much use when it comes to making an object look at something.

    I'll try to port the C code I gave before to Pascal.

    [pascal]procedure BuildLookAtMatrix(var pOut: D3DXMATRIX;
    const pEye: D3DXVECTOR3;
    const pAt: D3DXVECTOR3;
    const pUp: D3DXVECTOR3)
    var
    vRight: D3DXVECTOR3; // New x basis
    vUp: D3DXVECTOR3; // New y basis
    vView: D3DXVECTOR3; // New z basis
    begin
    // Subtract the camera's position from the viewer's position to
    // create a direction or view vector for the camera. We'll call
    // this vector, vView.
    D3DXVec3Subtract(vView, pAt, pEye);

    // Normalize our new z basis vector.
    D3DXVec3Normalize(vView, vView);

    // Take the cross-product of the new direction vector and the
    // x axis of the world space to get a right vector.
    // We'll call this vector vRight.
    D3DXVec3Cross(vRight, pUp, vView);
    D3DXVec3Normalize(vRight, vRight);

    // The cross-product of the direction vector (vView) and the
    // right vector (vRight) will give us our new up vector, which
    // we'll call vUp.
    D3DXVec3Cross(vUp, vView, vRight);

    // We now build the matrix. The first three columns contain the
    // basis vectors used to rotate the view to point at the look-at
    // point. The fourth row contains the translation values.
    // Rotations are still about the eye point.
    //
    // m11 m12 m13 m14
    // m21 m22 m23 m24
    // m31 m32 m33 m34
    // m41 m42 m43 m44

    pOut._11 = vRight.x;
    pOut._21 = vRight.y;
    pOut._31 = vRight.z;
    pOut._41 = -D3DXVec3Dot(vRight, pEye);

    pOut._12 = vUp.x;
    pOut._22 = vUp.y;
    pOut._32 = vUp.z;
    pOut._42 = -D3DXVec3Dot(vUp, pEye);

    pOut._13 = vView.x;
    pOut._23 = vView.y;
    pOut._33 = vView.z;
    pOut._43 = -D3DXVec3Dot(vView, pEye);

    pOut._14 = 0.0;
    pOut._24 = 0.0;
    pOut._34 = 0.0;
    pOut._44 = 1.0;
    end;[/pascal]

  2. #12

    Normilze a Vector

    thanks sly, but i dont know how to rotate then i dont know anything
    in D3D ^^"

    ok i upload a programm:
    http://daikrys.funpic.de/rotations.rar

    i work with it some days
    maybe someone find something wrong(i hope)

  3. #13

    Normilze a Vector

    thanks for helping

    some guys of www.indiegamer.com helped me also

    i think thats it

    alpha := ArcTan2(v1.y-v2.y , v1.x-v2.x);
    alpha := -(-90+(-1* alpha * 57.2957);

    this will work(i hope)

    to open my links please put it manually in the addressfield

    much thanks
    Daiki

Page 2 of 2 FirstFirst 12

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
  •