Help writing targeting algorithm

Hello,

Does anyone have any targeting demos. By that I mean an algorithm used to rotate an object so it is always facing another object that moves around. I have written one using calculations based on the angular difference of the objects on the 2d planes xz and xy. I use the angular differnce on the xz plane to rotate around the y axis and I use the angular differnce on the xy plane to rotate around the z axis. (I consider the x axis to be looking straight forward).

However it is a bit jerky and a more elegant implementation would be nice.

[567 byte] By [CrazzyBa] at [2007-9-21]
# 1

Easy stuff there bud ^_^

Anyways lemmie explain how to implement such algorithm.

Create a transform3D t3d and have it use the function lookAt(new Point3d(your hunter location), new Point3d(the target location), new Vector3d(up direction));

t3d.invert();

Now create a Matrix3f matrix, have t3d copy the rotation info into it by doing t3f.get(matrix);

Now you want your target to always face the hunter correct?

Well let's create a Matrix4f matrix_target, matrix_target.set(matrix,target location,targetscale);

T3D_target.set(matrix_target);

TG_target.setTransform(T3D_target);

Voila the target will always face the hunter, or you can exchange the names and have the hunter facing the target :P

javaCoolDudea at 2007-7-14 > top of java,Security,Cryptography...
# 2
Looks pretty good.1) If I wanted my hunter to face my object then I wouldnt need to call t3d.invert(), correct? If not then why did you call the invert function?2) This seems to give an unlimited turning radius, what about resrticting this.
CrazzyBa at 2007-7-14 > top of java,Security,Cryptography...
# 3

In my experience, and i have to confess to only having used this with a viewplatform if I told an object to lookat the viewplatform that would point it towards the view. If I told the viewplatform to lookat the object it would point it exactly the wrong direction and need to be inverted. I can't quite explain why, although I do sort of know.

_Breakfast_a at 2007-7-14 > top of java,Security,Cryptography...