Module: Box2D::ShapeDefinition
- Defined in:
- lib/box2d/shape_definition.rb
Class Method Summary collapse
- .apply_filter(filter, options) ⇒ Object
- .build(options) ⇒ Object
- .coefficient(value, label) ⇒ Object
- .query_filter(options) ⇒ Object
Class Method Details
.apply_filter(filter, options) ⇒ Object
31 32 33 34 35 |
# File 'lib/box2d/shape_definition.rb', line 31 def apply_filter(filter, ) filter[:categoryBits] = Integer(.fetch(:category, filter[:categoryBits])) filter[:maskBits] = Integer(.fetch(:mask, filter[:maskBits])) filter[:groupIndex] = Integer(.fetch(:group, filter[:groupIndex])) end |
.build(options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/box2d/shape_definition.rb', line 7 def build() definition = Native.b2DefaultShapeDef material = definition[:material] material[:friction] = ValueConversion.non_negative_float(.fetch(:friction, 0.6), label: "friction") material[:restitution] = coefficient(.fetch(:restitution, 0.0), "restitution") material[:rollingResistance] = coefficient(.fetch(:rolling_resistance, 0.0), "rolling_resistance") material[:tangentSpeed] = ValueConversion.finite_float(.fetch(:tangent_speed, 0.0), label: "tangent_speed") material[:userMaterialId] = Integer(.fetch(:material, 0)) definition[:density] = ValueConversion.non_negative_float(.fetch(:density, 1.0), label: "density") definition[:isSensor] = !!.fetch(:sensor, false) definition[:enableSensorEvents] = !!.fetch(:sensor_events, true) definition[:enableContactEvents] = !!.fetch(:contact_events, true) definition[:enableHitEvents] = !!.fetch(:hit_events, true) apply_filter(definition[:filter], .fetch(:filter, {})) definition end |
.coefficient(value, label) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/box2d/shape_definition.rb', line 37 def coefficient(value, label) number = ValueConversion.non_negative_float(value, label:) return number if number <= 1.0 raise ArgumentError, "#{label} must be between 0 and 1" end |
.query_filter(options) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/box2d/shape_definition.rb', line 24 def query_filter() filter = Native.b2DefaultQueryFilter filter[:categoryBits] = Integer(.fetch(:category, filter[:categoryBits])) filter[:maskBits] = Integer(.fetch(:mask, filter[:maskBits])) filter end |