Finding the local z angle from the camera to a target

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Dirtbiker
Posts: 29
Joined: Wed Aug 31, 2005 7:02 am
Location: U.S.
Contact:

Finding the local z angle from the camera to a target

Post 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.
Post Reply