- 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):
this is the function used by sphere creation function (probably not necessary):
Now here's the sphere function, nice and clean:
I understand projections more or less:
But what is this radoff? What is this:
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
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