bulldog_physics 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bulldog_physics.gemspec +2 -2
- data/lib/Particles/particle_gravity.rb +1 -4
- data/lib/bulldog_physics.rb +10 -6
- data/lib/examples/simple_game.rb +61 -61
- data/lib/vector3.rb +9 -7
- metadata +4 -4
data/Rakefile
CHANGED
@@ -21,8 +21,8 @@ Jeweler::Tasks.new do |gem|
|
|
21
21
|
gem.description = %Q{3D Physics Engine written in pure ruby that can be used for creating 3d simulations or games}
|
22
22
|
gem.email = "conner.wingard@gmail.com"
|
23
23
|
gem.authors = ["Conner Wingard"]
|
24
|
-
|
25
24
|
gem.add_dependency 'require_all'
|
25
|
+
|
26
26
|
# dependencies defined in Gemfile
|
27
27
|
end
|
28
28
|
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/bulldog_physics.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "bulldog_physics"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Conner Wingard"]
|
12
|
-
s.date = "2012-04-
|
12
|
+
s.date = "2012-04-26"
|
13
13
|
s.description = "3D Physics Engine written in pure ruby that can be used for creating 3d simulations or games"
|
14
14
|
s.email = "conner.wingard@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -15,11 +15,8 @@ module BulldogPhysics
|
|
15
15
|
#override
|
16
16
|
def update_force(particle, duration)
|
17
17
|
unless particle.has_infinite_mass
|
18
|
-
#puts "update_force"
|
19
|
-
#puts particle.mass
|
20
18
|
force_to_add = @gravity * particle.mass
|
21
|
-
particle.addForce(
|
22
|
-
#puts particle.object_id
|
19
|
+
particle.addForce(force_to_add)
|
23
20
|
end
|
24
21
|
particle
|
25
22
|
end
|
data/lib/bulldog_physics.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# make life easier by including all Physics files here
|
2
|
-
require 'rubygems'
|
3
2
|
require 'require_all'
|
4
3
|
|
5
4
|
|
@@ -21,10 +20,10 @@ class Module
|
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
|
-
require '
|
25
|
-
require '
|
26
|
-
require '
|
27
|
-
require '
|
23
|
+
#require 'vector3.rb'
|
24
|
+
#require 'matrix3.rb'
|
25
|
+
#require 'matrix4.rb'
|
26
|
+
#require 'quaternion.rb'
|
28
27
|
|
29
28
|
module BulldogPhysics
|
30
29
|
|
@@ -40,4 +39,9 @@ module BulldogPhysics
|
|
40
39
|
|
41
40
|
end
|
42
41
|
|
43
|
-
require_all 'Particles'
|
42
|
+
#require_all 'Particles'
|
43
|
+
require 'vector3'
|
44
|
+
require 'matrix3'
|
45
|
+
require 'quaternion'
|
46
|
+
require 'matrix4'
|
47
|
+
require_all File.dirname(__FILE__) + '/Particles'
|
data/lib/examples/simple_game.rb
CHANGED
@@ -44,7 +44,7 @@ class Game
|
|
44
44
|
@clock = Clock.new
|
45
45
|
@lighting = Lighting.new
|
46
46
|
@x_trans = 0; @y_trans = -5; @z_trans = -25
|
47
|
-
|
47
|
+
|
48
48
|
|
49
49
|
@world = ParticleWorld.new(20, 1)
|
50
50
|
|
@@ -67,8 +67,8 @@ class Game
|
|
67
67
|
@ball.damping = 1
|
68
68
|
@ball.material.specular = BALL_SPECULAR
|
69
69
|
@ball.material.diffuse = PARTICLE_DIFFUSE
|
70
|
-
|
71
|
-
|
70
|
+
@ball.frozen = true
|
71
|
+
|
72
72
|
|
73
73
|
@current_ball = Particle.new
|
74
74
|
@current_ball.position = @ball.position
|
@@ -79,7 +79,7 @@ class Game
|
|
79
79
|
@world.registry.add( @current_ball, ParticleGravity.new())
|
80
80
|
@world.particles << @current_ball
|
81
81
|
|
82
|
-
|
82
|
+
|
83
83
|
particle1 = Particle.new
|
84
84
|
particle1.mass = 1
|
85
85
|
particle1.position = Vector3.new(5,2,0)
|
@@ -98,25 +98,25 @@ class Game
|
|
98
98
|
|
99
99
|
prod = ParticleRod.new(particle1, particle2, 2.0)
|
100
100
|
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
@world.particles << particle1
|
102
|
+
@world.particles << particle2
|
103
|
+
@world.contact_generators << prod
|
104
104
|
|
105
|
-
|
106
|
-
|
105
|
+
@world.contact_generators << ParticleGroundContacts.new(@world.particles)
|
106
|
+
@world.contact_generators << ParticleParticleContacts.new(@world.particles)
|
107
107
|
|
108
108
|
for i in 1..5
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
109
|
+
for j in 1..5
|
110
|
+
part = Particle.new
|
111
|
+
part.mass = 0
|
112
|
+
offset = j % 2 == 0 ? 1 : 0
|
113
|
+
part.position = Vector3.new( -5 + i * 2 + offset, j * 2, 0)
|
114
|
+
part.material.specular = SPRING_SPECULAR
|
115
|
+
part.material.diffuse = PARTICLE_DIFFUSE
|
116
|
+
@world.particles << part
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
120
|
|
121
121
|
puts "PARTICLE COUNT [ #{@world.particles.size} ] "
|
122
122
|
puts "Contact Generators count: #{@world.contact_generators.size}"
|
@@ -134,8 +134,8 @@ class Game
|
|
134
134
|
Rubygame::GL.set_attrib(Rubygame::GL::BLUE_SIZE, 5)
|
135
135
|
Rubygame::GL.set_attrib(Rubygame::GL::DEPTH_SIZE, 16)
|
136
136
|
Rubygame::GL.set_attrib(Rubygame::GL::DOUBLEBUFFER, 1)
|
137
|
-
|
138
|
-
|
137
|
+
|
138
|
+
@maximum_resolution = Screen.get_resolution
|
139
139
|
@screen = Screen.new([@width,@height], 16, [OPENGL])
|
140
140
|
@clock.target_framerate = 30
|
141
141
|
@clock.calibrate
|
@@ -167,41 +167,41 @@ class Game
|
|
167
167
|
|
168
168
|
def run()
|
169
169
|
catch(:rubygame_quit) do
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
170
|
+
loop do
|
171
|
+
@queue.each do |event|
|
172
|
+
case event
|
173
|
+
when Rubygame::Events::KeyPressed
|
174
174
|
# puts event.key
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
175
|
+
case event.key
|
176
|
+
when :escape
|
177
|
+
throw :rubygame_quit
|
178
|
+
when :q
|
179
|
+
throw :rubygame_quit
|
180
|
+
when :w
|
181
|
+
@w_down = true
|
182
|
+
when :s
|
183
|
+
@s_down = true
|
184
|
+
when :a
|
185
|
+
@a_down = true
|
186
|
+
when :d
|
187
|
+
@d_down = true
|
188
|
+
when :l
|
189
|
+
@world.particles.each do |part|
|
190
|
+
puts part.position
|
191
|
+
puts "NUM CONTACTS: #{@world.contacts.size}"
|
192
|
+
end
|
193
|
+
when :space
|
194
|
+
@current_ball.frozen = !@current_ball.frozen
|
195
195
|
when :r
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
196
|
+
puts "RESET"
|
197
|
+
@current_ball = Particle.new
|
198
|
+
@current_ball.position = START_POSITION.dup
|
199
|
+
@current_ball.velocity = @ball.velocity.dup
|
200
|
+
@current_ball.mass = @ball.mass
|
201
|
+
@current_ball.damping = @ball.damping
|
202
|
+
@current_ball.frozen = true
|
203
|
+
@world.registry.add( @current_ball, ParticleGravity.new())
|
204
|
+
@world.particles << @current_ball
|
205
205
|
end
|
206
206
|
when Rubygame::Events::KeyReleased
|
207
207
|
case event.key
|
@@ -237,7 +237,7 @@ class Game
|
|
237
237
|
@world.start_frame
|
238
238
|
|
239
239
|
glClearColor(0.0, 0.0, 0.0, -1.0)
|
240
|
-
|
240
|
+
glClear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT)
|
241
241
|
glLoadIdentity()
|
242
242
|
|
243
243
|
glTranslatef(@x_trans,@y_trans,@z_trans)
|
@@ -252,7 +252,7 @@ class Game
|
|
252
252
|
glPopMatrix()
|
253
253
|
|
254
254
|
|
255
|
-
draw_skybox()
|
255
|
+
#draw_skybox()
|
256
256
|
|
257
257
|
#glClear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT)
|
258
258
|
@world.particles.each do |particle|
|
@@ -266,12 +266,12 @@ class Game
|
|
266
266
|
|
267
267
|
@world.run_physics(seconds_elapsed)
|
268
268
|
|
269
|
-
|
270
|
-
|
269
|
+
Rubygame::GL.swap_buffers()
|
270
|
+
@screen.update
|
271
271
|
@screen.flip
|
272
|
-
|
272
|
+
ObjectSpace.garbage_collect
|
273
273
|
|
274
|
-
|
274
|
+
end
|
275
275
|
end
|
276
276
|
|
277
277
|
end
|
data/lib/vector3.rb
CHANGED
@@ -21,10 +21,11 @@ module BulldogPhysics
|
|
21
21
|
|
22
22
|
## Gets the magnitude of this vector.
|
23
23
|
def magnitude
|
24
|
-
|
25
|
-
|
24
|
+
num = (@x*@x) + (@y * @y) + (@z * @z)
|
25
|
+
#return 0 if num.nan?
|
26
26
|
Math.sqrt((@x*@x)+(@y*@y)+(@z*@z))
|
27
|
-
|
27
|
+
end
|
28
|
+
|
28
29
|
|
29
30
|
def squareMagnitude
|
30
31
|
return (@x*@x)+(@y*@y)+(@z*@z)
|
@@ -34,11 +35,12 @@ module BulldogPhysics
|
|
34
35
|
def normalize
|
35
36
|
length = self.magnitude
|
36
37
|
if length > 0
|
37
|
-
@x
|
38
|
-
@y
|
39
|
-
@z
|
38
|
+
@x *= 1.0/length
|
39
|
+
@y *= 1.0/length
|
40
|
+
@z *= 1.0/length
|
40
41
|
end
|
41
42
|
end
|
43
|
+
|
42
44
|
|
43
45
|
def unit
|
44
46
|
length = self.magnitude
|
@@ -90,7 +92,7 @@ module BulldogPhysics
|
|
90
92
|
end
|
91
93
|
|
92
94
|
def *(scalar)
|
93
|
-
if scalar.kind_of?
|
95
|
+
if scalar.kind_of? Numeric
|
94
96
|
Vector3.new(@x*scalar, @y*scalar, @z*scalar)
|
95
97
|
elsif scalar.kind_of? Vector3
|
96
98
|
return @x * scalar.x + @y * scalar.y + @z * scalar.z
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bulldog_physics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Conner Wingard
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-26 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
type: :runtime
|