Floating Actor Tips
by Joachim Lous
This tutorial explains the basics of adding floating pop-up labels in the hud that track objects in the game, much like the info frames in DeusEx (if you enhance the rendering quite a bit). I call them ActorTips.
First of all we need to create a new HUD-type that implements the ActorTip feature. Here we'll add it to the normal UT ChallengeHUD, but you could base it on any HUD-type available to you:
class TipHUD expands ChallengeHUD; |
simulated function Actor GetFocusedActor() { local vector Look, EyePos; local Actor Candidate, Winner; local float Score, HiScore; // Find out where the camera is, and where it's
looking: // Iterate through all actors closer than 200 UUs to
the player, // Ignore actors too far to the sides
(too low scores): return
Winner; |
simulated function vector MapToScreen(vector TargetPos,
Canvas Canvas) { local vector Result, EyePos; local rotator Look, Focus; local float TanFOV, dYaw, dPitch, scale; // Again, our current point of view is sort of
essential: // Find out where we're facing, but his time as a
'rotator' providing // Find the corresponding rotator angles of the
direction from // Now find out how much the target angles are offset
from the // The field of view obviously affects how things are
projected // Finally calculate actual screen
coordinates: return
Result; |
simulated function DrawActorTip(Canvas
Canvas) { local Actor FocusedActor; local vector ScreenPos; // Find Target // Label Target |
// Override the old HUD-redrawing function: simulated function PostRender(Canvas Canvas) { // -But make sure all the old drawing is still done first: // (If you want to, that is) super.PostRender(Canvas); // Then add our ActorTip on
top: |
The problem is to find out where the vector from the camera to the target will intersect the screen. We can solve this for X and Y separately. Considering X first, looking at the figure below, our problem is to figure out dx:
From the definition of the tangent we know that
dx tan(dYaw) = --- z |
ClipX/2 tan(FOV/2) = ---------- z |
ClipX/2 dx = tan(dYaw) ----------------- tan(FOV/2) |
We then do the same thing for Y versus Pitch. Note that we then use
same scaling fraction (with ClipX, not ClipY), since we don't have any
separate vertical FOV.