PositionEntity verticeX/Y/Z

Blitz3D Forums/Blitz3D Programming/PositionEntity verticeX/Y/Z

Banshee(Posted 2005) [#1]
Hello

I'm very stuck on what I thought would be a simple mathematical problem. I'm trying to bind a gun to a players hand by reading in the vertice information.

I'm using my own code driven mesh deformation for the animation so there is no other way to read off the position of the characters hand.

Getting the vertice positions is easy enough, after figuring out the surface/vertex identity
x#=VertexX(surface,vertex)
y#=VertexY(surface,vertex)
z#=VertexZ(surface,vertex)

I then need to rescale the vertex information because my model is rescaled, so I multiply it by *.01 which should give me the x/y/z of the vertex relative to the objects pivot position.

The above all works, but now I need it to rotate depending upon the rotateEntity command. I thought in order to perform the rotation I would simply need to orbit the X/Z around the pivot based on it's distance from the epicentre - like a planet orbits the sun.

p\facing = the rotation of the character entity:

r#=Sqr((x*x)+(z*z))
x=x+(Cos(p\facing)*r)
z=z+(Sin(p\facing)*r)

If I now add the entities world position with the rescaling for the entityscale command and rotate the gun to the angle of the entity (i'll figure out how to rotate the gun in line with the vertex once this works, probably using normals).

PositionEntity p\gunObj,p\x+(x*.01),p\y+(y*.01),p\z+(z*.01)
RotateEntity p\gunObj,0,p\facing,0

Now the only problem is, this completely doesn't work :(

Have I done something wrong ?


Beaker(Posted 2005) [#2]
Its a lot simpler than you imagine. Once you have the local Vertex position you need to translate it into the parent or world space using TFormPoint.

You can scale and rotate it by parenting it to the character.

Although, thinking about it, you are using your own animation, so it might be an idea to create two vertices, one at the position of the hand/gun and the other at a distance of 1.0 away from the first. Then use TFormVector to adjust your gun scale and rotation.

Hope this helps.


Banshee(Posted 2005) [#3]
Thank you very much Beaker, it works a treat :) ! I feel all enlightened now...