- hinge.png (6.09 KiB) Viewed 7907 times
SBlade wrote:And this was exactly what confuses me, if there is parent / child relation then what is pivot point for?
The pivot is the point where the joint connects the two bodies.
The image shows two bodies (Parent and Child) and the pivot with positions (plus 1 to indicate a point as 4th. number).
Also there you see the Pin direction (plus 0 to indicate a vector).
Hope this eliminates confusion about terminology.
Note that all bodies must have been created already at their initial position when you create the joint.
I see your wrapper takes pivot and direction, which differs from matrices which i'm used to from C++,
but this does not matter.
It may matter that you have the 4th number right, similar to the 4th column for matrices.
The gifs you show look like it is an issue about that, but i can't be sure.
Your AsVector() may be the root of all evil, e.g. if it returns a pointer but only 3 numbers make sense and the 4th is random memory.
One more thing: If you want to render the pivot correctly for moving bodies, you have to store the local offset for both or at least one bodies.
Or, if you have access to the joint member variables, the local matrices are axactly that.
Local offsets would be (3,0,0) for Parent, and (-3,0,0) for Child.
So to render the pivot you would need to transform this vector by the body matrix to get it's actual world space position.
Making this work should show what really happens here.
Also note, if you have two bodies like in my example it does not matter which one is parent or child.
This only matters if you want a joint between only one body and the static world (only parent can be zero).