• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Lost in maths... again...

Status
Not open for further replies.
Level 24
Joined
Aug 1, 2013
Messages
4,657
Hi all.

Once again, I find myself lost in maths...
This time it is about finding the location on the field when having a specific location on the screen.
(Imagine I want to show floating texts as HUD.)

So I started out drawing the concept:
11cgHGf.png

I'll explain what happens in there:
Point C is the source of the camera.
Point B is the target of the camera.
This means that line BC is the distance to the target.
The line AG is the game field in the Y axis. (from A (bottom) to G (top) of the map.)

If I want to place something on the screen, it is definately gonna be that way that it is in a right corner of the target location.
That is point E.
The length of BE is equal to the length between the center of the screen and the location of my floating text on the Y axis.
If I want to see something on that location, I want to place it on point G because that is on the surface of it placed on the exact location of that point on the screen.

So I have to place my texttag on the target + BD+DG.
(Also there is a factor between BC and CG to make the location on the X axis right.

So I created this script (it is pretty messy and can be better definately but that will come as soon as it works).
JASS:
function GetNewYOffset takes real offset returns real
    //Corners
    local real BAC
    local real ABC
    local real ACB
    local real BCE
    local real BEC
    local real CEF
    local real ECF
    local real DGE
    
    //Lines
    local real AB
    local real AC
    local real BC
    local real BE
    local real BD
    local real DE
    local real CF
    local real DF
    local real EF
    local real DG
    local real CG
    local real CE
    local real EG
    
    set BC = GetCameraField(CAMERA_FIELD_TARGET_DISTANCE)
    set ABC = 2.*bj_PI - GetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK)
    set ACB = 0.5*bj_PI - ABC
    set AB = BC*Cos(ABC)
    set AC = BC*Cos(ACB)
    
    set BE = -offset
    call BJDebugMsg("offset = " + R2S(BE))
    set BD = BE*Cos(ACB)
    set DE = BE*Cos(ABC)
    
    set CE = SquareRoot(Pow(BE, 2) + Pow(BC, 2))
    set BEC = Atan(BC/BE)
    set BCE = 0.5*bj_PI - BEC
    
    set CF = AC - DE
    set EF = AB + BD
    set CEF = Atan(CF/EF)
    set ECF = ACB + BCE
    
    set DGE = CEF
    set DG = DE/Tan(DGE)
    set EG = DE/Sin(DGE)
    
    set udg_Factor = (CE+EG) / BC
    return -1* (BD + DG)
endfunction

Now the thing is that my texttag shows up at a location and if I zoom in (basically change angle of attack) and out, then my texttag does not change in X axis which is perfect but does change in the Y axis a little.

Because everything works (except that little change) I actually doubt that the problem is in the calculations.

Can someone tell me where the problem is and if I can do anything to solve it?

Here is the map in which you can see what happens:
 

Attachments

  • HUD Test.w3x
    18 KB · Views: 38
Status
Not open for further replies.
Top