Middle between 2 positions + orientation.. quick & easy question ?! [solved]

Hey guys…

I feel kind of mad today…

I dont get it exactly what you are trying to do…  :expressionless:

hmm… ok :wink:

I’ve bought a Gametrak-Controller. It enables me to track my hand-positions.

For the visualisation i use 2 boxes (left hand / right hand).

So i see my boxes moving exactly as my hands do in reality.

My thougt was to implement a staff-fight.

So i added a cylider as the staff.

Now my first thought was, to keep the center of the staff always in the middle between the hands. (in all axis).

(simple positions -> e.g.: leftHand(-3,0,0) / rightHand(3,3,0) --> staffMiddle(0,1.5,0))

And this works fine!

BUT there is no rotation. The staff is always paralell to the x axis, for example.

So there must be a way to calculate the rotation of the staff, so its orientation leeds through both hands.

But i haven’t found a way, to get the rotations (in all axis) from the avaliable positions (leftHand, rightHand, StaffCenter).

I hope it’s clearer now…

Have you looked at the lookAt() function? (just be careful to avoid recursion when you look into looking at the lookAt() :D)

I haven't tried it but perhaps something like staff.lookAt(leftHand.getLocalTranslation(), Vector3f.UNIT_Z.clone()); could help you. :slight_smile:

You can also do rotation with quaternions.

ok, i'll give the lookAt() method a try… thanks, haven't recognized it yet.


…i know that i could use quaternions for rotation… and use them for it.

But, before i have to know the angles to rotate the staff.




the lookAt() only enables me to look at a single position… that's not what i need to do.

I have to force the staff to be "hold" in both hands.

And i have only the 2 HandPositions as information.

How about using a vector from the midpoint (staff location) to one of the hands as the direction to look at. Provided the staff is built along the correct axis it should point to that hand. And because the location of the staff is the midpoint between the hands, the other end of the staff just so happens to be at the other hand as well. No?

ok… solved

The solution is that easy… tztz!

The lookAt() method works well.

I just had to insert an extra Node for the staff.

This node has the position of the  left Hand, and lookAt(rightHand)

The staff itself, gets a simple rotation and translation initially, so it leeds throughboth hands.

By adding the staff to the staffNode, everything is done automatically!

Thanks Guys, jMonkey is great! 

U just need to know how to use it… :wink: