how to draw a bounding box throug a hierachy

Blitz3D Forums/Blitz3D Programming/how to draw a bounding box throug a hierachy

Charrua(Posted 2010) [#1]
hi

i'm working with a world editor and when an object is selected i draw a box surrounding it.

basically i calculate 8 points in 3d space, then project them in 2d space and use 2d commands to draw lines after RenderWorld over the 3d renered scene.

  w# = MeshWidth (Temp) / 2
  h# = MeshHeight(Temp) / 2
  d# = MeshDepth (Temp) / 2
		
  TFormPoint  w, h, d,Temp,0
  CameraProject cam, TFormedX(), TFormedY(), TFormedZ()
  p1x=ProjectedX()
  p1y=ProjectedY()


this shows what i do basically for each point, changing w,h,d by its +/- combinations ( +, +, +, then +, +, - etc)

the question is:
what about if i have a hierarchy of objects: a father and some descendence , many levels down.

how should be the best way of doing it?
precalculate max, min in each axis and mantain updated this info every time a new member is added? or there are an easy way for doing this..

thank's

Juan


Matty(Posted 2010) [#2]
Do you want to see 1 bounding box that covers all the objects (parents and children)?

OR

Do you want to see individual bounding boxes for all objects (parents and children)?


Charrua(Posted 2010) [#3]
first one, 1 bounding box
that's what i think should be better

i try to recursively draw individual boxes for each but the visualization isn't much comfortably, and tform coordinates from child to parent and so on until reach the 3d world isn't much efficient, isn't it?

thanks

Juan


_PJ_(Posted 2010) [#4]
One bounding box would have dimensions equalling the largest separation of child entities from the centre of the source parent, right?

So I presume iterating through the children and checking their LOCAL relative positions is the only way (that I know of) to be sure.

i.e.:

; First, Get the largest dimension of the parent Mesh
Local GreatestDistanceX#=MeshWidth(Parent) * 0.5
Local GreatestDistanceY#=MeshHeight(Parent) *0.5
local GreatestDistanceZ#=MeshDepth(Parent) *0.5

; Now Iterate through the children

Local Child
For Child =1 To CountChildren(Parent)
 If (Child)
   If (abs(EntityX(Child))nGreatestDistanceX) Then nGreatestDistance=EntityX(Child)
   If (abs(EntityY(Child))>GreatestDistanceY) Then nGreatestDistance=EntityY(Child)
   If (abs(EntityZ(Child))>GreatestDistanceZ) Then nGreatestDistanceZ=EntityZ(Child)
Next

; The Dimensions for the box, then, should be:

;X  = (GreatestDistanceX * 2.0)  ,Y = (GreatestDistanceY * 2.0)  , Z = (GreatestDistanceZ * 2.0)



Charrua(Posted 2010) [#5]

how should be the best way of doing it?
precalculate max, min in each axis and mantain updated this info every time a new member is added?



so, it semms that i can't evade iteration!

thank's

Juan


_PJ_(Posted 2010) [#6]
Unless you already know the limits of how far the child entities may be from the parent, (in which case, you have your bounding box size already :) ) but otherwise, I think iteration is all you can do to find the info for each particular child.
If you can maybe do this just once on loading or something, provided animations may only extend a bounding box by a oproportion and yoyu're not scaling the children etc. halfway through, then rpesumably you would only need to do this once for each hierarchy. In theory at least :D