set_polar() Method 1

Made by: DontAtMe Usage: f_set_polar(STICK, ANGLE, RADIUS);
Version1.00
AuthorDontAtMe
Publish DateThu, 11 Jun 2020 - 07:18
Last UpdateThu, 11 Jun 2020 - 07:18
Downloads17
RATE


0

0

Release Notes: Release
Code: Select all
/*
    set_polar() Method 1
    Made by: DontAtMe
 
    Usage:
    f_set_polar(STICK, ANGLE, RADIUS);
 
    STICK:
    2 = Right Stick
    4 = Left Stick
 
    ANGLE:
    A value 0 to 359.
          0 = (right)
         45 = (down-right)
         90 = (down)
        135 = (down-left)
        180 = (left)
        225 = (up-left)
        270 = (up)
        315 = (up-right)
 
*/

define RIGHT_STICK  = 2;
define LEFT_STICK   = 4;
data(-100,-100,-100,-100,-100,-100,-100,-100,-100,-99,-99,-99,-98,-98,-98,-97,-97,-96,-96,-95,-94,-94,-93,-93,-92,-91,-90,-90,-89,-88,-87,-86,-85,-84,-83,-82,-81,-80,-79,-78,-77,-76,-75,-74,-72,-71,-70,-69,-67,-66,-65,-63,-62,-61,-59,-58,-56,-55,-53,-52,-50,-49,-47,-46,-44,-43,-41,-40,-38,-36,-35,-33,-31,-30,-28,-26,-25,-23,-21,-20,-18,-16,-14,-13,-11,-9,-7,-6,-4,-2,0,2,4,6,7,9,11,13,14,16,18,20,21,23,25,26,28,30,31,33,35,36,38,40,41,43,44,46,47,49,51,52,54,55,56,58,59,61,62,63,65,66,67,69,70,70,72,73,74,75,77,78,79,80,81,82,83,84,85,86,87,88,89,89,90,91,92,92,93,94,94,95,95,96,97,97,97,98,98,99,99,99,99,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,99,99,99,99,98,98,97,97,97,96,95,95,94,94,93,92,92,91,90,89,89,88,87,86,85,84,83,82,81,80,79,78,77,75,74,73,72,71,70,69,67,66,65,63,62,61,59,58,56,55,53,52,50,49,47,46,44,43,41,40,38,36,35,33,31,30,28,26,25,23,21,20,18,16,14,13,11,9,7,6,4,2,0,-1,-3,-5,-7,-8,-10,-12,-13,-15,-17,-19,-20,-22,-24,-25,-27,-29,-30,-32,-34,-35,-37,-39,-40,-42,-43,-45,-46,-48,-50,-51,-53,-54,-55,-57,-58,-60,-61,-62,-64,-65,-66,-68,-69,-70,-71,-73,-74,-75,-76,-77,-78,-79,-80,-81,-82,-83,-84,-85,-86,-87,-88,-89,-89,-90,-91,-92,-92,-93,-93,-94,-95,-95,-96,-96,-97,-97,-97,-98,-98,-99,-99,-99,-99,-100,-100,-100,-100,-100);
int ang_velocity, cos_angle, sin_angle;
//------------------------------------------------------------------------------
 
// Adjust variables
define speed = 1;
define radius = 100;
 
main {
  ang_velocity = (ang_velocity + speed) % 360;
 
  // right stick rotating anti-clockwise.
  f_set_polar(RIGHT_STICK, ang_velocity * -1, radius);
 
  // left stick rotating clockwise.
  f_set_polar(LEFT_STICK, ang_velocity, radius);
}
 
function f_set_polar(stick, angle, radius) {
  if(angle < 0) angle = 360 + (angle % 360);
  angle = (angle + 90) % 360;
 
  sin_angle = dchar(angle);
  cos_angle = dchar((angle + 90) % 360);
 
  set_val(7 + stick, f_clamp(((cos_angle * radius) / 100), -100, 100));
  set_val(8 + stick, f_clamp(((sin_angle * radius) / 100), -100, 100));
 
  return;
}
 
function f_clamp(v, lo, hi) { if(v < lo) return lo; if(v > hi) return hi; return v; }