• 🏆 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!

[JASS] Lightning System function

Status
Not open for further replies.
Level 13
Joined
Nov 22, 2006
Messages
1,260
Hello everybody, I downloaded a Lightning System from wc3c, the system is ok, but there's something I don't understand. When I was trying to make a sphere, it looked bad and wrong, but the author of that system did something so his looked perfect. Well I want to know exactly what he did, I hope someone here understands spherical coordinates and that stuff.

this is the function that initializes the whole thing, I don't know if it's necessary for this (but maybe for udg_start variable):

JASS:
function lgl_InitGL takes nothing returns nothing
 local integer i = 0
    loop
        exitwhen i == 8192
        set udg_start[i] = -1
        set i = i + 1
    endloop
endfunction

this is the function used by sphere creation function (probably not necessary):

JASS:
function GetAnIndex takes nothing returns integer
 local integer i = 0
 local integer pbv
    loop
        exitwhen i == 8192
        if udg_start[i] == -1 then


            set pbv = udg_indexes[0] + 1
            set udg_indexes[0] = pbv
            set udg_start[i] = pbv
            set udg_end[i] = pbv

            return i
        endif
        set i = i + 1
    endloop
    return -1
endfunction

Now here's the sphere function, nice and clean:

JASS:
function lgl_Sphere takes real MidX, real MidY, real MidZ, real radius, real RadianOffset, real RadianOffset2, real rotation, string lightning_effect returns integer
 local real array Angle
 local real radoff = 1.570796 / RadianOffset2
 local real array x
 local real array y
 local real array z
 local integer lightning_data = GetAnIndex()
 local real count

    set Angle[0] = rotation
    set Angle[4] = rotation
    
    loop
        exitwhen Angle[4] >= 6.2831853 + rotation

        set count = 1

        set x[0] = MidX + radius * Cos(Angle[0])
        set y[0] = MidY + radius * Sin(Angle[0])
        set z[0] = MidZ

        set x[2] = x[0]
        set y[2] = y[0]
        set z[2] = z[0]

        loop
            exitwhen count > radoff

            set Angle[1] = count * RadianOffset2
            set Angle[2] = -Angle[1]

            set x[1] = MidX + radius * Cos(Angle[0]) * Cos(Angle[1])
            set y[1] = MidY + radius * Sin(Angle[0]) * Cos(Angle[1])
            set z[1] = MidZ + radius * Sin(Angle[1])

            call lgl_CreateLightning(lightning_effect, x[0], y[0], z[0], x[1], y[1], z[1], lightning_data)

            set x[3] = MidX + radius * Cos(Angle[0]) * Cos(Angle[2])
            set y[3] = MidY + radius * Sin(Angle[0]) * Cos(Angle[2])
            set z[3] = MidZ + radius * Sin(Angle[2])

            call lgl_CreateLightning(lightning_effect, x[2], y[2], z[2], x[3], y[3], z[3], lightning_data)

            set x[0] = x[1]
            set y[0] = y[1]
            set z[0] = z[1]
            set x[2] = x[3]
            set y[2] = y[3]
            set z[2] = z[3]

            set count = count + 1
        endloop


        set Angle[4] = Angle[4] + RadianOffset
        set Angle[0] = Angle[4]

    endloop

    return lightning_data
endfunction

I understand projections more or less:

JASS:
set x[1] = MidX + radius * Cos(Angle[0]) * Cos(Angle[1])
set y[1] = MidY + radius * Sin(Angle[0]) * Cos(Angle[1])
set z[1] = MidZ + radius * Sin(Angle[1])

But what is this radoff? What is this:

JASS:
set x[0] = MidX + radius * Cos(Angle[0])
set y[0] = MidY + radius * Sin(Angle[0])
set z[0] = MidZ

Here's the description of the function:

Creates a sphere, MidX/Y/Z is the center, radius is the radius. Degree offset would be the arc measure
between each lightning horizontally (on the plane that would be perpendicular the Z axis).
DegreeOffset2 is the same, except it's for the vertical circles created (the ones that are parallel
to the Z axis). Rotation is how much the object is rotated on the Y axis. If this still confuses you,
take a look at the example. Also, one thing to be careful of is to make sure that the degree offsets
aren't too small, otherwise the loops inside the function would become too long and the sphere
wouldn't be fully created.

Please explain, thanks in advance
 
Level 11
Joined
Oct 13, 2005
Messages
233
Well, since I made the system I should be able to answer your question better than anyone. The lightning system uses radians instead of degrees because it's just plain faster to not have to multiply the degrees by bj_DEGTORAD every timer. It looks like I might still have used the word degree in the explanation even though I should have used radians. To convert degrees into radians, you simply multiply your number of degrees by bj_DEGTORAD. I'm assuming this is the cause of your problem, the other problem would not be having a full sphere which means the angle measures were too small causing too many loops. Too many loops in one function would cause it to end prematurely.

I wish I would have been able to help you before, but I didn't see this post.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
With this system I got a perfect sphere, but when I was trying to make a sphere without that system, but with 3D projections, I didn't quite succeed, though it was a sphere, but not a nice one......

I know what are radians and how to convert them, thank you. What I don't know is what's this radoff = 1.570796 / RadianOffset2, what is this 1.570796? Is it a constant or something? I wanted to analyze this function so I can understand it and make a sphere of something else than lightning

I'm sorry I forgot it's your system :), I like it very much, nice work
 
Status
Not open for further replies.
Top