Snippet 3D Functions

Reaction score
86
3D Functions

Well, after doing a bit of research I was able to learn more about this 3D environment. So, I decided to post a few functions that pertain to this subject.

Functions:
  • SphereProjLoc takes location source, real Radius, real Degrees, real ZDegrees returns location
  • SphereProjZ takes real Zsource, real Radius, real ZDegrees returns real
  • SetUnitZ takes unit u, real Z returns nothing
Uses:
- Yay! Sphere Projections! Basically, similar to Polar Projection except with a Z factor.
-You can set a unit's Z *almost* instantly. (This is pretty simple but I added it for the heck of it :D)

How to Implement:
Jass:
-Just click on the map icon in Trigger Editor, and post the scripts in there. Call them when needed through out your map :D

GUI:
-Just click on the map icon in Trigger Editor, and post the scripts in there.
-You must create a global variable that receives the function I.E. Point for location, Real for real.
- Create a custom script, Example, "call SetUnitZ(100,GetTriggerUnit(),false)"
or "set udg_Point = SphereProjLoc(Parameters)"

Explanation:
SphereProjLoc and SphereProjZ:
Because a location's Z value is hard to change, these function comes in a package. MAKE SURE the parameters you send to each of these functions are the equal to the parameters you enter in the other. One returns a Location(X,Y) of the Spherical Point and the other returns the Z of the location. Now, some people are confused by ZDegrees, right? Well, its simple really. If ZDegrees equals 0 then the point will be directly above the source. If ZDegrees equal pi/2 or 90 the point will be on the plane of the X and Y axis. if ZDegrees equal 180, then the point will be directly below the source. Zsource is there so you can get the Z in terms of the source. It doesn't matter if you set it to 0 then add it the Z later.

Code:
JASS:
function SphereProjLoc takes location source, real Radius, real Degrees, real ZDegrees  returns location
    local real x = GetLocationX(source)+Radius*Sin(ZDegrees*bj_DEGTORAD) * Cos(Degrees*bj_DEGTORAD)
    local real y = GetLocationY(source)+Radius*Sin(ZDegrees*bj_DEGTORAD) * Sin(Degrees*bj_DEGTORAD)
    return Location(x,y)
endfunction

function SphereProjZ takes real Zsource, real Radius, real ZDegrees  returns real
    return Zsource + Radius * Cos(ZDegrees*bj_DEGTORAD)
endfunction

function SetUnitZ takes unit u, real Z returns nothing //Created by Flare
   call UnitAddAbility (u, 'Amrf')
  call SetUnitFlyHeight (u, Z, 0)
  call UnitRemoveAbility (u, 'Amrf')
endfunction


If anyone finds any errors in this, please let me know!

Spherical Coordinates in Action!

Take a look at this spell, it shows how ingenious effects can be created from this simple formula.
 

trb92

Throwing science at the wall to see what sticks
Reaction score
142
JASS:
function SetUnitZ takes unit u, real Z, boolean canFly returns nothing
    if canFly == false then
        call UnitAddAbility(u,'Amrf')
    endif
    call SetUnitFlyHeight(u,Z,Z*1000)
    set u = null
endfunction

In that function, you should also remove Crow Form or it will remain for the unit to cast.
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
That is also not a true setunitz because it doesn't take into account the terrain height beneath the unit.
 
Reaction score
86
:( Yep, but these are simple 3D functions, the SetUnitZ was only there for people who don't know how to do that... Even though it's pretty simple...
 

Flare

Stops copies me!
Reaction score
662
The rest just set's the unit's Z. IMPORTANT, THIS IS NOT INSTANT!

Set rate to 0.

And you should probably change the function name for SetUnitZ (and remove that useless boolean argument, adding the ability to a flying unit won't break the game -.-')

JASS:
function SetUnitFlyHeight2 takes unit u, real h returns nothing //Since we want it done quick, we won't bother with a rate argument
//If you want, make a secondary function that allows for rate
  call UnitAddAbility (u, 'Amrf')
  call SetUnitFlyHeight (u, h, 0)
  call UnitRemoveAbility (u, 'Amrf')
endfunction
 
Reaction score
86
Lol, see :( I'm a noob at this stuff :*( All I can do is do math, XD

I also like how everyones criticizing the SetUnitZ but no ones saying anything about the other functions, which, actually, where the main focus of this snippet... :(
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
Reaction score
86
XD, I am making a spell that deals with these spherical coordinates. I'll post the map with this when its done. Take a look, it might get you interest :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top