Centering Meshes

Blitz3D Forums/Blitz3D Beginners Area/Centering Meshes

How do I center a mesh?
So the Meshes x and y co-ordinates are in the very middle.

I havent tested the code, but something like this might work...

PositionMesh mesh,meshwidth(mesh)/2.0,meshheight(mesh)/2.0,meshdepth(mesh)/2.0



Andy

sumx#=0
sumz#=0
sumy#=0
vcount=0
for s=1 to countsurfaces(mesh)
surf=getsurface(mesh,s)
for v=0 to countvertices(surf)-1
sumx#=sumx#+vertexx(surf,v)
sumy#=sumy#+vertexy(surf,v)
sumz#=sumz#+vertexz(surf,v)
vcount=vcount+1
next

next
if vcount>0 then 
avgx#=sumx/vcount
avgy#=sumy/vcount
avgz#=sumz/vcount
positionmesh mesh,-avgx,-avgy,-avgz
endif 



Thanks Matty

most times it works with:
fitmesh mesh, -meshwidth(mesh)/2,-meshheight(mesh)/2,-meshdepth(mesh)/2,meshwidth(mesh),meshheight(mesh),meshdepth(mesh)

tho mattys code may be more bullet proof.

Syncronicity!
jfk - I just built your method (from the code archives) into my code today. It's great.