Class: CP::DampedSpring
- Inherits:
-
Object
- Object
- CP::DampedSpring
- Includes:
- Constraint
- Defined in:
- lib/chipmunk-ffi/constraints/damped_spring.rb
Constant Summary
Constants included from Constraint
Constraint::DampedRotarySpring, Constraint::DampedSpring, Constraint::GearJoint, Constraint::GrooveJoint, Constraint::PinJoint, Constraint::PivotJoint, Constraint::RatchetJoint, Constraint::RotaryLimitJoint, Constraint::SimpleMotor, Constraint::SlideJoint
Instance Attribute Summary
Attributes included from Constraint
Instance Method Summary collapse
-
#initialize(a_body, b_body, anchr_one, anchr_two, rest_length, stiffness, damping) ⇒ DampedSpring
constructor
A new instance of DampedSpring.
- #spring_force_func ⇒ Object
- #spring_force_func=(l) ⇒ Object
Methods included from Constraint
Constructor Details
#initialize(a_body, b_body, anchr_one, anchr_two, rest_length, stiffness, damping) ⇒ DampedSpring
Returns a new instance of DampedSpring.
26 27 28 29 30 31 32 33 34 |
# File 'lib/chipmunk-ffi/constraints/damped_spring.rb', line 26 def initialize(a_body, b_body, anchr_one, anchr_two, rest_length, stiffness, damping) @body_a, @body_b = a_body, b_body @struct = DampedSpringStruct.new(CP.cpDampedSpringNew( a_body.struct.pointer,b_body.struct.pointer,anchr_one.struct,anchr_two.struct, rest_length, stiffness, damping)) set_data_pointer set_initial_force_proc end |
Instance Method Details
#spring_force_func ⇒ Object
36 37 38 |
# File 'lib/chipmunk-ffi/constraints/damped_spring.rb', line 36 def spring_force_func @user_level_force_lambda end |
#spring_force_func=(l) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/chipmunk-ffi/constraints/damped_spring.rb', line 40 def spring_force_func=(l) @user_level_force_lambda = l # We keep the lambda in an ivar to keep it from being GCed @spring_force_lambda = Proc.new do |spring_ptr,dist| spring_struct = DampedSpringStruct.new(spring_ptr) obj_id = spring_struct.constraint.data.get_long(0) spring = ObjectSpace._id2ref(obj_id) l.call(spring,dist) end @struct.spring_force_func = @spring_force_lambda end |