Class: ProconBypassMan::Procon::AnalogStickCap
- Inherits:
-
Object
- Object
- ProconBypassMan::Procon::AnalogStickCap
- Defined in:
- lib/procon_bypass_man/procon/analog_stick_cap.rb
Instance Method Summary collapse
-
#abs_x ⇒ Object
0, 0からのx.
-
#abs_y ⇒ Object
0, 0からのy.
- #capped_position(cap_hypotenuse:) ⇒ ProconBypassMan::AnalogStickPosition
- #hypotenuse ⇒ Object
-
#initialize(binary) ⇒ AnalogStickCap
constructor
A new instance of AnalogStickCap.
- #position ⇒ ProconBypassMan::AnalogStickPosition
- #rad ⇒ Object
- #relative_x ⇒ Object
- #relative_y ⇒ Object
- #x ⇒ Object deprecated Deprecated.
- #y ⇒ Object
Constructor Details
#initialize(binary) ⇒ AnalogStickCap
Returns a new instance of AnalogStickCap.
2 3 4 5 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 2 def initialize(binary) @binary = binary @analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary) end |
Instance Method Details
#abs_x ⇒ Object
0, 0からのx
28 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 28 def abs_x; @analog_stick.abs_x; end |
#abs_y ⇒ Object
0, 0からのy
29 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 29 def abs_y; @analog_stick.abs_y; end |
#capped_position(cap_hypotenuse:) ⇒ ProconBypassMan::AnalogStickPosition
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 8 def capped_position(cap_hypotenuse: ) if hypotenuse > cap_hypotenuse relative_capped_x = cap_hypotenuse * Math.cos(rad * Math::PI / 180).abs relative_capped_y = cap_hypotenuse * Math.sin(rad * Math::PI / 180).abs relative_capped_x = -(relative_capped_x.abs) if relative_x.negative? relative_capped_y = -(relative_capped_y.abs) if relative_y.negative? return ProconBypassMan::AnalogStickPosition.new( x: relative_capped_x + @analog_stick.neutral_position.x, y: relative_capped_y + @analog_stick.neutral_position.y, ) else return position end end |
#hypotenuse ⇒ Object
43 44 45 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 43 def hypotenuse Math.sqrt((relative_x**2) + (relative_y**2)).floor(6) end |
#position ⇒ ProconBypassMan::AnalogStickPosition
24 25 26 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 24 def position ProconBypassMan::AnalogStickPosition.new(x: abs_x, y: abs_y) end |
#rad ⇒ Object
37 38 39 40 41 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 37 def rad ( Math.atan(relative_y / relative_x.to_f) * 180 / Math::PI ).floor(6) end |
#relative_x ⇒ Object
30 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 30 def relative_x; @analog_stick.relative_x; end |
#relative_y ⇒ Object
31 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 31 def relative_y; @analog_stick.relative_y; end |
#x ⇒ Object
Deprecated.
34 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 34 def x; relative_x; end |
#y ⇒ Object
35 |
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 35 def y; relative_y; end |