Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

Deciding which is dimension is which for rotated quadrangles.

This topic is 2890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm creating a quadrangle using the following method:



// 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

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!