Results 1 to 4 of 4

Thread: Matrix*vector= how to?

  1. #1
    Guest

    Matrix*vector= how to?

    i'm trying to multiply a vector by a matrix the problem is that doesn't
    perform any rotation on the vector !

    argh... i'm blocked in the creation of my little 3d game ( Space invader 2003)



    i've this formula to multiply a vector by a matrix
    | A B C D | | x1 x2 x3 x4 x5 | | A.x1+B.y1+C.z1+D A.x2+B.y2+C.z2+D ... |
    | E F G H | . | y1 y2 y3 y4 y5 | = | E.x1+F.y1+G.z1+H E.x2+F.y2+G.z2+H ... |
    | I J K L | | z1 z2 y3 y4 z5 | | I.x1+J.y1+K.z1+L I.x2+J.y2+K.z2+L ... |
    | M N O P | | 1 1 1 1 1 | | M.x1+N.y1+O.z1+P M.x2+N.y2+O.z2+P ... |

    so i've created this func

    void M4x4multV3(Vector3f *result,Vector3f *in,float *m)
    {

    result->x=(m[0]*in->x)+(m[4]*in->y)+(m[8]*in->z)+m[12];
    result->y=(m[1]*in->x)+(m[5]*in->y)+(m[9]*in->z)+m[13];
    result->z=(m[2]*in->x)+(m[6]*in->y)+(m[10]*in->z)+m[14];
    }

    /*
    m is a 4x4 matrix OpenGL order
    Vector3f is define like this
    typedef struct
    {
    float x,y,z;
    }Vector3f;
    */

  2. #2
    Guest

    Re: Matrix*vector= how to?

    i'll reply to myself
    in fact that work the problem was not here

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Adelaide, South Australia, Australia
    Posts
    763

    Re: Matrix*vector= how to?

    hello

    be aware of a potential snafu: you're not computing the w component of your vector. This may not be a problem for your work, but just keep it in mind if you start using funky psycho matricies!

    cheers
    John

  4. #4
    Guest

    Re: Matrix*vector= how to?

    okay!

Similar Threads

  1. 2d vector and matrix operation
    By giugio in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-27-2011, 10:08 AM
  2. Efficiency: vector*matrix or matrix*vector
    By Alfonse Reinheart in forum OpenGL: Windows
    Replies: 1
    Last Post: 07-02-2010, 05:27 AM
  3. eye and up vector from view matrix
    By Vexator in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-16-2008, 12:41 AM
  4. matrix * vector or vector * matrix
    By V-man in forum OpenGL: GLSL
    Replies: 12
    Last Post: 08-24-2004, 03:20 PM
  5. Replies: 2
    Last Post: 01-07-2004, 11:48 PM

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