float4x4 CreateWorldMatrix( float3 pos, float3 rot, float2 scl )
{
float4x4 rotate;
float4x4 translate = { 1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
pos.x, pos.y, pos.z, 1.0 };
float4x4 rotateX = { 1.0, 0.0, 0.0, 0.0,
0.0, cos(rot.x), -sin(rot.x), 0.0,
0.0, sin(rot.x), cos(rot.x), 0.0,
0.0, 0.0, 0.0, 1.0 };
float4x4 rotateY = { cos(rot.y), 0.0, sin(rot.y), 0.0,
0.0, 1.0, 0.0, 0.0,
-sin(rot.y), 0.0, cos(rot.y), 0.0,
0.0, 0.0, 0.0, 1.0 };
float4x4 rotateZ = { cos(rot.z), -sin(rot.z), 0.0, 0.0,
sin(rot.z), cos(rot.z), 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 };
float4x4 scale = { scl.x, 0.0, 0.0, 0.0,
0.0, scl.y, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 };
rotate = mul( rotateY, mul( rotateX, rotateZ ));
return mul( scale, mul( rotate, mul( gCamera, translate ) ) );
}
OutputVS TransformVS( InputVS input )
{
// output structure
OutputVS outVS = (OutputVS)0;
//Creates the world matrix and applies the camera's view for billboarding
float4x4 world = CreateWorldMatrix( input.transPos, input.rot, input.scale );
float4 worldPos = mul( float4(input.vertPos, 1.0f), world );
outVS.worldPos = mul( worldPos, gVP );
outVS.color = input.color;
outVS.texCoord = input.texCoord;
return outVS;
}
The gCamera is a float4x4 that orients the quads to the inverse facing of the camera (hence facing the camera) calculated here:
D3DXMATRIX vp = CCamera::GetInstance()->GetViewMatrix() * CCamera::GetInstance()->GetProjectionMatrix();
D3DXMATRIX camMat = CCamera::GetInstance()->GetViewMatrix();
D3DXMATRIX identity;
D3DXMatrixIdentity(&identity);
camMat._41 = camMat._42 = camMat._43 = 0.0f; camMat._44 = 1.0f;
camMat._13 *= -1.0f; camMat._23 *= -1.0f; camMat._33 *= -1.0f;
The problem I'm having is that the quads are billboarding in every direction as they should except in the local X. As the camera goes down the quad rotates up. I have changed around the order of rotation to every possible order I can think of to no avail. If more information is need just ask. Thanks.