Class: ProconBypassMan::Procon::AnalogStickCap

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/procon/analog_stick_cap.rb

Instance Method Summary collapse

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_xObject

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_yObject

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

#hypotenuseObject



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

#positionProconBypassMan::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

#radObject



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_xObject



30
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 30

def relative_x; @analog_stick.relative_x; end

#relative_yObject



31
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 31

def relative_y; @analog_stick.relative_y; end

#xObject

Deprecated.


34
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 34

def x; relative_x; end

#yObject



35
# File 'lib/procon_bypass_man/procon/analog_stick_cap.rb', line 35

def y; relative_y; end