Skip to main content
GameDev.net gamedev.net
🔒 Locked

bounding box

Started by giugio Sep 15, 2010 at 9:43 AM 0 replies 500+ views
Original Post
giugio
giugio
Hello.
I have a node object that have a rectangular bounding box, I would like to add a decorator(the pattern) with the pattern edge, ie view the outline of the bounding box.
I wanted to ask what is the difference between a oriented BoundingBox and and a generic bounding box ?
In the computation of the contour, what are the differences between the two?
Thank you.
Spa8nky
Spa8nky
To draw the outline of a 2D rectangle you can extract the corners using the minimum point and the maximum point on the AABB where:

MinPoint = Centre - Extents
MaxPoint = Centre + Extents

            corners[0].X = min.X;            corners[0].Y = max.Y;            corners[1].X = max.X;            corners[1].Y = max.Y;            corners[2].X = max.X;            corners[2].Y = min.Y;            corners[3].X = min.X;            corners[3].Y = min.Y;


A 3D AABB box would be:

            corners[0].X = min.X;            corners[0].Y = max.Y;            corners[0].Z = max.Z;            corners[1].X = max.X;            corners[1].Y = max.Y;            corners[1].Z = max.Z;            corners[2].X = max.X;            corners[2].Y = min.Y;            corners[2].Z = max.Z;            corners[3].X = min.X;            corners[3].Y = min.Y;            corners[3].Z = max.Z;            corners[4].X = min.X;            corners[4].Y = max.Y;            corners[4].Z = min.Z;            corners[5].X = max.X;            corners[5].Y = max.Y;            corners[5].Z = min.Z;            corners[6].X = max.X;            corners[6].Y = min.Y;            corners[6].Z = min.Z;            corners[7].X = min.X;            corners[7].Y = min.Y;            corners[7].Z = min.Z;


As for an orientated rectangle you will need to take into account the orientation of the shape:

            // [Rotation]            Matrix m = Matrix.Identity;            float a = (float)Math.Cos(rotation);            float b = (float)Math.Sin(rotation);            m.M11 = a;            m.M12 = b;            m.M21 = -b;            m.M22 = a;            Vector3 extents = rect.Extents;            Vector3 hX = new Vector3();            hX.X = -m.M11 * extents.X;            hX.Y = -m.M12 * extents.X;            Vector3 hY = new Vector3();            hY.X = m.M21 * extents.Y;            hY.Y = m.M22 * extents.Y;            Vector3 p = new Vector3();            p.X = rect.Position.X;            p.Y = rect.Position.Y;            Vector3[] corners = new Vector3[4];            //   [0] -- [1]            //    |      |            //    |      |            //   [3] -- [2]            corners[0] = p - hX + hY;            corners[1] = p + hX + hY;            corners[2] = p + hX - hY;            corners[3] = p - hX - hY;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.