Page 1 of 1

Finding the local z angle from the camera to a target

Posted: Wed Aug 02, 2006 11:11 am
by Dirtbiker
I am working on a Target HUD. When the Target is offscreen, I need to find the local z angle from the Camera to a Target, to point an arrow towards the target in the HUD.

This is when the target is onscreen.
Image

This is the result from my code for the offscreen target.
Image
The returned angle is wrong.

I create the arrow at a 2D position. My formulae is something like.

Code: Select all

TargetXY = Collide.getScreenCoordinatesFrom3DPosition(Target.getPosition())

TargetAngle = Vector2df.createFromVals(TargetXY.getX(), TargetXY.getY()).getAngle()

ArrowX = (Cos(TargetAngle)*(128-16))+(ScreenW/2)
ArrowY = (Sin(TargetAngle)*(128-16))+(ScreenH/2)
What would I need to correct to make this formulae return the proper angle? Thank you.
BTW I am writing my game for another programming language using a wrapper.