I guess this is because you use animated 3ds meshes. So in fact you've got several meshes that are linked together (some are parented to others). In the targetbox function, only the root is taken into account, where you would need to also take into account all the children.
Here is a modifed version of targetbox, with a little test:
It's not very nice (I use a string to store the 4 corrdinates) but it works.
Just a note: this way of computing the box (iterate through each vertex) is far from being efficient. If you don't need the box being too accurate, you could precompute a 3d bounding box, and then at runtime deduce the 2d bounding box.
Here is a modifed version of targetbox, with a little test:
Function targetbox$(ent,cam%,rec%=True,parentBox$="") isRoot% = (parentBox="") If ent=0 Return "10000:10000,-10000:-10000" If Not EntityInView(ent,cam) Return "10000:10000,-10000:-10000" If (isRoot) Then leftmost#=10000 rightmost#=-10000 topmost#=10000 bottommost#=-10000 Else leftmost#=parentBox parentBox=Right(parentBox,Len(parentBox)-Instr(parentBox,":")) topmost#=parentBox parentBox=Right(parentBox,Len(parentBox)-Instr(parentBox,",")) rightmost#=parentBox parentBox=Right(parentBox,Len(parentBox)-Instr(parentBox,":")) bottommost#=parentBox EndIf For i=1 To CountSurfaces(ent) s=GetSurface(ent,1) For v=0 To CountVertices(s)-1 TFormPoint VertexX(s,v),VertexY(s,v),VertexZ(s,v),ent,0 CameraProject cam,TFormedX(),TFormedY(),TFormedZ() If ProjectedX()<leftmost leftmost=ProjectedX() If ProjectedX()>rightmost rightmost=ProjectedX() If ProjectedY()<topmost topmost=ProjectedY() If ProjectedY()>bottommost bottommost=ProjectedY() Next Next childcount%=CountChildren(ent) parentBox = leftmost+":"+topmost+","+rightmost+":"+bottommost For i = 1 To childcount childBox$=targetbox(GetChild(ent, i), cam, True, parentBox) leftmost_#=childBox childBox=Right(childBox,Len(childBox)-Instr(childBox,":")) topmost_#=childBox childBox=Right(childBox,Len(childBox)-Instr(childBox,",")) rightmost_#=childBox childBox=Right(childBox,Len(childBox)-Instr(childBox,":")) bottommost_#=childBox If leftmost_<leftmost leftmost=leftmost_ If rightmost_>rightmost rightmost=rightmost_ If topmost_<topmost topmost=topmost_ If bottommost_>bottommost bottommost=bottommost_ parentBox = leftmost+":"+topmost+","+rightmost+":"+bottommost Next If (isRoot) Then Rect leftmost,topmost,rightmost-leftmost,bottommost-topmost,0 EndIf Return parentBox End Function Graphics3D 640,480,32,2 cube% = CreateCube() sphere% = CreateSphere(8, cube) cone% = CreateCone(8,True,sphere) cyl% = CreateCylinder(8,True,sphere) PositionEntity(sphere, 4,1,-1) PositionEntity(cone, 2,0.5,1) PositionEntity(cone, -2,-1,0.5) cam% = CreateCamera() PositionEntity(cam, 0,0, -5) While Not KeyHit(1) TurnEntity(cube, 0.1,0.3,0.2) TurnEntity(sphere, 0.2,0.5,0.3) UpdateWorld RenderWorld Text(5,5,targetbox(cube, cam)) Flip() Wend End
It's not very nice (I use a string to store the 4 corrdinates) but it works.
Just a note: this way of computing the box (iterate through each vertex) is far from being efficient. If you don't need the box being too accurate, you could precompute a 3d bounding box, and then at runtime deduce the 2d bounding box.