Positioning problems

BlitzMax Forums/MiniB3D Module/Positioning problems

MrTAToad(Posted 2008) [#1]
I'm having real trouble positioning my objects consistantly.

I'm creating a pivot and positioning the mesh so that the pivot is in the centre of the mesh, and then positioning the object at 0,0,0

This works for one mesh, but another one is way out for some reason.

playArea[index].pivot=CreatePivot()
playArea[index].mesh=CopyMesh(loadData[6].mesh,playArea[index].pivot)
PositionEntity playArea[index].mesh,0.0-(MeshWidth(playArea[index].mesh)/2.0),0.0-(MeshHeight(playArea[index].mesh)/2.0),0.0-(MeshDepth(playArea[index].mesh)/2.0)


and this for creating the initial positions

s.pivot=CreatePivot()
s.mesh=CopyMesh(loadData[7].mesh,s.pivot)
PositionEntity s.mesh,0.0-(MeshWidth(s.mesh)/2.0),0.0-(MeshHeight(s.mesh)/2.0),0.0-(MeshDepth(s.mesh)/2.0)


and this for displaying them :

PositionEntity playArea[index].pivot,0.0,0.0,0.0 
PositionEntity s.pivot,0.0,0.0,0.0



simonh(Posted 2008) [#2]
The problem may be that you're not taking into account the mesh's minimum x/y/z.

Try doing:

s.mesh.min_x+(s.mesh.MeshWidth()/2.0)

...and similar for all the lines above. min_x/min_y/min_z store the position of the left-most, bottom-most, near-most vertex.

Generally though, I'd advise against using MeshWidth/Height etc. I'm sure there is probably an easier way to do what you're doing just using the standard Entity commands.


MrTAToad(Posted 2008) [#3]
Would be nice if there was a command to auto-centre an object - I'm just so used to it being done automatically (ala DBPro), and its very handy.

I'm trying various permutations, but so far its got somewhat close, but not exactly how it should be - for some reason it seems to be a few units out in all directions.


simonh(Posted 2008) [#4]
FitMesh will centre a mesh - for example do:

FitMesh mesh,-10,-10,-10,20,20,20,True


MrTAToad(Posted 2008) [#5]
I presume that will work for loaded objects too, as well?


MrTAToad(Posted 2008) [#6]
Looks like its sorted now.