technohippy-Pongo 0.1.0
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/History.txt +17 -0
- data/Manifest.txt +52 -0
- data/README.txt +93 -0
- data/lib/pongo.rb +33 -0
- data/lib/pongo/abstract_collection.rb +135 -0
- data/lib/pongo/abstract_constraint.rb +25 -0
- data/lib/pongo/abstract_item.rb +93 -0
- data/lib/pongo/abstract_particle.rb +226 -0
- data/lib/pongo/angular_constraint.rb +108 -0
- data/lib/pongo/apengine.rb +157 -0
- data/lib/pongo/circle_particle.rb +36 -0
- data/lib/pongo/collision.rb +11 -0
- data/lib/pongo/collision_detector.rb +222 -0
- data/lib/pongo/collision_event.rb +23 -0
- data/lib/pongo/collision_resolver.rb +39 -0
- data/lib/pongo/composite.rb +52 -0
- data/lib/pongo/container/container.rb +7 -0
- data/lib/pongo/container/shoes_container.rb +14 -0
- data/lib/pongo/group.rb +166 -0
- data/lib/pongo/iforce.rb +7 -0
- data/lib/pongo/logger/logger.rb +21 -0
- data/lib/pongo/logger/shoes_logger.rb +15 -0
- data/lib/pongo/logger/standard_logger.rb +11 -0
- data/lib/pongo/rectangle_particle.rb +79 -0
- data/lib/pongo/renderer/renderer.rb +61 -0
- data/lib/pongo/renderer/shoes_renderer.rb +51 -0
- data/lib/pongo/renderer/tk_renderer.rb +73 -0
- data/lib/pongo/rim_particle.rb +53 -0
- data/lib/pongo/spring_constraint.rb +128 -0
- data/lib/pongo/spring_constraint_particle.rb +235 -0
- data/lib/pongo/util/interval.rb +13 -0
- data/lib/pongo/util/math_util.rb +27 -0
- data/lib/pongo/util/numeric_ext.rb +4 -0
- data/lib/pongo/util/vector.rb +133 -0
- data/lib/pongo/vector_force.rb +34 -0
- data/lib/pongo/wheel_particle.rb +103 -0
- metadata +90 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
module Pongo
|
2
|
+
# A particle that simulates the behavior of a wheel
|
3
|
+
class WheelParticle < CircleParticle
|
4
|
+
attr_accessor :rp, :tan, :norm_slip, :orientation, :traction
|
5
|
+
|
6
|
+
def initialize(x, y, radius, options={})
|
7
|
+
options = {:fixed => false, :mass => 1, :elasticity => 0.3, :friction => 0, :traction => 1}.update(options)
|
8
|
+
super(x, y, radius, options)
|
9
|
+
@tan = Vector.new
|
10
|
+
@norm_slip = Vector.new
|
11
|
+
@rp = RimParticle.new(radius, 2)
|
12
|
+
|
13
|
+
self.traction = options[:traction]
|
14
|
+
@orientation = Vector.new
|
15
|
+
end
|
16
|
+
|
17
|
+
# The speed of the WheelParticle. You can alter this value to make the
|
18
|
+
# WheelParticle spin.
|
19
|
+
def speed
|
20
|
+
@rp.speed
|
21
|
+
end
|
22
|
+
|
23
|
+
def speed=(s)
|
24
|
+
@rp.speed = s
|
25
|
+
end
|
26
|
+
|
27
|
+
# The angular velocity of the WheelParticle. You can alter this value to make the
|
28
|
+
# WheelParticle spin.
|
29
|
+
def angular_velocity
|
30
|
+
@rp.angular_velocity
|
31
|
+
end
|
32
|
+
|
33
|
+
def angular_velocity=(a)
|
34
|
+
@rp.angular_velocity = a
|
35
|
+
end
|
36
|
+
|
37
|
+
# The amount of traction during a collision. This property controls how much traction is
|
38
|
+
# applied when the WheelParticle is in contact with another particle. If the value is set
|
39
|
+
# to 0, there will be no traction and the WheelParticle will behave as if the
|
40
|
+
# surface was totally slippery, like ice. Values should be between 0 and 1.
|
41
|
+
#
|
42
|
+
# <p>
|
43
|
+
# Note that the friction property behaves differently than traction. If the surface
|
44
|
+
# friction is set high during a collision, the WheelParticle will move slowly as if
|
45
|
+
# the surface was covered in glue.
|
46
|
+
# </p>
|
47
|
+
def traction
|
48
|
+
1 - @traction
|
49
|
+
end
|
50
|
+
|
51
|
+
def traction=(t)
|
52
|
+
@traction = 1 - t
|
53
|
+
end
|
54
|
+
|
55
|
+
def radian
|
56
|
+
@orientation.set_to(rp.curr)
|
57
|
+
Math.atan2(@orientation.y, @orientation.x) + Math::PI
|
58
|
+
end
|
59
|
+
|
60
|
+
def angle
|
61
|
+
self.radian * MathUtil::ONE_EIGHTY_OVER_PI
|
62
|
+
end
|
63
|
+
|
64
|
+
def update(dt)
|
65
|
+
super
|
66
|
+
@rp.update(dt)
|
67
|
+
end
|
68
|
+
|
69
|
+
def resolve_collision(mtd, vel, n, d, o, p)
|
70
|
+
super
|
71
|
+
resolve(n * MathUtil.sign(d * o))
|
72
|
+
end
|
73
|
+
|
74
|
+
# simulates torque/wheel-ground interaction - n is the surface normal
|
75
|
+
# Origins of this code thanks to Raigan Burns, Metanet software
|
76
|
+
def resolve(n)
|
77
|
+
# this is the tangent vector at the rim particle
|
78
|
+
@tan.set_to(-@rp.curr.y, @rp.curr.x)
|
79
|
+
|
80
|
+
# normalize so we can scale by the rotational speed
|
81
|
+
@tan = @tan.normalize
|
82
|
+
|
83
|
+
# velocity of the wheel's surface
|
84
|
+
wheel_surface_velocity = @tan * @rp.speed
|
85
|
+
|
86
|
+
# the velocity of the wheel's surface relative to the ground
|
87
|
+
combined_velocity = velocity.plus!(wheel_surface_velocity)
|
88
|
+
|
89
|
+
# the wheel's comb velocity projected onto the contact normal
|
90
|
+
cp = combined_velocity.cross(n)
|
91
|
+
|
92
|
+
# set the wheel's spinspeed to track the ground
|
93
|
+
@tan.mult!(cp)
|
94
|
+
@rp.prev.copy(@rp.curr - @tan)
|
95
|
+
|
96
|
+
# some of the wheel's torque is removed and converted into linear displacement
|
97
|
+
slip_speed = (1 - @traction) * @rp.speed
|
98
|
+
norm_slip.set_to(slip_speed * n.y, slip_speed * n.x)
|
99
|
+
@curr.plus!(norm_slip)
|
100
|
+
@rp.speed *= @traction
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: technohippy-Pongo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ANDO Yasushi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-07 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby version of APE (Actionscript Physics Engine)
|
17
|
+
email: andyjpn@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- History.txt
|
26
|
+
- lib/pongo/abstract_collection.rb
|
27
|
+
- lib/pongo/abstract_constraint.rb
|
28
|
+
- lib/pongo/abstract_item.rb
|
29
|
+
- lib/pongo/abstract_particle.rb
|
30
|
+
- lib/pongo/angular_constraint.rb
|
31
|
+
- lib/pongo/apengine.rb
|
32
|
+
- lib/pongo/circle_particle.rb
|
33
|
+
- lib/pongo/collision.rb
|
34
|
+
- lib/pongo/collision_detector.rb
|
35
|
+
- lib/pongo/collision_event.rb
|
36
|
+
- lib/pongo/collision_resolver.rb
|
37
|
+
- lib/pongo/composite.rb
|
38
|
+
- lib/pongo/container
|
39
|
+
- lib/pongo/container/container.rb
|
40
|
+
- lib/pongo/container/shoes_container.rb
|
41
|
+
- lib/pongo/group.rb
|
42
|
+
- lib/pongo/iforce.rb
|
43
|
+
- lib/pongo/logger/logger.rb
|
44
|
+
- lib/pongo/logger/shoes_logger.rb
|
45
|
+
- lib/pongo/logger/standard_logger.rb
|
46
|
+
- lib/pongo/rectangle_particle.rb
|
47
|
+
- lib/pongo/renderer/renderer.rb
|
48
|
+
- lib/pongo/renderer/shoes_renderer.rb
|
49
|
+
- lib/pongo/renderer/tk_renderer.rb
|
50
|
+
- lib/pongo/rim_particle.rb
|
51
|
+
- lib/pongo/spring_constraint.rb
|
52
|
+
- lib/pongo/spring_constraint_particle.rb
|
53
|
+
- lib/pongo/util/interval.rb
|
54
|
+
- lib/pongo/util/math_util.rb
|
55
|
+
- lib/pongo/util/numeric_ext.rb
|
56
|
+
- lib/pongo/util/vector.rb
|
57
|
+
- lib/pongo/vector_force.rb
|
58
|
+
- lib/pongo/wheel_particle.rb
|
59
|
+
- lib/pongo.rb
|
60
|
+
- Manifest.txt
|
61
|
+
- README.txt
|
62
|
+
has_rdoc: false
|
63
|
+
homepage: http://github.com/technohippy/Pongo
|
64
|
+
licenses:
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
81
|
+
version:
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project: pongo
|
85
|
+
rubygems_version: 1.3.5
|
86
|
+
signing_key:
|
87
|
+
specification_version: 2
|
88
|
+
summary: Pure Ruby Phyisics Engine.
|
89
|
+
test_files: []
|
90
|
+
|