Class: CP::Arbiter
- Inherits:
-
Object
- Object
- CP::Arbiter
- Defined in:
- lib/chipmunk-ffi/arbiter.rb
Instance Attribute Summary collapse
-
#struct ⇒ Object
readonly
Returns the value of attribute struct.
Instance Method Summary collapse
- #a ⇒ Object
- #b ⇒ Object
- #e ⇒ Object
- #e=(new_e) ⇒ Object
- #each_contact ⇒ Object
- #first_contact? ⇒ Boolean
- #impulse(with_friction = false) ⇒ Object
-
#initialize(ptr) ⇒ Arbiter
constructor
A new instance of Arbiter.
- #normal(index = 0) ⇒ Object
- #point(index = 0) ⇒ Object
- #shapes ⇒ Object
- #u ⇒ Object
- #u=(new_u) ⇒ Object
Constructor Details
#initialize(ptr) ⇒ Arbiter
Returns a new instance of Arbiter.
29 30 31 32 33 34 35 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 29 def initialize(ptr) @struct = ArbiterStruct.new(ptr) @shapes = nil # Temporary workaround for a bug in chipmunk, fixed in r342. @struct.num_contacts = 0 if @struct.contacts.null? end |
Instance Attribute Details
#struct ⇒ Object (readonly)
Returns the value of attribute struct.
28 29 30 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 28 def struct @struct end |
Instance Method Details
#a ⇒ Object
78 79 80 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 78 def a self.shapes[0] end |
#b ⇒ Object
82 83 84 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 82 def b self.shapes[1] end |
#e ⇒ Object
86 87 88 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 86 def e @struct.e end |
#e=(new_e) ⇒ Object
89 90 91 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 89 def e=(new_e) @struct.e = new_e end |
#each_contact ⇒ Object
100 101 102 103 104 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 100 def each_contact (0...@struct.num_contacts).each do |index| yield CP.cpArbiterGetPoint(@struct, index), CP.cpArbiterGetNormal(@struct, index) end end |
#first_contact? ⇒ Boolean
37 38 39 40 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 37 def first_contact? # CP.cpArbiterIsFirstContact(@struct.pointer).nonzero? @struct.first_col.nonzero? end |
#impulse(with_friction = false) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 52 def impulse with_friction = false if with_friction Vec2.new CP.cpArbiterTotalImpulseWithFriction(@struct.pointer) else Vec2.new CP.cpArbiterTotalImpulse(@struct.pointer) end end |
#normal(index = 0) ⇒ Object
47 48 49 50 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 47 def normal(index = 0) raise IndexError unless (0...@struct.num_contacts).include? index Vec2.new CP.cpArbiterGetNormal(@struct.pointer, index) end |
#point(index = 0) ⇒ Object
42 43 44 45 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 42 def point(index = 0) raise IndexError unless (0...@struct.num_contacts).include? index Vec2.new CP.cpArbiterGetPoint(@struct.pointer, index) end |
#shapes ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 60 def shapes return @shapes if @shapes swapped = @struct.swapped_col.nonzero? arba = swapped ? @struct.b : @struct.a arbb = swapped ? @struct.a : @struct.b as = ShapeStruct.new(arba) a_obj_id = as.data.get_long 0 rb_a = ObjectSpace._id2ref a_obj_id bs = ShapeStruct.new(arbb) b_obj_id = bs.data.get_long 0 rb_b = ObjectSpace._id2ref b_obj_id @shapes = [ rb_a, rb_b ] end |
#u ⇒ Object
93 94 95 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 93 def u @struct.u end |
#u=(new_u) ⇒ Object
96 97 98 |
# File 'lib/chipmunk-ffi/arbiter.rb', line 96 def u=(new_u) @struct.u = new_u end |