I have written a simple method which just draws lines between the bounding boxes coordinates to display the bounding box which is how I know that the bounding box isn't being rotated correctly. Interestingly enough, the bounding box is always drawn with vertical and horizontal lines, never diagonal lines. So it could be my drawing method which is incorrect but I can't see what I'm doing wrong.
This is the code for calculating the position and rotation of the bounding box:
Matrix rotMatrix = Matrix.CreateRotationZ(rotation.Z);
boundingBox.Min.X = position.X - 40;
boundingBox.Min.Y = position.Y - 70;
boundingBox.Max.X = position.X + 40;
boundingBox.Max.Y = position.Y + 70;
boundingBox.Min = Vector3.Transform(boundingBox.Min, rotMatrix);
boundingBox.Max = Vector3.Transform(boundingBox.Max, rotMatrix);
Matrix tempMatrix = worldMatrix * rotMatrix * Matrix.CreateTranslation(position);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = tempMatrix;
}
}
This is the method I am using to draw the bounding box:
public void DrawBoundingBox(BoundingBox boundingBox)
{
BasicEffect basicEffect = new BasicEffect(graphics.GraphicsDevice, null);
basicEffect.EnableDefaultLighting();
basicEffect.DiffuseColor = new Vector3(1.0f, 0.0f, 0.0f);
Matrix viewMatrix = camera.View;
Matrix projectionMatrix = camera.Projection;
Matrix worldMatrix = Matrix.CreateRotationX(0);
basicEffect.World = worldMatrix;
basicEffect.View = viewMatrix;
basicEffect.Projection = projectionMatrix;
VertexPositionColor[] vertices = new VertexPositionColor

Vector3 topLeft = new Vector3(boundingBox.Min.X, boundingBox.Max.Y, 0.0f);
Vector3 topRight = new Vector3(boundingBox.Max.X, boundingBox.Max.Y, 0.0f);
Vector3 bottomLeft = new Vector3(boundingBox.Min.X, boundingBox.Min.Y, 0.0f);
Vector3 bottomRight = new Vector3(boundingBox.Max.X, boundingBox.Min.Y, 0.0f);
vertices[0] = new VertexPositionColor(bottomLeft, Color.White);
vertices[1] = new VertexPositionColor(topLeft, Color.White);
vertices[2] = new VertexPositionColor(topLeft, Color.White);
vertices[3] = new VertexPositionColor(topRight, Color.White);
vertices[4] = new VertexPositionColor(topRight, Color.White);
vertices[5] = new VertexPositionColor(bottomRight, Color.White);
vertices

vertices[7] = new VertexPositionColor(bottomLeft, Color.White);
VertexBuffer vertexBuffer = new VertexBuffer(
graphics.GraphicsDevice,
VertexPositionColor.SizeInBytes * vertices.Length,
ResourceUsage.None,
ResourceManagementMode.Automatic
);
vertexBuffer.SetData<VertexPositionColor>(vertices);
VertexDeclaration basicEffectVertexDeclaration = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionColor.VertexElements);
graphics.GraphicsDevice.VertexDeclaration = basicEffectVertexDeclaration;
graphics.GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionColor.SizeInBytes);
basicEffect.Begin();
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.GraphicsDevice.DrawPrimitives(
PrimitiveType.LineList,
0,
4
);
pass.End();
}
basicEffect.End();
}
Can anyone spot what I'm doing wrong