Jump to content
  • Advertisement
Sign in to follow this  
dave

Vector Matrix Multiplication

This topic is 4883 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here i have a piece of code that is supposed to rotate the normal of the first vertex around the origin by 180 degrees. Since the input vector is (0,0,-1) then the output vector should be (0,0,1), but it isnt. It comes out as (junk, 0, 1 );
void a_renderer::MakeNormalisedBoxMesh()
{
    LPDIRECT3DVERTEXBUFFER9     vb = NULL;
    LPDIRECT3DINDEXBUFFER9      ib = NULL;

    // vertex struct
    struct vertex
    {
        D3DXVECTOR3 pos;
        D3DXVECTOR3 norm;
        D3DXVECTOR2 uv;
    };

    //flexible vertex format
    #define D3DFVF_3DNORM (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)

    //create the buffers
    renderDevice->CreateVertexBuffer( 24 * sizeof(vertex) , 0, D3DFVF_3DNORM, D3DPOOL_DEFAULT, &vb, NULL );

    // Create 4 vertices for  the front face
    vertex  frontFace[] = {
        { D3DXVECTOR3( -0.5f,   -0.5f,  -0.5f ), D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXVECTOR2( 0.0f, 1.0f) },
        { D3DXVECTOR3(  0.5f,   -0.5f,  -0.5f ), D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f) },
        { D3DXVECTOR3( -0.5f,    0.5f,  -0.5f ), D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f) },
        { D3DXVECTOR3(  0.5f,    0.5f,  -0.5f ), D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f) },
    };

    /* Transform all vertices about the y axis 180 degrees for the back fce */
    D3DXMATRIXA16 matRot;
    D3DXMatrixRotationY( &matRot, 3.14159f );

    /* make another matrix and put the vectors into it */
    D3DXMATRIXA16 vecMat;
    /* make it a no-effect matrix */
    D3DXMatrixIdentity( &vecMat );

    vecMat._41 = frontFace[0].norm.x;
    vecMat._42 = frontFace[0].norm.y;
    vecMat._43 = frontFace[0].norm.z;
    vecMat._44 = 1.0f;

    D3DXMatrixMultiply( &vecMat, &vecMat, &matRot );

    if ( vb ) vb->Release();
    if ( ib ) ib->Release();
}

Any ideas? ace

Share this post


Link to post
Share on other sites
Advertisement
Why not negate them.

A vector pointing into the Z will point out when negated. Same with all axis and with all arbitrary directions. A vector * -1 = a flipped vector with same magnitude.
Constant*vector (ie. 3*normal ) = Vector( normal.x*3, normal.y*3, normal.z*3 )

Share this post


Link to post
Share on other sites
What is the value of "junk"? Are you sure it is really "junk" and not an extremely small number very close to 0?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!