I am rotating a plane composite of these vertices,
Vector3[] VertexPositionData = new Vector3[]{
new Vector3( 0f, 0f, 1f),
new Vector3( 1f, 0f, 1f),
new Vector3( 1f, 1f, 1f),
new Vector3( 0f, 1f, 1f)
};
on it's y-axis with:
Rotation.Y += (float)Math.PI / 4;
The effect is shown above. But I'd rather the plane rotated around it's left edge, so that the yellow remains fixed to the red.
The model matrix is calculated as per usual with,
public Matrix4 GetModelMatrix()
{
return Matrix4.Scale(Scale) * Matrix4.CreateRotationX(Rotation.X) * Matrix4.CreateRotationY(Rotation.Y) * Matrix4.CreateRotationZ(Rotation.Z) * Matrix4.CreateTranslation(Position);
}
Besides modifying the X and Z positions, how can I achieve this?
The plane is rotating around it's local Y axis, if you want the plane to rotate around it's left edge, you need to align it with the Y axis. In your case, the plane is 1 unit far from the origin on the Z axis.
You can either modify it's vertices like so:
Vector3[] VertexPositionData = new Vector3[]{
new Vector3( 0f, 0f, 0f),
new Vector3( 1f, 0f, 0f),
new Vector3( 1f, 1f, 0f),
new Vector3( 0f, 1f, 0f)
};
Or, you can translate it 1 unit on the Z axis so it would be aligned on the origin (0, 0, 0) like so:
Matrix4 result = Matrix4.Scale(Scale) * Matrix4.CreateTranslation(new Vector3(0, 0, -1)) * Matrix4.CreateRotationX(Rotation.X) * Matrix4.CreateRotationY(Rotation.Y) * Matrix4.CreateRotationZ(Rotation.Z) * Matrix4.CreateTranslation(Position);