Class: Box2D::Chain

Inherits:
Handle show all
Defined in:
lib/box2d/chain.rb

Constant Summary collapse

ID_CLASS =
Native::ChainId

Instance Attribute Summary collapse

Attributes inherited from Handle

#id, #world

Instance Method Summary collapse

Methods inherited from Handle

#destroyed?, #eql?, #hash, #valid?

Constructor Details

#initialize(world, id, body: nil) ⇒ Chain

Returns a new instance of Chain.



9
10
11
12
# File 'lib/box2d/chain.rb', line 9

def initialize(world, id, body: nil)
  super(world, id)
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/box2d/chain.rb', line 7

def body
  @body
end

Instance Method Details

#destroyObject



14
15
16
17
18
19
20
21
# File 'lib/box2d/chain.rb', line 14

def destroy
  ensure_valid!
  Native.b2DestroyChain(@id)
  invalidate!
  @world.unregister_chain(self)
  @body&.unregister_chain(self)
  true
end

#frictionObject



35
36
37
38
# File 'lib/box2d/chain.rb', line 35

def friction
  ensure_valid!
  Native.b2Chain_GetFriction(@id)
end

#friction=(value) ⇒ Object



40
41
42
43
# File 'lib/box2d/chain.rb', line 40

def friction=(value)
  ensure_valid!
  Native.b2Chain_SetFriction(@id, ValueConversion.non_negative_float(value, label: "friction"))
end

#restitutionObject



45
46
47
48
# File 'lib/box2d/chain.rb', line 45

def restitution
  ensure_valid!
  Native.b2Chain_GetRestitution(@id)
end

#restitution=(value) ⇒ Object



50
51
52
53
# File 'lib/box2d/chain.rb', line 50

def restitution=(value)
  ensure_valid!
  Native.b2Chain_SetRestitution(@id, ShapeDefinition.coefficient(value, "restitution"))
end

#segmentsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/box2d/chain.rb', line 23

def segments
  ensure_valid!
  count = Native.b2Chain_GetSegmentCount(@id)
  pointer = FFI::MemoryPointer.new(Native::ShapeId, count)
  actual = Native.b2Chain_GetSegments(@id, pointer, count)

  Array.new(actual) do |index|
    id = Native::ShapeId.new(pointer + index * Native::ShapeId.size)
    @world.shape_for_id(id)
  end
end