Class: BulldogPhysics::Buoyancy

Inherits:
ForceGenerator show all
Defined in:
lib/RigidBodies/buoyancy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_buoyancyObject

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_densityObject

Returns the value of attribute liquid_density.



4
5
6
# File 'lib/RigidBodies/buoyancy.rb', line 4

def liquid_density
  @liquid_density
end

#max_depthObject

Returns the value of attribute max_depth.



4
5
6
# File 'lib/RigidBodies/buoyancy.rb', line 4

def max_depth
  @max_depth
end

#volumeObject

Returns the value of attribute volume.



4
5
6
# File 'lib/RigidBodies/buoyancy.rb', line 4

def volume
  @volume
end

#water_heightObject

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