• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[JASS] Getting Correct real Rotation

Status
Not open for further replies.
Level 4
Joined
Jun 22, 2016
Messages
71
I've decided to start making my own spells in JASS. So far I'm creating spawn target points with Polar Offset based from the cast click point. I've followed this guide but it's a little difficult since I'm not very knowledgeable with geometry Math. So I'm taking it one step at a time.

This is my based understanding with the circle example so far that works.

JASS:
// PolarProjectionBJ(<location> Target, <real> Offset, <real> Direction) returns <location> Polar Offset Location
// I2R(<integer> Number) returns <real> Integer to Real
// CreateNUnitsAtLocFacingLocBJ(<integer> Create Number, <integer> Unit Type ID, <player> Owner, <location> Target, <location> Facing Target) returns <nothing>
set illusionLoc = PolarProjectionBJ(targetLoc, distance, (I2R(i) * (360.00 / l)))
call CreateNUnitsAtLocFacingLocBJ(1, uType, owner, illusionLoc, targetLoc)

I know 0 starts at East and there are 360 degrees in a circle. I want to find the value if I rotate by half. Say if value starts at 190 and I rotate by 180. This will result 370 but it's an overflow of the maximum possible result and should result in 10. Maybe if I reverse the direction by 180 from 170, it could result in 350 instead. Is there a easy function of way to safely get the correct rotation even if an overflow?

Example

JASS:
function getRotation takes real rotation returns real
// return correct rotation
endfunction

JASS:
local real start = 100.00
local real modify = start + 300.00
local real result = getRotation(modify) returns 40.00
 
Level 4
Joined
Jun 22, 2016
Messages
71
The spell I'm doing will spawn illusion in 2 certain points were the caster is facing. So the if I go under or over the degrees it will auto correct the value?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,233
I know 0 starts at East and there are 360 degrees in a circle. I want to find the value if I rotate by half. Say if value starts at 190 and I rotate by 180. This will result 370 but it's an overflow of the maximum possible result and should result in 10. Maybe if I reverse the direction by 180 from 170, it could result in 350 instead. Is there a easy function of way to safely get the correct rotation even if an overflow?
The function is well defined for every angle. The cyclic nature of angles means that polar projection of 370 degrees produces approximately equal results to 10 degrees. Deviations in results would be due to rounding error, and should only really start being considerable if very large numbers are involved.
 
Status
Not open for further replies.
Top