Centering Meshes

Blitz3D Forums/Blitz3D Beginners Area/Centering Meshes

Swefx(Posted 2005) [#1]
How do I center a mesh?
So the Meshes x and y co-ordinates are in the very middle.


Andy(Posted 2005) [#2]
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


Matty(Posted 2005) [#3]
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 




Swefx(Posted 2005) [#4]
Thanks Matty


jfk EO-11110(Posted 2005) [#5]
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.


John Blackledge(Posted 2005) [#6]
Syncronicity!
jfk - I just built your method (from the code archives) into my code today. It's great.