Centre point of mesh

Blitz3D Forums/Blitz3D Programming/Centre point of mesh

If you want to change the center of a mesh you need to first choose the point which you want to be the center relative to the current center of the mesh, and then move all the vertcies in the mesh.

this is hard to explain though.

Okay...

Inside your mesh it has it's own "space". Each vertex is at a position in mesh space. These positions are the same no matter how you orient the mesh in the world.

So, you need to define the center point in this mesh space. Once you have done that you can figure out how much to offset all the vertices.

But finding this point in mesh space can be hard for you.

Here's an easy way to do it.

Leave your mesh at 0,0,0 in the world, with no rotation when you load it.

FInd the point in world cooridnates where you want the center point to be in the mesh.

This point will be Px# Py# Pz#.

Then do this, where Mesh is the pointer to your mesh.

TFormPoint Px#, Py#, Pz#, 0, Mesh
Px# = TFormedX()
Py# = TFormedY()
Pz# = TFormedZ()

You now have transformed the point from world space to mesh space.

Now the center of your mesh is always at 0,0,0 in mesh space. So, Pxyz is going to be a point around this somewhere.

Let's pretend Px=1, and Py and Pz = 0.

That means that the new center point you want is one unit (in mesh space) to the right of the current center location.

So what you need to do is move all the vertices one unit to the LEFT to move 0,0,0 over to 1,0,0.

So all you do now is loop through every vertex in the mesh, and move it from it's current position, to it's current position MINUS Pxyz.

In other words:

Loop through each vertex
For this vertex
Set it's position to VertexX#()-Px#, VertexY#()-Py#, VertexZ#()-Pz#

And voila, you now have a new mesh center.