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

Thread: Normilze a Vector

  1. #1

    Normilze a Vector

    hi,

    how can i rotate a object with a normalized vector?
    have anyone a function?

    thanks

  2. #2

    Normilze a Vector

    You can?¢_~t describe a rotation with a vector. Normalized just means that it?¢_Ts length is equal to one. Could you explain in more detail what you want to accomplish and with what.

  3. #3

    Normilze a Vector

    Paulius, rotations can be stored in a vector. That's done when using euler angles which represent rotations in such a way that they can be stored in a vector data structure.

    See http://skal.planet-d.net/demo/matrixfaq.htm#Q36 to see how you get a rotation matrix out of such euler angles.

  4. #4

    Normilze a Vector

    From a data structure point of view you could also call a quaternion a vector, but not in a mathematical sense.

  5. #5

    Normilze a Vector

    thanks

    but it isnt what i mean ^^"

    i was thinking i can get the direction over a normalized vector

    i will rotate an object in the direction of an other object
    how to do?

  6. #6

    Normilze a Vector

    i mean the following:

    i have this situation:
    http://daikrys.funpic.de/01.JPG

    and i will have this situation:
    http://daikrys.funpic.de/02.JPG

    that means i must rotate the first object with the position of the other

    thanks
    daiki

  7. #7

    Normilze a Vector

    So what you want to do is transform an object so one of it?¢_Ts own axis is normalized(TargetPosition - ObjectPosition), we still need more information if you want to do it in 2D or 3D and using which API.

  8. #8

    Normilze a Vector

    Ahh, so you want an object to turn to be facing another object? Here is some C code I found for creating a look-at matrix. But better still, it actually has comments to say what it is doing!

    Code:
    //-----------------------------------------------------------------------------
    // Name: buildLookAtMatrix()
    // Desc: Creates a Left-Handed view matrix
    //
    // Building a View Matrix:
    //
    // 1. Subtract the camera's position from the position to look at, to 
    //    create a view vector called 'l'.
    // 2. Take the cross-product of the new view vector and the y axis of 
    //    world space to get a right vector called 'r'.
    // 3. The cross-product of vectors 'l' and 'r' will give you a up vector 
    //    called 'u'.
    // 4. Compute translation factors by taking the negative of the 
    //    dot-product between the camera's position, called 'c', and our new 
    //    orientation or basis vectors called u, r, and l.
    //
    // Here's what the final matrix should look like:
    //
    //  |   rx     ux     lx    0 |
    //  |   ry     uy     ly    0 |
    //  |   rz     uz     lz    0 |
    //  | -(r.c) -(u.c) -(l.c)  1 |
    //
    // Where r = Right vector
    //       u = Up vector
    //       l = Look vector
    //       c = Camera's world space position
    //       . = Dot-product operation
    //-----------------------------------------------------------------------------
    void buildLookAtMatrix( D3DXMATRIX        *pOut, 
    					    const D3DXVECTOR3 &pEye, 
    					    const D3DXVECTOR3 &pAt, 
    					    const D3DXVECTOR3 &pUp )
    {
        D3DXVECTOR3 vRight; // New x basis
    	D3DXVECTOR3 vUp;    // New y basis
    	D3DXVECTOR3 vView;  // New z basis
    
        // 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.0f;
        pOut->_24 = 0.0f;
        pOut->_34 = 0.0f;
        pOut->_44 = 1.0f;
    }

  9. #9

    Normilze a Vector

    hi and thanks

    sorry for waiting

    ok i dont understanding anything from the C source :toothy:

    i will create an Aim-Target like Sly said
    it can be used in strategie and rpg

    i use opengl and found this from delphigl.com:

    Code:
    //Cross-product 
    function VectorCross(v1, v2 : TVec): TVec; 
    
    var 
    Temp : TVec; 
    
    begin 
    Temp.x := V1.y*V2.z - V1.z*V2.y; 
    Temp.y := V1.z*V2.x - V1.x*V2.z; 
    Temp.z := V1.x*V2.y - V1.y*V2.x; 
    Result := Temp; 
    end; 
    
    
    //Angle in Float(Extended)
    function VectorAngle(v1, v2 : TVec) : float; 
    
    var 
    v, w : float; 
    
    begin 
    v := v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; 
    w := (sqr(v1.x)+sqr(v1.y)+sqr(v1.z)) * (sqr(v2.x)+sqr(v2.y)+sqr(v2.z)); 
    result := ArcCos(v / sqrt(w)); 
    end;
    or smaller:

    Code:
    ArcCos(v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
    this can be used by 2 normalized vectors

    ok now how to get an correct angle for glrotate?

    thanks
    Daiki

  10. #10

    Normilze a Vector

    Edit: sort of repost of the thread..
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

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
  •