Turning an object around it's centre?

Blitz3D Forums/Blitz3D Programming/Turning an object around it's centre?

Dicon(Posted 2011) [#1]
I need to "spin" some meshes around their centre point, but they swing around on a distant turning point. I know there is a simple way around this but can't seem to figure out how.
Thanks.
Dicon


GfK(Posted 2011) [#2]
Go back into your modelling program, and put the 'centre' of your mesh at global coordinates 0,0,0. Resave. Bish bash bosh. Job's a good 'un.


Warner(Posted 2011) [#3]
Alternatively, use a pivot, place it in the center of the object, set it as the parent of the object and rotate the pivot, or use:
FitMesh mesh, -1, -1, -1, 2, 2, 2, True


Dicon(Posted 2011) [#4]
Thanks all. Dicon


jfk EO-11110(Posted 2011) [#5]
A further method would be:

Determine the min and max xyz of the vertices, then use FitMesh with these values.

Getting vertex xyz is easy, use VertexX, then TFormPoint it with zero as the destination entity.

x#=vertexx(surf, index)
y#=vertexy(surf, index)
z#=vertexz(surf, index)

tformpoint x,y,z,mymesh,0
world_x#=tformedx()
world_y#=tformedy()
world_z#=tformedz()

determining min and max is easy, initially set min_x# to 1000000 and max_x# to -1000000. Then check every vertex: is vertex x smaller than min_x? if so then the new min_x is this vertex x. The same with y and z of course.

A simplified version may use Meshwidth this way :
Fitmesh mymesh, -(meshwidth(mymesh)/2.0),-(meshheight(mymesh)/2.0),-(meshdepth(mymesh)/2.0), meshwidth(mymesh), meshheight(mymesh),meshdepth(mymesh)

But this probably won't work if the base pivot is somewhere outside the mesh (which seems to be the problem with your mesh).