Notifications
Clear all

[Closed] bbox calculations

hi people

    I'm trying to figure out a way to calculate an object's bounding box as if "watched" from 45  degree orthographic view
    
    [[img] http://img99.imageshack.us/img99/8756/bboxua0.jpg [/img]]( http://imageshack.us) 

like the red rectangle on the pic above ( the blue one is the bbox as returned from nodeLocalBoundingBox()). Is there some nice and easy way or I’ll have to cast rays =)

3 Replies

do you want to do it with math, or do you want to cheat?

if you want to cheat… apply a XForm modifier, rotate its gizmo 45 degrees, counter-rotate the node, grab the BBox, rotate back, remove the modifier.
( some of the rotations you can do with some transform math instead, of course )

This code creates a bounding box (in this case for Teapot01) using another node’s transform matrix (in this case Box01). Haven’t done any thorough testing but it should work.

(
      	local trgNode	= $Teapot01 -- The object to create a bounding box for
      	local refNode	= $Box01 -- The object to use as a reference
      
      	-- Get the reference node's transform matrix
      	local refTm = refNode.transform
      	
      	-- Move the matrix to the center of the target node
      	local refBb = nodeGetBoundingBox trgNode refTm
      	refTm.translation = (refBb[1] + ((refBb[2]-refBb[1]) / 2)) * refTm
      	
      	-- Get the target node's bounding box using this matrix
      	local bb = nodeGetBoundingBox trgNode refTm
      	local bbs = bb[2] - bb[1]
      	
      	-- Boxes are created with their pivots at the bottom,
      	-- so we need to compensate for that
      	preTranslate refTm [0, 0, bbs.z/-2]
      	
      	-- Create the bounding box!
      	box width:bbs[1] length:bbs[2] height:bbs[3] transform:refTm
      )
 Martijn

well I didn’t want to cheat, rather wanted to do it the clean, beautiful math way =)
magicm, your code works great!
thank you both =)