PDA

View Full Version : 2DBounds in Float Function


thatoneguy
04-23-2008, 10:50 PM
Little function to return a bounding box for an object relative to a plane.

So if you have a plane rotated arbitrarily in the middle of nowhere and you want a Bounding box of an object relative to the plane... this'll return the position and dimensions (in float relative of the reference plane)



fn get2DRelativeBounds obj refObj =
(
objpos = nodegetboundingbox obj refObj.transform
objmin = [objpos[1].x,objpos[2].y]
objmax = [objpos[2].x,objpos[1].y]
objbounds = nodegetboundingbox refobj refobj.transform
minposx = ((objmin.x-objbounds[1].x)/(abs(objbounds[1].x)+abs(objbounds[2].x)))
minposy = ((objmin.y-objbounds[1].y)/(abs(objbounds[1].y)+abs(objbounds[2].y)))
minposy = (minposy - 1)*(-1)
maxposx = ((objmax.x-objbounds[1].x)/(abs(objbounds[1].x)+abs(objbounds[2].x)))
maxposy = ((objmax.y-objbounds[1].y)/(abs(objbounds[1].y)+abs(objbounds[2].y)))
maxposy = (maxposy - 1)*(-1)

objwidth = maxposx-minposx
objheight = maxposy-minposy

struct Bounds2D (pos, width, height)

return Bounds2D [minposx,minposy] objwidth objheight
)

CGTalk Moderation
04-23-2008, 10:50 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.