• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • 💡 We're thrilled to announce that our upcoming texturing contest is in the works, and we're eager to hear your suggestions! Please take this opportunity to share your ideas in this theme discussion thread for the Texturing Contest #34!
  • 🏆 Hive's 7th HD Modeling Contest: Icecrown Creature is now open! The frozen wastes of Icecrown are home to some of Azeroth’s most terrifying and resilient creatures. For this contest, your challenge is to design and model a HD 3D monster that embodies the cold, undead, and sinister essence of Icecrown! 📅 Submissions close on April 13, 2025. Don't miss this opportunity to let your creativity shine! Enter now and show us your frozen masterpiece! 🔗 Click here to enter!

Lost in maths... again...

Status
Not open for further replies.
Level 24
Joined
Aug 1, 2013
Messages
4,658
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