Sign in to follow this  
dave

Vector Matrix Multiplication

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this