Class: BulldogPhysics::Buoyancy
- Inherits:
-
ForceGenerator
- Object
- ForceGenerator
- BulldogPhysics::Buoyancy
- Defined in:
- lib/RigidBodies/buoyancy.rb
Instance Attribute Summary collapse
-
#center_of_buoyancy ⇒ Object
Returns the value of attribute center_of_buoyancy.
-
#liquid_density ⇒ Object
Returns the value of attribute liquid_density.
-
#max_depth ⇒ Object
Returns the value of attribute max_depth.
-
#volume ⇒ Object
Returns the value of attribute volume.
-
#water_height ⇒ Object
Returns the value of attribute water_height.
Instance Method Summary collapse
-
#initialize(c_of_b, max_depth, volume, water_height, liquid_density = 1000.0) ⇒ Buoyancy
constructor
A new instance of Buoyancy.
- #update_force(body, duration) ⇒ Object
Constructor Details
#initialize(c_of_b, max_depth, volume, water_height, liquid_density = 1000.0) ⇒ Buoyancy
Returns a new instance of Buoyancy.
6 7 8 9 |
# File 'lib/RigidBodies/buoyancy.rb', line 6 def initialize(c_of_b, max_depth, volume, water_height, liquid_density = 1000.0) @center_of_buoyancy, @max_depth, @volume, @water_height, @liquid_density = c_of_b, max_depth, volume, water_height, liquid_density end |
Instance Attribute Details
#center_of_buoyancy ⇒ Object
Returns the value of attribute center_of_buoyancy.
4 5 6 |
# File 'lib/RigidBodies/buoyancy.rb', line 4 def center_of_buoyancy @center_of_buoyancy end |
#liquid_density ⇒ Object
Returns the value of attribute liquid_density.
4 5 6 |
# File 'lib/RigidBodies/buoyancy.rb', line 4 def liquid_density @liquid_density end |
#max_depth ⇒ Object
Returns the value of attribute max_depth.
4 5 6 |
# File 'lib/RigidBodies/buoyancy.rb', line 4 def max_depth @max_depth end |
#volume ⇒ Object
Returns the value of attribute volume.
4 5 6 |
# File 'lib/RigidBodies/buoyancy.rb', line 4 def volume @volume end |
#water_height ⇒ Object
Returns the value of attribute water_height.
4 5 6 |
# File 'lib/RigidBodies/buoyancy.rb', line 4 def water_height @water_height end |
Instance Method Details
#update_force(body, duration) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/RigidBodies/buoyancy.rb', line 11 def update_force(body, duration) point_in_world = body.get_point_in_world_space(@center_of_buoyancy) depth = point_in_world.y if(depth >= @water_height + @max_depth) return end force = Vector3.new if depth <= @water_height - @max_depth force.y = @liquid_density * @volume body.add_force_at_point(force, @center_of_buoyancy) return end force.y = @liquid_density * @volume * (depth - @max_depth - @water_height) / (2 * @max_depth) body.add_force_at_point(force, @center_of_buoyancy) end |