Finding the local z angle from the camera to a target
Posted: Wed Aug 02, 2006 11:11 am
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](http://img221.imageshack.us/img221/2674/targethudmz1.th.png)
This is the result from my code for the offscreen target.
![Image](http://img146.imageshack.us/img146/5442/targethud2wa9.th.png)
The returned angle is wrong.
I create the arrow at a 2D position. My formulae is something like.
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.
This is when the target is onscreen.
![Image](http://img221.imageshack.us/img221/2674/targethudmz1.th.png)
This is the result from my code for the offscreen target.
![Image](http://img146.imageshack.us/img146/5442/targethud2wa9.th.png)
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)
BTW I am writing my game for another programming language using a wrapper.