// Lower Left -- [d]
// Upper Left | |
// Lower Right | |
// Upper Right [a] -- [c]
quadrangle = new Quadrangle(
(a + d) * 0.5f, // Position
Vector3.Distance(b, d), // Width
Vector3.Distance(b, a), // Height
Vector3.Normalize(Vector3.Cross(b - a, c - a)), // Normal
64 // Texture Index
);
The constructor then rotates the quadrangle so that its normal faces in the direction specified:
private static Matrix RotationFrom(Vector3 normal)
{
normal.Normalize();
Matrix rotation = Matrix.Identity;
rotation.Backward = normal;
rotation.Up = Vector3.Cross(Vector3.UnitY, normal);
if (rotation.Up.LengthSquared() < MathTools.EPSILON)
{
rotation.Up = Vector3.Cross(-Vector3.UnitZ, normal);
}
rotation.Up.Normalize();
rotation.Right = Vector3.Cross(rotation.Up, normal);
rotation.Right.Normalize();
return rotation;
}
The problem is that this ruins the method for finding the width and height as they can be swapped around depending on quadrangle orientation. How can I make sure that the dimensions are set correctly so that when the quadrangle transform is scaled:
worldTransform.M11 *= scale.X;
worldTransform.M12 *= scale.X;
worldTransform.M13 *= scale.X;
worldTransform.M21 *= scale.Y;
worldTransform.M22 *= scale.Y;
worldTransform.M23 *= scale.Y;
It takes into account the current orientation?
E.g.
width ------>
-- [d] ^
| | |
| | |
[a] -- [c] height
ROTATED
height------>
[a] -- ^
| | |
| | |
[c] -- [d] width