• 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.

[JASS] Loop Stopping Function? [+Math]

Status
Not open for further replies.
Level 13
Joined
Mar 16, 2008
Messages
941
Hi guys.
First of all, no I don't want to know how to stop a loop.
I have a small problem. I have a loop, thats creating four orbs.
I want those orbs to move from their position to a
location, but they had to fly in a curve. I had no idea
how to calculate a curve just with h as the maximum excursion
and the two points. While sitting in class today, it hit me.
My Problem is, that the functions I wrote seem to stop my loop...

the idea is this picture: (my programm had no brush for a curve xD)
ImageShack - Hosting :: blapm5.jpg
So the two points and h are given, I searched r.
So I calculated the distance and used the "highsentence" (in german: "Höhensatz", found no translation, sry^^).
It says: b² (half the distance) = h*rest, while the rest is 2*c+h, the point where r hits c is the middle of the line.

This is my loop:
JASS:
//x and y are set outside ...
    loop
        exitwhen i>=4
        set data2 = Orbs.create()
        set ox = x+350*Cos((i*90+angle)*bj_DEGTORAD)
        set oy = y+350*Sin((i*90+angle)*bj_DEGTORAD) 
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl", ox, oy))
        set data2.orb = CreateUnit(Player(1), 'h002', ox, oy, 0)
        set data2.tx = tx+i*40*Cos(i*70*bj_DEGTORAD)
        set data2.ty = ty+i*40*Sin(i*70*bj_DEGTORAD)
        set data2.lx = tx
        set data2.ly = ty
        if i <= 1 then
            set data2.dist = FlightRadius(ox, oy, data2.tx, data2.ty, i*200)
            set data2.angle = FlightAngle(ox, oy, data2.tx, data2.ty, i*200)
        else
            set data2.dist = FlightRadius(ox, oy, data2.tx, data2.ty, i*-200)
            set data2.angle = FlightAngle(ox, oy, data2.tx, data2.ty, i*-200)
        endif        
        set data2.height = 100*i+50
        set OrbData[i] = data2
        set i = i+1
    endloop

JASS:
    function FlightRadius takes real x, real y, real tx, real ty, real h returns real
        local real b = 0.5*SquareRoot((x-tx)*(x-tx)+(y-ty)*(y-ty))
        local real c = ((b*b)/h)+h
        return SquareRoot(b*b+c*c)
    endfunction
    
    function FlightAngle takes real x, real y, real tx, real ty, real h returns real
        local real b = 0.5*SquareRoot((x-tx)*(x-tx)+(y-ty)*(y-ty))
        local real c = ((b*b)/h)+h
        return Asin(SquareRoot(b*b+c*c)/(2*c+2*h))*bj_RADTODEG
    endfunction

Can anyone help me? I know that the loop "stops", because only one orb is created and the stuff after it isn't made, while it works without the if-condition. Btw, is the calculation for the angle right?
Sry for any mistakes in the text, I'm still learning English ;)

Greets, Justify
 
Last edited:
Level 15
Joined
Jan 16, 2008
Messages
1,244
I'm gonna give you a little math insight since i'm not a great jasser. The function you need is described with f(x)=ax2+b which you already seem to know, mostly. Here's the idea. Imagine the x axis of the coordinate system as the axis connecting source and destination point of the orb with the starting point (0,0) at it's middle. Here's a little explanation of function parameters:
 

Attachments

  • explanation.jpg
    explanation.jpg
    308.5 KB · Views: 110
Level 13
Joined
Mar 16, 2008
Messages
941
I tried it with this idea already, but my problem is:
how to "imagine" that the x axis is the axis, connecting both points? I mean, the axis are diagonal. Also I had another problem:
d as the distance between the points
a as the factor of x
c as the distance to the axis (old habit)

f(x) = a*(x-(d/2))²+c

but, how to set a? I mean, since the height and the distance is given, I need to set a in dependency of them. I tried this a year befor for a jump, and didn't got the solution :S

Btw my "crash" was division by zero, I'm dumb. If you find a way to do it with your formula I would be honored if you tell it to me, since it's a lot easier ^^ dunno if my formula even works, have to make one for the spinpoint and try it then...
 
Level 13
Joined
Mar 16, 2008
Messages
941
I thought I did, but I didn't. My problem is that I need the point where c hits r, and it seems that I'm to dumb for it, I just don't get it.
Btw, you don't need to do it in Jass, normal math is enough xD
Isn't there an easy way to create a curve between two points with a defined distance?
 
Status
Not open for further replies.
Top