• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Math problem with modulo

Status
Not open for further replies.
Level 5
Joined
Jul 10, 2010
Messages
124
So I remember this problem from WCIII where a function that returned angles would sometimes return a range of 0,360 and other times would return -180,180.

I solved it in WCIII using mod360, but I can't figure it out here.

So I have 2 tanks facing each other. They are placed on the map facing east and west. The action definition sets up the range of the turrets to be from their initial facing +/- 30 degrees, so the tank facing east will rotate from 270, thru 0, to 30. The tank facing west will rotate from 150 to 210.

Problem is the tank facing west, upon hitting 180, will think it is LESS THAN 150:

note: camera yaw controls the tank facing

attachment.php
 

Attachments

  • tanks.jpg
    tanks.jpg
    149.4 KB · Views: 1,228
Level 9
Joined
Nov 4, 2007
Messages
931
The problem is that past 180 degrees the trigger for some reason starts to return the value into negatives. For example, it ends up going 150, 160, 170, 180, -170, -160, -150. If you want to fix this then I would recommend that after 180 degrees when it starts going into negatives is to use 360 + Degrees to return the true facing angle.
Heres a quick little map I threw together to show what it would look like.
http://www.mediafire.com/?6sk03celqamcr80
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,232
Modding by 360 the current camera yaw of the player is a stupid exercise cause it will only ever return something that is not divisible by 360.

To avoid problems you will have to convert everything to angle with respect to the units facing. This means that a miximum and minimum yaw is usless and can be deleted cause they are constants of 30 and -30 respectivly.

Converting current yaw to relative yaw is the problem. I assume it returns a value in the range of 180 (inclusive) to -180 (excluded). First and formost you get the rough realitive angle as (yaw-facing) which returns an angular correct representation of its respective facing but in an unsuitable domain for our use. As the domain is -360 to +360 (both excluded) and we want the domain to be +180 (inclusive) to -180 (excluded) a simple conditional opperation can perform the conversion. If the angle is greater than 180 subtract 360 and if it is less than or equal to -180 you add 360 to it.

You should now know what angle the camera is facing, and if it exceedes the 30 to -30 range you will have to nudge it into that range using a method of your own choice. Converting back to actual angle for setting the yaw is a simple addition of your desired camera yaw with respects to the units facing plus the units facing. Further more the range of angle provided to the yaw function should not mater as usually such functions ignore multiples of 360. If you apply come custom buffer smooth it is important to do so using the yaw angle with respect to unit facing and not the true yaw as you may end up with clipping problems if doing so.
 
Status
Not open for further replies.
Top