find center point

Blitz3D Forums/Blitz3D Programming/find center point

type point
   field x#,y#,z# 
   field lx#,ly#,lz#
   field rx#,ry#,rz#
end type

function centrePoint.vector(mesh)
local lx#,ly#,lz#
local rx#,ry#,rz#
    for j=1 to countSurfaces(mesh)
       srf=getSurface(mesh,j)
       for k=1 to countVertices(srf)-1
           vX# =vertexX(srf,k)
           vY# =vertexY(srf,k)
           vZ# =vertexZ(srf,k)
           if vX<lx lx=vx 
           if vX>rx rx=vx
           if vY<ly ly=vy
           if vy>ry ry=vy
           if vz<lz lz=vz
           if vz>rz rz=vz
       next
   next
   out.point =new point
   out\x =lx+(rx-lx)/2.
   out\y =ly+(ry-ly)/2.
   out\z =lz+(rz-lz)/2.
   out\lx=lx:out\ly=ly:out\lz=lz
   out\rx=rx:out\ry=ry:out\rz=rz
end function


Should return the true centre of a mesh, in the form of a type.(Point\x,point\y,point\z)=actual 3d position of centre.
and lx,ly,lz = Left, bottom,in bounds, rx,ry,rz=right, top out bounds. (Err..a box..in other words ;) )