Class: Jolt::Constraint
- Inherits:
-
Object
- Object
- Jolt::Constraint
- Defined in:
- lib/jolt/constraint.rb
Instance Attribute Summary collapse
-
#body_a ⇒ Object
readonly
Returns the value of attribute body_a.
-
#body_b ⇒ Object
readonly
Returns the value of attribute body_b.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#system ⇒ Object
readonly
Returns the value of attribute system.
Instance Method Summary collapse
- #__involves?(body) ⇒ Boolean
- #__mark_destroyed ⇒ Object
- #__native_pointer ⇒ Object
- #current_position ⇒ Object
- #destroy ⇒ Object
- #destroyed? ⇒ Boolean
- #disable_motor ⇒ Object
- #enabled=(value) ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(system, pointer, kind, body_a, body_b) ⇒ Constraint
constructor
A new instance of Constraint.
- #limits ⇒ Object
- #limits=(value) ⇒ Object
- #motor_speed ⇒ Object
- #motor_speed=(value) ⇒ Object
Constructor Details
#initialize(system, pointer, kind, body_a, body_b) ⇒ Constraint
Returns a new instance of Constraint.
7 8 9 10 11 12 13 14 |
# File 'lib/jolt/constraint.rb', line 7 def initialize(system, pointer, kind, body_a, body_b) @system = system @pointer = pointer @kind = kind @body_a = body_a @body_b = body_b @destroyed = false end |
Instance Attribute Details
#body_a ⇒ Object (readonly)
Returns the value of attribute body_a.
5 6 7 |
# File 'lib/jolt/constraint.rb', line 5 def body_a @body_a end |
#body_b ⇒ Object (readonly)
Returns the value of attribute body_b.
5 6 7 |
# File 'lib/jolt/constraint.rb', line 5 def body_b @body_b end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
5 6 7 |
# File 'lib/jolt/constraint.rb', line 5 def kind @kind end |
#system ⇒ Object (readonly)
Returns the value of attribute system.
5 6 7 |
# File 'lib/jolt/constraint.rb', line 5 def system @system end |
Instance Method Details
#__involves?(body) ⇒ Boolean
86 87 88 |
# File 'lib/jolt/constraint.rb', line 86 def __involves?(body) @body_a.equal?(body) || @body_b.equal?(body) end |
#__mark_destroyed ⇒ Object
90 91 92 93 |
# File 'lib/jolt/constraint.rb', line 90 def __mark_destroyed @destroyed = true @pointer = nil end |
#__native_pointer ⇒ Object
81 82 83 84 |
# File 'lib/jolt/constraint.rb', line 81 def __native_pointer check_alive! @pointer end |
#current_position ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jolt/constraint.rb', line 42 def current_position check_alive! function = case @kind when :hinge then :JPH_HingeConstraint_GetCurrentAngle when :slider then :JPH_SliderConstraint_GetCurrentPosition else raise InvalidArgumentError, "#{@kind} constraints do not have a scalar position" end Native.public_send(function, @pointer) end |
#destroy ⇒ Object
73 74 75 |
# File 'lib/jolt/constraint.rb', line 73 def destroy @system.__destroy_constraint(self) end |
#destroyed? ⇒ Boolean
77 78 79 |
# File 'lib/jolt/constraint.rb', line 77 def destroyed? @destroyed end |
#disable_motor ⇒ Object
67 68 69 70 71 |
# File 'lib/jolt/constraint.rb', line 67 def disable_motor check_alive! Native.public_send(motor_functions.fetch(:state), @pointer, 0) self end |
#enabled=(value) ⇒ Object
21 22 23 24 |
# File 'lib/jolt/constraint.rb', line 21 def enabled=(value) check_alive! Native.JPH_Constraint_SetEnabled(@pointer, !!value) end |
#enabled? ⇒ Boolean
16 17 18 19 |
# File 'lib/jolt/constraint.rb', line 16 def enabled? check_alive! Native.JPH_Constraint_GetEnabled(@pointer) end |
#limits ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/jolt/constraint.rb', line 26 def limits check_alive! functions = limit_functions [ Native.public_send(functions.fetch(:min), @pointer), Native.public_send(functions.fetch(:max), @pointer) ] end |
#limits=(value) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/jolt/constraint.rb', line 35 def limits=(value) check_alive! minimum, maximum = ConstraintCollection.interval(value, "limits") Native.public_send(limit_functions.fetch(:set), @pointer, minimum, maximum) value end |
#motor_speed ⇒ Object
53 54 55 56 |
# File 'lib/jolt/constraint.rb', line 53 def motor_speed check_alive! Native.public_send(motor_functions.fetch(:get), @pointer) end |
#motor_speed=(value) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/jolt/constraint.rb', line 58 def motor_speed=(value) check_alive! speed = Conversions.finite_float(value, "motor_speed") functions = motor_functions Native.public_send(functions.fetch(:state), @pointer, 1) Native.public_send(functions.fetch(:set), @pointer, speed) value end |