Class: BulldogPhysics::World

Inherits:
Object
  • Object
show all
Defined in:
lib/RigidBodies/world.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_contacts = 20, iterations = 5) ⇒ World

Returns a new instance of World.



31
32
33
34
35
36
37
38
39
# File 'lib/RigidBodies/world.rb', line 31

def initialize(max_contacts = 20, iterations = 5)
	@max_contacts = max_contacts
	@contacts = Array.new
	@calculate_iterations = iterations == 0
	@resolver = ContactResolver.new(iterations)
	@bodies = Array.new
	@registry = ForceRegistry.new
	@contact_generators = Array.new
end

Instance Attribute Details

#bodiesObject

Returns the value of attribute bodies.



22
23
24
# File 'lib/RigidBodies/world.rb', line 22

def bodies
  @bodies
end

#calculate_iterationsObject

Returns the value of attribute calculate_iterations.



28
29
30
# File 'lib/RigidBodies/world.rb', line 28

def calculate_iterations
  @calculate_iterations
end

#contact_generatorsObject

Returns the value of attribute contact_generators.



24
25
26
# File 'lib/RigidBodies/world.rb', line 24

def contact_generators
  @contact_generators
end

#contactsObject

Returns the value of attribute contacts.



26
27
28
# File 'lib/RigidBodies/world.rb', line 26

def contacts
  @contacts
end

#first_bodyObject

Returns the value of attribute first_body.



25
26
27
# File 'lib/RigidBodies/world.rb', line 25

def first_body
  @first_body
end

#max_contactsObject

Returns the value of attribute max_contacts.



27
28
29
# File 'lib/RigidBodies/world.rb', line 27

def max_contacts
  @max_contacts
end

#registryObject

Returns the value of attribute registry.



22
23
24
# File 'lib/RigidBodies/world.rb', line 22

def registry
  @registry
end

#resolverObject

Returns the value of attribute resolver.



23
24
25
# File 'lib/RigidBodies/world.rb', line 23

def resolver
  @resolver
end

Instance Method Details

#add_gravityObject



90
91
92
93
# File 'lib/RigidBodies/world.rb', line 90

def add_gravity
  #gravity = Gravity.new(Vector3.new(0, -0.5, 0))
  #@bodies.each{|body| @registry.add(body, gravity)}
end

#generate_contactsObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/RigidBodies/world.rb', line 48

def generate_contacts()
	limit = @max_contacts


	for g in @contact_generators
		used = g.add_contact(@contacts, limit)				
	end

	#eturn @max_contacts - limit
	return @contacts.size
end

#integrate(duration) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/RigidBodies/world.rb', line 61

def integrate(duration)
	for b in @bodies
		b.integrate(duration)
		b.calculate_derived_data
		#b.calculate_internals
	end
end

#run_physics(duration, clear_contacts = true) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/RigidBodies/world.rb', line 69

def run_physics(duration, clear_contacts = true)

	#@contacts.clear() if clear_contacts

	@registry.update_forces(duration)
	integrate(duration)
	used_contacts = generate_contacts()
        
	if(used_contacts > 0)
		#if(@calculate_iterations)
	  		@resolver.iterations = used_contacts * 2
	  		@resolver.resolve_contacts(@contacts, used_contacts, duration)
	#	end
	end




	#integrate(duration)
end

#start_frameObject



41
42
43
44
45
46
# File 'lib/RigidBodies/world.rb', line 41

def start_frame()
	@bodies.each do |body|
		body.clear_accumulators
		body.calculate_derived_data
	end
end