How would I find the which side of a Box entity is facing up

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
ThyChief
Posts: 2
Joined: Sat Dec 06, 2014 5:48 am

How would I find the which side of a Box entity is facing up

Post by ThyChief »

How would I calculate which side of a Box entity is predominantly facing up?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: How would I find the which side of a Box entity is facin

Post by Norbo »

Assuming +Y is up, check the Y component of the OrientationMatrix's axes. Whichever one has the largest value is associated with the one facing up. Similarly, to check which side points towards an arbitrary direction, take the dot product of that direction and the axes.

For example, if box.OrientationMatrix.Right is associated with the highest value, then the right side of the box is pointing up.

(Conceptually, the dot products are equivalent to moving the 'up' direction into the box's local space by transforming by the transposed box.OrientationMatrix. In local space, the 'right' side of the box is always along +UnitX, Up is along +UnitY, and Forward is along -UnitZ, so it's easy to analyze the transformed result.)
ThyChief
Posts: 2
Joined: Sat Dec 06, 2014 5:48 am

Re: How would I find the which side of a Box entity is facin

Post by ThyChief »

Thanks! That worked great, thanks for your time.
Post Reply