# Vector Matrix Multiplication

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

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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634065
• Total Posts
3015313
×