Class: Box2D::Shape
Constant Summary
collapse
- ID_CLASS =
Native::ShapeId
- TYPES =
{
Native::ShapeType::CIRCLE_SHAPE => :circle,
Native::ShapeType::CAPSULE_SHAPE => :capsule,
Native::ShapeType::SEGMENT_SHAPE => :segment,
Native::ShapeType::POLYGON_SHAPE => :polygon,
Native::ShapeType::CHAIN_SEGMENT_SHAPE => :chain_segment
}.freeze
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) ⇒ Shape
Returns a new instance of Shape.
16
17
18
19
|
# File 'lib/box2d/shape.rb', line 16
def initialize(world, id, body: nil)
super(world, id)
@body = body
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
14
15
16
|
# File 'lib/box2d/shape.rb', line 14
def body
@body
end
|
Instance Method Details
#density ⇒ Object
40
41
42
43
|
# File 'lib/box2d/shape.rb', line 40
def density
ensure_valid!
Native.b2Shape_GetDensity(@id)
end
|
#density=(value) ⇒ Object
#destroy ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/box2d/shape.rb', line 21
def destroy
ensure_valid!
Native.b2DestroyShape(@id, true)
invalidate!
@world.unregister_shape(self)
@body&.unregister_shape(self)
true
end
|
#filter ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/box2d/shape.rb', line 70
def filter
ensure_valid!
native_filter = Native.b2Shape_GetFilter(@id)
{
category: native_filter[:categoryBits],
mask: native_filter[:maskBits],
group: native_filter[:groupIndex]
}
end
|
#filter=(options) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/box2d/shape.rb', line 80
def filter=(options)
ensure_valid!
native_filter = Native.b2Shape_GetFilter(@id)
ShapeDefinition.apply_filter(native_filter, options)
Native.b2Shape_SetFilter(@id, native_filter)
end
|
#friction ⇒ Object
50
51
52
53
|
# File 'lib/box2d/shape.rb', line 50
def friction
ensure_valid!
Native.b2Shape_GetFriction(@id)
end
|
#friction=(value) ⇒ Object
#restitution ⇒ Object
60
61
62
63
|
# File 'lib/box2d/shape.rb', line 60
def restitution
ensure_valid!
Native.b2Shape_GetRestitution(@id)
end
|
#restitution=(value) ⇒ Object
65
66
67
68
|
# File 'lib/box2d/shape.rb', line 65
def restitution=(value)
ensure_valid!
Native.b2Shape_SetRestitution(@id, ShapeDefinition.coefficient(value, "restitution"))
end
|
#sensor? ⇒ Boolean
35
36
37
38
|
# File 'lib/box2d/shape.rb', line 35
def sensor?
ensure_valid!
Native.b2Shape_IsSensor(@id)
end
|
#type ⇒ Object
30
31
32
33
|
# File 'lib/box2d/shape.rb', line 30
def type
ensure_valid!
TYPES.fetch(Native.b2Shape_GetType(@id))
end
|
#user_data ⇒ Object
87
88
89
90
|
# File 'lib/box2d/shape.rb', line 87
def user_data
ensure_valid!
@world.shape_user_data(self)
end
|
#user_data=(value) ⇒ Object
92
93
94
95
|
# File 'lib/box2d/shape.rb', line 92
def user_data=(value)
ensure_valid!
@world.set_shape_user_data(self, value)
end
|