Okay I made this program that takes a single triangle and spins it about the x axis using the fixed function pipeline. All fine and dandy. Then I converted it to a vertex shader and now its not so fine. It does the color part of the VS properly but the matrices it uses gets a little screwed up. Instead of rotating the triangle about its y axis (so you see a spinning triangle) it looks as though the triangle is spinning around the camera with a radius about as big as big as how far back my eye is. wierd. anyway here is the code that sets up my matrices and VS constant:
HRESULT SetupMatrices(const DWORD δ)
{
//world matrix
D3DXMATRIX matWorld;
UINT iTime = timeGetTime() % 4000;
FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 4000.0f;
D3DXMatrixRotationY( &matWorld, fAngle );
//view matrix
D3DXMATRIX matView;
D3DXMatrixLookAtLH( &matView
, &D3DXVECTOR3( 0.0f, 0.0f,-5.0f ) //eye
, &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ) //at
, &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) ); //up
//projection matrix
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj
, D3DXToRadian( 45 )
, 4/3
, 1.0f
, 100.0f);
//setup vertexshader clipping matrix
D3DXMATRIX matClip;
D3DXMatrixTranspose( &matClip, &(matWorld * matView * matProj) );
g_pD3DDevice->SetVertexShaderConstantF(0, (FLOAT*)matClip, 4);
return S_OK;
}
Here is my VertexShader:
//----------------------------------------------------------------------------
// reg c0-3 = WorldViewProj matrix
// reg v0 = position register
// reg v1 = color register
//----------------------------------------------------------------------------
vs_1_1 //Shader version 1.1
dcl_position v0 //declare position
dcl_color v1 //declare color
m4x4 oPos, v0, c0 //position the vertex
mov oD0, v1 //output vertex color from input (untouched)