#### Sgqvur

##### FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi

- Reaction score
- 62

An orbiteffect is basically an eyecandy effect that happens to rotate in an circular type of movement (on a sphere's surface).

uses/requires: xefx

The api is really simple:

Create:

[ljass]orbiteffect orbiteffect.add_to_unit(unit u, real radius, integer axis_of_rotation, real angle_in_degrees, real orbits_per_second, string path_to_effect)[/ljass]

Where the orbiteffect will orbit the unit "u" from a distance of "radius", in a path determent by the "axis_of_rotation" and the "angle_in_degrees", with a speed of "orbits_per_second", using the model of "path_to_effect".

Destroy:

[ljass]nothing <orbiteffect_instance>.destroy()[/ljass]

The most important and tricky arguments in the add_to_unit method are the axis_of_rotation which can take only the following values (ORBIT_X_AXIS, ORBIT_Y_AXIS and ORBIT_Z_AXIS).

I am finding it difficult for explaining them so I tried to make a "silly" pic that only describes the ORBIT_Z_AXIS (see the attachments section).

Yeah... not much of explanation but... there's always the demo map in which there are examples which hopefully would make sense.

uses/requires: xefx

The api is really simple:

Create:

[ljass]orbiteffect orbiteffect.add_to_unit(unit u, real radius, integer axis_of_rotation, real angle_in_degrees, real orbits_per_second, string path_to_effect)[/ljass]

Where the orbiteffect will orbit the unit "u" from a distance of "radius", in a path determent by the "axis_of_rotation" and the "angle_in_degrees", with a speed of "orbits_per_second", using the model of "path_to_effect".

Destroy:

[ljass]nothing <orbiteffect_instance>.destroy()[/ljass]

The most important and tricky arguments in the add_to_unit method are the axis_of_rotation which can take only the following values (ORBIT_X_AXIS, ORBIT_Y_AXIS and ORBIT_Z_AXIS).

I am finding it difficult for explaining them so I tried to make a "silly" pic that only describes the ORBIT_Z_AXIS (see the attachments section).

Yeah... not much of explanation but... there's always the demo map in which there are examples which hopefully would make sense.

JASS:

```
library orbiteffect uses xefx
globals
private real PERIOD = 0.03125
endglobals
globals
// exported globals used for the axis_of_rotation argument in the add_to_unit method
integer ORBIT_X_AXIS = 0
integer ORBIT_Y_AXIS = 1
integer ORBIT_Z_AXIS = 2
// private global(s)
private location g_loc = Location(0, 0)
endglobals
struct orbiteffect
private static timer graviton = CreateTimer()
private static orbiteffect array instances
private static integer instance_count = 0
private unit center_unit
public real radius
private integer rotation_axis
private real rotation_angle
public xefx xefx
private real az = 0
private real az_inc
public real x_offset
public real y_offset
public real z_offset
static method looop takes nothing returns nothing
local orbiteffect this
local integer i
local real ox
local real oy
local real oz
local real cux
local real cuy
local real cuz
// local real cuf
if instance_count == 0 then // the destroy method was called on all orbiteffect instances
call PauseTimer(graviton)
return
endif
set i = 0
loop
exitwhen i >= instance_count
set this = instances<i>
set i = i + 1
set cux = GetUnitX(center_unit)
set cuy = GetUnitY(center_unit)
call MoveLocation(g_loc, cux, cuy)
set cuz = GetUnitFlyHeight(center_unit) + GetLocationZ(g_loc)
// set cuf = GetUnitFacing(center_unit) * bj_DEGTORAD
if ORBIT_X_AXIS == rotation_axis then
set ox = cuz + radius * Sin(az) * Cos(rotation_angle) + z_offset
set oy = cuy + radius * Sin(az) * Sin(rotation_angle) + y_offset //* Sin(cuf)
set oz = cux + radius * Cos(az) + x_offset //* Cos(cuf)
set xefx.x = oz
set xefx.y = oy
call MoveLocation(g_loc, oz, oy)
set xefx.z = ox - GetLocationZ(g_loc)
elseif ORBIT_Y_AXIS == rotation_axis then
set ox = cux + radius * Sin(az) * Cos(rotation_angle) + x_offset //* Cos(cuf)
set oy = cuz + radius * Sin(az) * Sin(rotation_angle) + z_offset
set oz = cuy + radius * Cos(az) + y_offset //* Sin(cuf)
set xefx.x = ox
set xefx.y = oz
call MoveLocation(g_loc, ox, oz)
set xefx.z = oy - GetLocationZ(g_loc)
elseif ORBIT_Z_AXIS == rotation_axis then
set ox = cux + radius * Sin(az) * Cos(rotation_angle) + x_offset //* Cos(cuf)
set oy = cuy + radius * Sin(az) * Sin(rotation_angle) + y_offset //* Sin(cuf)
set oz = cuz + radius * Cos(az) + z_offset
set xefx.x = ox
set xefx.y = oy
call MoveLocation(g_loc, ox, oy)
set xefx.z = oz - GetLocationZ(g_loc)
endif
set az = az + az_inc
endloop
endmethod
static method add_to_unit takes unit u, real radius, integer axis_of_rotation, real angle_in_degrees, real orbits_per_second, string path_to_effect returns orbiteffect
local orbiteffect this = orbiteffect.allocate()
set center_unit = u
set this.radius = radius
set rotation_axis = axis_of_rotation
set rotation_angle = angle_in_degrees * bj_DEGTORAD
// get a dummy
// and attach the effect to it
set xefx = xefx.create(0, 0, 0)
set xefx.fxpath = path_to_effect
set x_offset = 0
set y_offset = 0
set z_offset = 0
set az_inc = ((360.0 / (1 / PERIOD)) * orbits_per_second) * bj_DEGTORAD
set instances[instance_count] = this
set instance_count = instance_count + 1
if instance_count == 1 then
call TimerStart(graviton, PERIOD, true, function orbiteffect.looop)
endif
return this
endmethod
method destroy takes nothing returns nothing
set instance_count = instance_count - 1
set instances[this - 1] = instances[instance_count]
call this.xefx.destroy()
call deallocate()
endmethod
endstruct
endlibrary
</i>
```