Class: MSPhysics::Material

Inherits:
Entity
  • Object
show all
Defined in:
RubyExtension/MSPhysics/material.rb

Overview

Since:

  • 1.0.0

Instance Method Summary collapse

Methods inherited from Entity

#inspect, #to_s

Constructor Details

#initialize(name, density, static_friction, kinetic_friction, elasticity, softness) ⇒ Material

Returns a new instance of Material.

Parameters:

  • name (String)

    Material name. Passing the name of an existing material will simply overwrite it.

  • density (Numeric)

    Material density in kilograms per cubic meter.

  • static_friction (Numeric)

    Static friction coefficient. This value is clamped between 0.01 and 2.00.

  • kinetic_friction (Numeric)

    Kinetic friction coefficient. This value is clamped between 0.01 and 2.00.

  • elasticity (Numeric)

    The coefficient of restitution. This is the rebound ratio. A basketball has a rebound ratio of 0.83. This means the new height of a basketball is 83% of original height within each bounce. This value is clamped between 0.01 and 2.00.

  • softness (Numeric)

    The softness coefficient. Decreasing softness yields adaptable collision. Increasing softness yields resistible collision. This value is clamped between 0.01 and 1.00. Typical value is 0.15.

Since:

  • 1.0.0



19
20
21
22
23
24
25
26
# File 'RubyExtension/MSPhysics/material.rb', line 19

def initialize(name, density, static_friction, kinetic_friction, elasticity, softness)
  @name = name.to_s
  @density = AMS.clamp(density, 0.001, nil)
  @static_friction = AMS.clamp(static_friction, 0.01, 2.00)
  @kinetic_friction = AMS.clamp(kinetic_friction, 0.01, 2.00)
  @elasticity = AMS.clamp(elasticity, 0.01, 2.00)
  @softness = AMS.clamp(softness, 0.01, 1.00)
end

Instance Method Details

#densityNumeric

Get material density in kilograms per cubic meter (kg/m^3).

Returns:

  • (Numeric)

Since:

  • 1.0.0



36
37
38
# File 'RubyExtension/MSPhysics/material.rb', line 36

def density
  @density
end

#density=(value) ⇒ Object

Set material density in kilograms per cubic meter (kg/m^3).

Parameters:

  • value (Numeric)

Since:

  • 1.0.0



42
43
44
# File 'RubyExtension/MSPhysics/material.rb', line 42

def density=(value)
  @density = AMS.clamp(value, 0.001, nil)
end

#elasticityNumeric

Get material coefficient of restitution - bounciness.

Returns:

  • (Numeric)

    A value between 0.01 and 2.00.

Since:

  • 1.0.0



72
73
74
# File 'RubyExtension/MSPhysics/material.rb', line 72

def elasticity
  @elasticity
end

#elasticity=(coefficient) ⇒ Object

Set material coefficient of restitution - bounciness.

Parameters:

  • coefficient (Numeric)

    A value between 0.01 and 2.00.

Since:

  • 1.0.0



78
79
80
# File 'RubyExtension/MSPhysics/material.rb', line 78

def elasticity=(coefficient)
  @elasticity = AMS.clamp(coefficient, 0.01, 2.00)
end

#equals?(other_material) ⇒ Boolean

Determine whether thi material has the same properties as another material.

Parameters:

Returns:

  • (Boolean)

Since:

  • 1.0.0



98
99
100
101
102
103
104
# File 'RubyExtension/MSPhysics/material.rb', line 98

def equals?(other_material)
  ( other_material.density == @density &&
    other_material.static_friction == @static_friction &&
    other_material.kinetic_friction == @kinetic_friction &&
    other_material.elasticity == @elasticity &&
    other_material.softness == @softness )
end

#kinetic_frictionNumeric

Get material kinetic friction coefficient.

Returns:

  • (Numeric)

    A value between 0.01 and 2.00.

Since:

  • 1.0.0



60
61
62
# File 'RubyExtension/MSPhysics/material.rb', line 60

def kinetic_friction
  @kinetic_friction
end

#kinetic_friction=(coefficient) ⇒ Object

Set material kinetic friction coefficient.

Parameters:

  • coefficient (Numeric)

    A value between 0.01 and 2.00.

Since:

  • 1.0.0



66
67
68
# File 'RubyExtension/MSPhysics/material.rb', line 66

def kinetic_friction=(coefficient)
  @kinetic_friction = AMS.clamp(coefficient, 0.01, 2.00)
end

#nameString

Get material name.

Returns:

  • (String)

Since:

  • 1.0.0



30
31
32
# File 'RubyExtension/MSPhysics/material.rb', line 30

def name
  @name
end

#softnessNumeric

Get material softness coefficient.

Returns:

  • (Numeric)

    A value between 0.01 and 1.00.

Since:

  • 1.0.0



84
85
86
# File 'RubyExtension/MSPhysics/material.rb', line 84

def softness
  @softness
end

#softness=(coefficient) ⇒ Object

Set material softness coefficient.

Parameters:

  • coefficient (Numeric)

    A value between 0.01 and 1.00.

Since:

  • 1.0.0



90
91
92
# File 'RubyExtension/MSPhysics/material.rb', line 90

def softness=(coefficient)
  @softness = AMS.clamp(coefficient, 0.01, 1.00)
end

#static_frictionNumeric

Get material static friction coefficient.

Returns:

  • (Numeric)

    A value between 0.01 and 2.00.

Since:

  • 1.0.0



48
49
50
# File 'RubyExtension/MSPhysics/material.rb', line 48

def static_friction
  @static_friction
end

#static_friction=(coefficient) ⇒ Object

Set material static friction coefficient.

Parameters:

  • coefficient (Numeric)

    A value between 0.01 and 2.00.

Since:

  • 1.0.0



54
55
56
# File 'RubyExtension/MSPhysics/material.rb', line 54

def static_friction=(coefficient)
  @static_friction = AMS.clamp(coefficient, 0.01, 2.00)
end