For example, if you had a rectangle with 10 width, and 20 height standing tall, when the object rotates 90 degrees (e.g. as its being tossed around and lands at arbitrary location), the width then becomes 20 and height becomes 10, etc. It could be any angle really. (see attached)
Here's a sample of the code I'm using to clamp a rectangular image to the left and right sides of an 800x600 window -
Code: Select all
-- sample code run in love.update(dt)
local p = objects.player.body
X1, Y1, X2, Y2, X3, Y3, X4, Y4 = objects.player.shape:getBoundingBox()
-- calculate distance between top left and top right points in bounding box
dxW = X3 - X2
dyW = Y3 - Y2
-- find the distance between the two points
heroWidth = math.sqrt(math.pow(dxW,2) + math.pow(dyW,2))
-- clamp object
p:setX( math.min( math.max( p:getX(), heroWidth/2 ), 800 - heroWidth/2 ) )