teien 0.0.1 → 0.0.2
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/bin/teien +3 -3
- data/lib/teien/animation_operator.rb +45 -45
- data/lib/teien/camera.rb +2 -2
- data/lib/teien/camera_mover.rb +43 -41
- data/lib/teien/garden.rb +7 -7
- data/lib/teien/garden_object.rb +50 -50
- data/lib/teien/light_object.rb +6 -6
- data/lib/teien/object_factory.rb +96 -90
- data/lib/teien/physics.rb +17 -17
- data/lib/teien/smooth_mover.rb +13 -13
- data/lib/teien/ui_listener.rb +14 -14
- data/lib/teien/user_interface.rb +159 -159
- data/lib/teien/version.rb +1 -1
- data/lib/teien/view.rb +58 -58
- data/lib/teien.rb +6 -6
- metadata +8 -8
data/lib/teien/garden_object.rb
CHANGED
@@ -41,7 +41,7 @@ class GardenObject < Bullet::BtMotionState
|
|
41
41
|
|
42
42
|
@rigid_body = nil
|
43
43
|
@transform = Bullet::BtTransform.new()
|
44
|
-
@transform.
|
44
|
+
@transform.set_identity()
|
45
45
|
@acceleration = Vector3D.new(0, 0, 0)
|
46
46
|
|
47
47
|
@maxHorizontalVelocity = 0
|
@@ -53,12 +53,12 @@ class GardenObject < Bullet::BtMotionState
|
|
53
53
|
#
|
54
54
|
def create_scene_node(entity, offset = Vector3D.new(0, 0, 0), rotate = Quaternion.new(0, 0, 0, 1.0))
|
55
55
|
if (@pivot_scene_node == nil)
|
56
|
-
@pivot_scene_node = @garden.view.scene_mgr.
|
56
|
+
@pivot_scene_node = @garden.view.scene_mgr.get_root_scene_node().create_child_scene_node()
|
57
57
|
end
|
58
|
-
@scene_node = @pivot_scene_node.
|
58
|
+
@scene_node = @pivot_scene_node.create_child_scene_node(Vector3D.to_ogre(offset), Quaternion.to_ogre(rotate))
|
59
59
|
@pivot_scene_node.instance_variable_set(:@child, @scene_node) # prevent this from GC.
|
60
60
|
if entity
|
61
|
-
@scene_node.
|
61
|
+
@scene_node.attach_object(entity)
|
62
62
|
@entity = entity
|
63
63
|
end
|
64
64
|
return @scene_node
|
@@ -71,9 +71,9 @@ class GardenObject < Bullet::BtMotionState
|
|
71
71
|
# puts "offset(#{offset.x}, #{offset.y}, #{offset.z})"
|
72
72
|
@pivot_shape = Bullet::BtCompoundShape.new
|
73
73
|
localTrans = Bullet::BtTransform.new
|
74
|
-
localTrans.
|
75
|
-
localTrans.
|
76
|
-
@pivot_shape.
|
74
|
+
localTrans.set_identity()
|
75
|
+
localTrans.set_origin(offset)
|
76
|
+
@pivot_shape.add_child_shape(localTrans, shape)
|
77
77
|
@shape = shape
|
78
78
|
@rigid_body = @garden.physics.create_rigid_body(mass, self, @pivot_shape, inertia)
|
79
79
|
end
|
@@ -83,7 +83,7 @@ class GardenObject < Bullet::BtMotionState
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def set_activation_state(state)
|
86
|
-
@rigid_body.
|
86
|
+
@rigid_body.set_activation_state(state)
|
87
87
|
end
|
88
88
|
|
89
89
|
|
@@ -92,9 +92,9 @@ class GardenObject < Bullet::BtMotionState
|
|
92
92
|
# ==== Args
|
93
93
|
# [aPos: Vector3D]
|
94
94
|
def set_position(aPos)
|
95
|
-
@pivot_scene_node.
|
96
|
-
@transform.
|
97
|
-
@rigid_body.
|
95
|
+
@pivot_scene_node.set_position(aPos.x, aPos.y, aPos.z) unless @garden.is_server
|
96
|
+
@transform.set_origin(Bullet::BtVector3.new(aPos.x, aPos.y, aPos.z))
|
97
|
+
@rigid_body.set_center_of_mass_transform(@transform) if (@rigid_body != nil)
|
98
98
|
end
|
99
99
|
|
100
100
|
# Set a linear velocity.
|
@@ -103,7 +103,7 @@ class GardenObject < Bullet::BtMotionState
|
|
103
103
|
# [aVel: Vector3D]
|
104
104
|
def set_linear_velocity(aVel)
|
105
105
|
@rigid_body.activate(true)
|
106
|
-
@rigid_body.
|
106
|
+
@rigid_body.set_linear_velocity(aVel)
|
107
107
|
end
|
108
108
|
|
109
109
|
# Set an angular velocity.
|
@@ -111,7 +111,7 @@ class GardenObject < Bullet::BtMotionState
|
|
111
111
|
# ==== Args
|
112
112
|
# [vel: Vector3D]
|
113
113
|
def set_angular_velocity(vel)
|
114
|
-
@rigid_body.
|
114
|
+
@rigid_body.set_angular_velocity(vel)
|
115
115
|
end
|
116
116
|
|
117
117
|
# Set a max horizontal velocity.
|
@@ -136,22 +136,22 @@ class GardenObject < Bullet::BtMotionState
|
|
136
136
|
end
|
137
137
|
|
138
138
|
def set_gravity(grav)
|
139
|
-
@rigid_body.
|
139
|
+
@rigid_body.set_gravity(grav)
|
140
140
|
end
|
141
141
|
|
142
142
|
def set_rotation(quad)
|
143
|
-
transform = @rigid_body.
|
144
|
-
transform.
|
145
|
-
@rigid_body.
|
143
|
+
transform = @rigid_body.get_center_of_mass_transform()
|
144
|
+
transform.set_rotation(quad)
|
145
|
+
@rigid_body.set_center_of_mass_transform(transform)
|
146
146
|
end
|
147
147
|
|
148
148
|
def set_collision_filter(filter)
|
149
|
-
@garden.physics.dynamicsWorld.
|
150
|
-
@garden.physics.dynamicsWorld.
|
149
|
+
@garden.physics.dynamicsWorld.remove_rigid_body(@rigid_body)
|
150
|
+
@garden.physics.dynamicsWorld.add_rigid_body(@rigid_body, filter.group, filter.mask)
|
151
151
|
physics_info.collisionFilter = filter
|
152
152
|
end
|
153
153
|
|
154
|
-
def
|
154
|
+
def set_world_transform(worldTrans)
|
155
155
|
# puts "setWorldTransform"
|
156
156
|
|
157
157
|
if (@mode == MODE_FREE)
|
@@ -159,8 +159,8 @@ class GardenObject < Bullet::BtMotionState
|
|
159
159
|
# puts "origin(#{pos.x}, #{pos.y}, #{pos.z})"
|
160
160
|
|
161
161
|
@transform = Bullet::BtTransform.new(worldTrans)
|
162
|
-
newPos = @transform.
|
163
|
-
newRot = @transform.
|
162
|
+
newPos = @transform.get_origin()
|
163
|
+
newRot = @transform.get_rotation()
|
164
164
|
# puts "newRot(#{id}: #{newRot.x}, #{newRot.y}, #{newRot.z}, #{newRot.w})"
|
165
165
|
# puts "newPos(#{id}: #{newPos.x}, #{newPos.y}, #{newPos.z})"
|
166
166
|
|
@@ -169,43 +169,43 @@ class GardenObject < Bullet::BtMotionState
|
|
169
169
|
end
|
170
170
|
|
171
171
|
unless @garden.is_server
|
172
|
-
@pivot_scene_node.
|
173
|
-
@pivot_scene_node.
|
172
|
+
@pivot_scene_node.set_position(newPos.x, newPos.y, newPos.z)
|
173
|
+
@pivot_scene_node.set_orientation(newRot.w, newRot.x, newRot.y, newRot.z)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
-
def
|
178
|
+
def get_world_transform(worldTrans)
|
179
179
|
# puts "getWorldTransform"
|
180
180
|
end
|
181
181
|
|
182
182
|
def get_activation_state()
|
183
|
-
@rigid_body.
|
183
|
+
@rigid_body.get_activation_state()
|
184
184
|
end
|
185
185
|
|
186
186
|
def get_mass()
|
187
|
-
return 1.0 / @rigid_body.
|
187
|
+
return 1.0 / @rigid_body.get_inv_mass()
|
188
188
|
end
|
189
189
|
|
190
190
|
def get_inv_mass()
|
191
|
-
return @rigid_body.
|
191
|
+
return @rigid_body.get_inv_mass()
|
192
192
|
end
|
193
193
|
|
194
194
|
def get_collision_mask()
|
195
|
-
@rigid_body.
|
195
|
+
@rigid_body.get_broadphase_handle().m_collisionFilterMask
|
196
196
|
end
|
197
197
|
|
198
198
|
def get_position()
|
199
|
-
newPos = @transform.
|
199
|
+
newPos = @transform.get_origin()
|
200
200
|
return newPos
|
201
201
|
end
|
202
202
|
|
203
203
|
def get_linear_velocity()
|
204
|
-
return @rigid_body.
|
204
|
+
return @rigid_body.get_linear_velocity()
|
205
205
|
end
|
206
206
|
|
207
207
|
def get_angular_velocity()
|
208
|
-
return @rigid_body.
|
208
|
+
return @rigid_body.get_angular_velocity()
|
209
209
|
end
|
210
210
|
|
211
211
|
def get_acceleration()
|
@@ -213,15 +213,15 @@ class GardenObject < Bullet::BtMotionState
|
|
213
213
|
end
|
214
214
|
|
215
215
|
def get_gravity()
|
216
|
-
return @rigid_body.
|
216
|
+
return @rigid_body.get_gravity()
|
217
217
|
end
|
218
218
|
|
219
219
|
def get_rotation()
|
220
|
-
return @transform.
|
220
|
+
return @transform.get_rotation()
|
221
221
|
end
|
222
222
|
|
223
223
|
def get_orientation()
|
224
|
-
return @transform.
|
224
|
+
return @transform.get_rotation()
|
225
225
|
end
|
226
226
|
|
227
227
|
def limit_velocity(vel)
|
@@ -245,7 +245,7 @@ class GardenObject < Bullet::BtMotionState
|
|
245
245
|
|
246
246
|
def apply_impulse(imp, rel = Vector3D.new(0, 0, 0))
|
247
247
|
@rigid_body.activate(true)
|
248
|
-
@rigid_body.
|
248
|
+
@rigid_body.apply_impulse(imp, rel)
|
249
249
|
end
|
250
250
|
|
251
251
|
#
|
@@ -260,32 +260,32 @@ class GardenObject < Bullet::BtMotionState
|
|
260
260
|
qnorm = Quaternion.new()
|
261
261
|
qnorm.copy(quat)
|
262
262
|
qnorm.normalize()
|
263
|
-
transform = @rigid_body.
|
264
|
-
curRot = transform.
|
263
|
+
transform = @rigid_body.get_center_of_mass_transform()
|
264
|
+
curRot = transform.get_rotation()
|
265
265
|
newRot = curRot * qnorm
|
266
|
-
transform.
|
267
|
-
@rigid_body.
|
266
|
+
transform.set_rotation(newRot)
|
267
|
+
@rigid_body.set_center_of_mass_transform(transform)
|
268
268
|
|
269
|
-
@pivot_scene_node.
|
269
|
+
@pivot_scene_node.set_orientation(Quaternion.to_ogre(newRot)) unless @garden.is_server
|
270
270
|
end
|
271
271
|
|
272
272
|
def attach_object_to_bone(boneName, obj)
|
273
|
-
obj.scene_node.
|
274
|
-
tag = @entity.
|
275
|
-
@garden.physics.dynamics_world.
|
273
|
+
obj.scene_node.detach_object(obj.entity)
|
274
|
+
tag = @entity.attach_object_to_bone(boneName, obj.entity)
|
275
|
+
@garden.physics.dynamics_world.remove_rigid_body(obj.rigid_body)
|
276
276
|
obj.mode = MODE_ATTACHED
|
277
277
|
return tag
|
278
278
|
end
|
279
279
|
|
280
280
|
def detach_object_from_bone(obj)
|
281
|
-
@entity.
|
282
|
-
obj.scene_node.
|
281
|
+
@entity.detach_object_from_bone(obj.entity)
|
282
|
+
obj.scene_node.attach_object(obj.entity)
|
283
283
|
if obj.physics_info.collisionFilter
|
284
|
-
@garden.physics.dynamics_world.
|
285
|
-
|
286
|
-
|
284
|
+
@garden.physics.dynamics_world.add_rigid_body(obj.rigid_body,
|
285
|
+
obj.physics_info.collisionFilter.group,
|
286
|
+
obj.physics_info.collisionFilter.mask)
|
287
287
|
else
|
288
|
-
@garden.physics.dynamics_world.
|
288
|
+
@garden.physics.dynamics_world.add_rigid_body(obj.rigid_body)
|
289
289
|
end
|
290
290
|
obj.mode = MODE_FREE
|
291
291
|
end
|
data/lib/teien/light_object.rb
CHANGED
@@ -11,26 +11,26 @@ class LightObject
|
|
11
11
|
def initialize(garden, name)
|
12
12
|
@garden = garden
|
13
13
|
@name = name
|
14
|
-
@light = @garden.view.scene_mgr.
|
14
|
+
@light = @garden.view.scene_mgr.create_light(@name);
|
15
15
|
end
|
16
16
|
|
17
17
|
def set_type(type)
|
18
|
-
@light.
|
18
|
+
@light.set_type(type)
|
19
19
|
end
|
20
20
|
|
21
21
|
def set_diffuse_color(color)
|
22
|
-
@light.
|
22
|
+
@light.set_diffuse_colour(color);
|
23
23
|
end
|
24
24
|
|
25
25
|
def set_specular_color(color)
|
26
|
-
@light.
|
26
|
+
@light.set_specular_colour(color)
|
27
27
|
end
|
28
28
|
|
29
29
|
def set_position(vec)
|
30
|
-
@light.
|
30
|
+
@light.set_position(Vector3D.to_ogre(vec));
|
31
31
|
end
|
32
32
|
|
33
33
|
def set_direction(vec)
|
34
|
-
@light.
|
34
|
+
@light.set_direction(Vector3D.to_ogre(vec));
|
35
35
|
end
|
36
36
|
end
|
data/lib/teien/object_factory.rb
CHANGED
@@ -42,7 +42,7 @@ class ObjectFactory
|
|
42
42
|
# Setting an entity and a node of Ogre3d.
|
43
43
|
normal = Ogre::Vector3.new(0, 1, 0)
|
44
44
|
up = Ogre::Vector3.new(0, 0, 1)
|
45
|
-
Ogre::MeshManager::
|
45
|
+
Ogre::MeshManager::get_singleton().create_plane(name,
|
46
46
|
Ogre::ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
|
47
47
|
Ogre::Plane.new(normal, 0),
|
48
48
|
object_info.width * 2.0,
|
@@ -52,19 +52,19 @@ class ObjectFactory
|
|
52
52
|
true, 1,
|
53
53
|
object_info.u_tile,
|
54
54
|
object_info.v_tile, up)
|
55
|
-
entity = @garden.view.scene_mgr.
|
56
|
-
entity.
|
57
|
-
entity.
|
55
|
+
entity = @garden.view.scene_mgr.create_entity(name, name)
|
56
|
+
entity.set_cast_shadows(true)
|
57
|
+
entity.set_material_name(object_info.material_name)
|
58
58
|
node = obj.create_scene_node(entity)
|
59
59
|
end
|
60
60
|
|
61
61
|
# Setting a collision shape and rigid body of Bullet.
|
62
62
|
cShape = Bullet::BtBoxShape.new(Vector3D.new(object_info.width, object_info.depth, object_info.height))
|
63
63
|
rb = obj.create_rigid_body(0, cShape, Vector3D.new(0, 0, 0), Vector3D.new(0.0, -object_info.depth, 0.0))
|
64
|
-
rb.
|
65
|
-
rb.
|
66
|
-
rb.
|
67
|
-
rb.
|
64
|
+
rb.set_angular_factor(physics_info.angular_factor)
|
65
|
+
rb.set_restitution(physics_info.restitution)
|
66
|
+
rb.set_friction(physics_info.friction)
|
67
|
+
rb.set_damping(physics_info.linear_damping, physics_info.angular_damping)
|
68
68
|
|
69
69
|
@garden.add_object(obj)
|
70
70
|
|
@@ -79,23 +79,27 @@ class ObjectFactory
|
|
79
79
|
|
80
80
|
unless @garden.is_server
|
81
81
|
gen = Procedural::BoxGenerator.new()
|
82
|
-
gen.
|
83
|
-
gen.
|
84
|
-
gen.
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
gen.set_size_x(object_info.size.x * 2.0)
|
83
|
+
gen.set_size_y(object_info.size.y * 2.0)
|
84
|
+
gen.set_size_z(object_info.size.z * 2.0)
|
85
|
+
gen.set_num_seg_x(object_info.num_seg_x)
|
86
|
+
gen.set_num_seg_y(object_info.num_seg_y)
|
87
|
+
gen.set_num_seg_z(object_info.num_seg_z)
|
88
|
+
gen.set_utile(object_info.u_tile).set_vtile(object_info.v_tile).realize_mesh(name)
|
89
|
+
entity = @garden.view.scene_mgr.create_entity(name)
|
90
|
+
entity.set_cast_shadows(true)
|
91
|
+
entity.set_material_name(object_info.material_name)
|
88
92
|
node = obj.create_scene_node(entity)
|
89
93
|
end
|
90
94
|
|
91
95
|
cShape = Bullet::BtBoxShape.new(Vector3D.new(object_info.size.x, object_info.size.y, object_info.size.z))
|
92
96
|
inertia = Bullet::BtVector3.new()
|
93
|
-
cShape.
|
97
|
+
cShape.calculate_local_inertia(physics_info.mass, inertia)
|
94
98
|
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia)
|
95
|
-
rb.
|
96
|
-
rb.
|
97
|
-
rb.
|
98
|
-
rb.
|
99
|
+
rb.set_angular_factor(physics_info.angular_factor)
|
100
|
+
rb.set_restitution(physics_info.restitution)
|
101
|
+
rb.set_friction(physics_info.friction)
|
102
|
+
rb.set_damping(physics_info.linear_damping, physics_info.angular_damping)
|
99
103
|
|
100
104
|
|
101
105
|
@garden.add_object(obj)
|
@@ -111,24 +115,24 @@ class ObjectFactory
|
|
111
115
|
|
112
116
|
unless @garden.is_server
|
113
117
|
gen = Procedural::SphereGenerator.new()
|
114
|
-
gen.
|
115
|
-
gen.
|
116
|
-
gen.
|
117
|
-
gen.
|
118
|
-
entity = @garden.view.scene_mgr.
|
119
|
-
entity.
|
120
|
-
entity.
|
118
|
+
gen.set_radius(object_info.radius)
|
119
|
+
gen.set_num_rings(object_info.num_rings)
|
120
|
+
gen.set_num_segments(object_info.num_segments)
|
121
|
+
gen.set_vtile(object_info.u_tile).set_vtile(object_info.v_tile).realize_mesh(name)
|
122
|
+
entity = @garden.view.scene_mgr.create_entity(name)
|
123
|
+
entity.set_cast_shadows(true)
|
124
|
+
entity.set_material_name(object_info.material_name)
|
121
125
|
node = obj.create_scene_node(entity)
|
122
126
|
end
|
123
127
|
|
124
128
|
cShape = Bullet::BtSphereShape.new(object_info.radius)
|
125
129
|
inertia = Bullet::BtVector3.new()
|
126
|
-
cShape.
|
130
|
+
cShape.calculate_local_inertia(physics_info.mass, inertia)
|
127
131
|
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia)
|
128
|
-
rb.
|
129
|
-
rb.
|
130
|
-
rb.
|
131
|
-
rb.
|
132
|
+
rb.set_angular_factor(physics_info.angular_factor)
|
133
|
+
rb.set_restitution(physics_info.restitution)
|
134
|
+
rb.set_friction(physics_info.friction)
|
135
|
+
rb.set_damping(physics_info.linear_damping, physics_info.angular_damping)
|
132
136
|
|
133
137
|
|
134
138
|
@garden.add_object(obj)
|
@@ -144,23 +148,25 @@ class ObjectFactory
|
|
144
148
|
|
145
149
|
unless @garden.is_server
|
146
150
|
gen = Procedural::CapsuleGenerator.new()
|
147
|
-
gen.
|
148
|
-
gen.
|
149
|
-
gen.
|
150
|
-
|
151
|
-
|
152
|
-
entity.
|
151
|
+
gen.set_radius(object_info.radius).set_height(object_info.height)
|
152
|
+
gen.set_num_rings(object_info.num_rings)
|
153
|
+
gen.set_num_segments(object_info.num_segments)
|
154
|
+
gen.set_num_seg_height(object_info.num_seg_height)
|
155
|
+
gen.set_vtile(object_info.u_tile).set_vtile(object_info.v_tile).realize_mesh(name)
|
156
|
+
entity = @garden.view.scene_mgr.create_entity(name)
|
157
|
+
entity.set_cast_shadows(true)
|
158
|
+
entity.set_material_name(object_info.material_name)
|
153
159
|
node = obj.create_scene_node(entity)
|
154
160
|
end
|
155
161
|
|
156
162
|
cShape = Bullet::BtCapsuleShape.new(object_info.radius, object_info.height)
|
157
163
|
inertia = Bullet::BtVector3.new()
|
158
|
-
cShape.
|
164
|
+
cShape.calculate_local_inertia(physics_info.mass, inertia)
|
159
165
|
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia)
|
160
|
-
rb.
|
161
|
-
rb.
|
162
|
-
rb.
|
163
|
-
rb.
|
166
|
+
rb.set_angular_factor(physics_info.angular_factor)
|
167
|
+
rb.set_restitution(physics_info.restitution)
|
168
|
+
rb.set_friction(physics_info.friction)
|
169
|
+
rb.set_damping(physics_info.linear_damping, physics_info.angular_damping)
|
164
170
|
|
165
171
|
|
166
172
|
@garden.add_object(obj)
|
@@ -176,23 +182,23 @@ class ObjectFactory
|
|
176
182
|
|
177
183
|
unless @garden.is_server
|
178
184
|
gen = Procedural::ConeGenerator.new
|
179
|
-
gen.
|
180
|
-
gen.
|
181
|
-
gen.
|
182
|
-
entity = @garden.view.scene_mgr.
|
183
|
-
entity.
|
184
|
-
entity.
|
185
|
+
gen.set_radius(object_info.radius).set_height(object_info.height)
|
186
|
+
gen.set_num_seg_base(object_info.num_seg_base).set_num_seg_height(object_info.num_seg_height)
|
187
|
+
gen.set_utile(object_info.u_tile).set_vtile(object_info.v_tile).realize_mesh(name)
|
188
|
+
entity = @garden.view.scene_mgr.create_entity(name)
|
189
|
+
entity.set_cast_shadows(true)
|
190
|
+
entity.set_material_name(object_info.material_name)
|
185
191
|
node = obj.create_scene_node(entity)
|
186
192
|
end
|
187
193
|
|
188
194
|
cShape = Bullet::BtConeShape.new(object_info.radius, object_info.height)
|
189
195
|
inertia = Bullet::BtVector3.new()
|
190
|
-
cShape.
|
196
|
+
cShape.calculate_local_inertia(physics_info.mass, inertia)
|
191
197
|
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia, Vector3D.new(0, object_info.height / 2, 0))
|
192
|
-
rb.
|
193
|
-
rb.
|
194
|
-
rb.
|
195
|
-
rb.
|
198
|
+
rb.set_angular_factor(physics_info.angular_factor)
|
199
|
+
rb.set_restitution(physics_info.restitution)
|
200
|
+
rb.set_friction(physics_info.friction)
|
201
|
+
rb.set_damping(physics_info.linear_damping, physics_info.angular_damping)
|
196
202
|
|
197
203
|
|
198
204
|
@garden.add_object(obj)
|
@@ -208,12 +214,12 @@ class ObjectFactory
|
|
208
214
|
|
209
215
|
unless @garden.is_server
|
210
216
|
gen = Procedural::CylinderGenerator.new
|
211
|
-
gen.
|
212
|
-
gen.
|
213
|
-
gen.
|
214
|
-
entity = @garden.view.scene_mgr.
|
215
|
-
entity.
|
216
|
-
entity.
|
217
|
+
gen.set_radius(object_info.radius).set_height(object_info.height).set_capped(object_info.capped)
|
218
|
+
gen.set_num_seg_base(object_info.num_seg_base).set_num_seg_height(object_info.num_seg_height)
|
219
|
+
gen.set_utile(object_info.u_tile).set_vtile(object_info.v_tile).realize_mesh(name)
|
220
|
+
entity = @garden.view.scene_mgr.create_entity(name)
|
221
|
+
entity.set_cast_shadows(true)
|
222
|
+
entity.set_material_name(object_info.material_name)
|
217
223
|
node = obj.create_scene_node(entity, Vector3D.new(0, -object_info.height / 2, 0))
|
218
224
|
end
|
219
225
|
|
@@ -221,12 +227,12 @@ class ObjectFactory
|
|
221
227
|
object_info.height / 2,
|
222
228
|
object_info.radius))
|
223
229
|
inertia = Bullet::BtVector3.new()
|
224
|
-
cShape.
|
230
|
+
cShape.calculate_local_inertia(physics_info.mass, inertia)
|
225
231
|
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia)
|
226
|
-
rb.
|
227
|
-
rb.
|
228
|
-
rb.
|
229
|
-
rb.
|
232
|
+
rb.set_angular_factor(physics_info.angular_factor)
|
233
|
+
rb.set_restitution(physics_info.restitution)
|
234
|
+
rb.set_friction(physics_info.friction)
|
235
|
+
rb.set_damping(physics_info.linear_damping, physics_info.angular_damping)
|
230
236
|
|
231
237
|
@garden.add_object(obj)
|
232
238
|
|
@@ -240,23 +246,23 @@ class ObjectFactory
|
|
240
246
|
obj.physics_info = physics_info
|
241
247
|
|
242
248
|
unless @garden.is_server
|
243
|
-
entity = @garden.view.scene_mgr.
|
244
|
-
entity.
|
245
|
-
entity.
|
249
|
+
entity = @garden.view.scene_mgr.create_entity(name, object_info.mesh_path)
|
250
|
+
entity.set_cast_shadows(true)
|
251
|
+
entity.set_material_name(object_info.material_name) if object_info.material_name
|
246
252
|
node = obj.create_scene_node(entity, object_info.view_offset, object_info.view_rotation)
|
247
|
-
node.
|
248
|
-
|
249
|
-
|
253
|
+
node.set_scale(object_info.size.x * object_info.scale.x,
|
254
|
+
object_info.size.y * object_info.scale.y,
|
255
|
+
object_info.size.z * object_info.scale.z)
|
250
256
|
end
|
251
257
|
|
252
258
|
cShape = Bullet::BtBoxShape.new(object_info.size)
|
253
259
|
inertia = Bullet::BtVector3.new()
|
254
|
-
cShape.
|
260
|
+
cShape.calculate_local_inertia(physics_info.mass, inertia)
|
255
261
|
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia, object_info.physics_offset)
|
256
|
-
rb.
|
257
|
-
rb.
|
258
|
-
rb.
|
259
|
-
rb.
|
262
|
+
rb.set_angular_factor(physics_info.angular_factor)
|
263
|
+
rb.set_restitution(physics_info.restitution)
|
264
|
+
rb.set_friction(physics_info.friction)
|
265
|
+
rb.set_damping(physics_info.linear_damping, physics_info.angular_damping)
|
260
266
|
|
261
267
|
@garden.add_object(obj)
|
262
268
|
|
@@ -270,26 +276,26 @@ class ObjectFactory
|
|
270
276
|
obj.physics_info = physics_info
|
271
277
|
|
272
278
|
unless @garden.is_server
|
273
|
-
entity = @garden.view.scene_mgr.
|
274
|
-
entity.
|
275
|
-
entity.
|
279
|
+
entity = @garden.view.scene_mgr.create_entity(name, object_info.mesh_path)
|
280
|
+
entity.set_cast_shadows(true)
|
281
|
+
entity.set_material_name(object_info.material_name) if object_info.material_name
|
276
282
|
node = obj.create_scene_node(entity, object_info.view_offset)
|
277
|
-
node.
|
278
|
-
strider = Teienlib::MeshStrider.new(entity.
|
283
|
+
node.set_scale(object_info.scale.x, object_info.scale.y, object_info.scale.z)
|
284
|
+
strider = Teienlib::MeshStrider.new(entity.get_mesh().get())
|
279
285
|
cShape = Bullet::BtGImpactMeshShape.new(strider)
|
280
|
-
cShape.
|
281
|
-
|
282
|
-
|
286
|
+
cShape.set_local_scaling(Bullet::BtVector3.new(object_info.scale.x,
|
287
|
+
object_info.scale.y,
|
288
|
+
object_info.scale.z))
|
283
289
|
cShape.instance_variable_set(:@strider, strider) # prevent this from GC.
|
284
|
-
cShape.
|
285
|
-
cShape.
|
290
|
+
cShape.post_update()
|
291
|
+
cShape.update_bound()
|
286
292
|
inertia = Bullet::BtVector3.new()
|
287
|
-
cShape.
|
293
|
+
cShape.calculate_local_inertia(physics_info.mass, inertia)
|
288
294
|
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia, object_info.physics_offset)
|
289
|
-
rb.
|
290
|
-
rb.
|
291
|
-
rb.
|
292
|
-
rb.
|
295
|
+
rb.set_angular_factor(physics_info.angular_factor)
|
296
|
+
rb.set_restitution(physics_info.restitution)
|
297
|
+
rb.set_friction(physics_info.friction)
|
298
|
+
rb.set_damping(physics_info.linear_damping, physics_info.angular_damping)
|
293
299
|
end
|
294
300
|
|
295
301
|
@garden.add_object(obj)
|
data/lib/teien/physics.rb
CHANGED
@@ -12,9 +12,9 @@ class ContactResult < Bullet::ContactResultCallback
|
|
12
12
|
return @isCollided
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
15
|
+
def add_single_result(cp,
|
16
|
+
colObj0, partId0, index0,
|
17
|
+
colObj1, partId1, index1)
|
18
18
|
@isCollided = true
|
19
19
|
return 0
|
20
20
|
end
|
@@ -51,10 +51,10 @@ class Physics < Bullet::TickListener
|
|
51
51
|
@dynamics_world = Bullet::BtDiscreteDynamicsWorld.new(@collision_dispatcher, @aabb_cache,
|
52
52
|
@solver, @collision_config)
|
53
53
|
gravity = Bullet::BtVector3.new(0.0, -9.8, 0.0)
|
54
|
-
@dynamics_world.
|
54
|
+
@dynamics_world.set_gravity(gravity)
|
55
55
|
|
56
|
-
@dynamics_world.
|
57
|
-
@dynamics_world.
|
56
|
+
@dynamics_world.set_internal_tick_callback(self, true);
|
57
|
+
@dynamics_world.set_internal_tick_callback(self, false);
|
58
58
|
=begin
|
59
59
|
worldAabbCache->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
|
60
60
|
=end
|
@@ -70,7 +70,7 @@ class Physics < Bullet::TickListener
|
|
70
70
|
def finalize
|
71
71
|
# clear all objects.
|
72
72
|
@rigid_bodies.each{|body|
|
73
|
-
@dynamics_world.
|
73
|
+
@dynamics_world.remove_rigid_body(body)
|
74
74
|
}
|
75
75
|
@rigid_bodies = []
|
76
76
|
|
@@ -78,24 +78,24 @@ class Physics < Bullet::TickListener
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def update(delta)
|
81
|
-
@dynamics_world.
|
81
|
+
@dynamics_world.step_simulation(delta, @max_sub_steps, @fixed_time_step)
|
82
82
|
return true
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
85
|
+
def frame_rendering_queued(evt)
|
86
86
|
# print "Physics::tick: ", evt.timeSinceLastFrame * 1000, "ms\n"
|
87
|
-
@dynamics_world.
|
87
|
+
@dynamics_world.step_simulation(evt.timeSinceLastFrame, @max_sub_steps, @fixed_time_step)
|
88
88
|
return true
|
89
89
|
end
|
90
90
|
|
91
91
|
def flush_pair_cache(rigid_body)
|
92
|
-
pair_cache = @dynamics_world.
|
93
|
-
pair_cache.
|
94
|
-
|
92
|
+
pair_cache = @dynamics_world.get_broadphase().get_overlapping_pair_cache()
|
93
|
+
pair_cache.remove_overlapping_pairs_containing_proxy(rigid_body.get_broadphase_handle(),
|
94
|
+
@dynamics_world.get_dispatcher())
|
95
95
|
end
|
96
96
|
|
97
97
|
def set_gravity(vec)
|
98
|
-
@dynamics_world.
|
98
|
+
@dynamics_world.set_gravity(vec)
|
99
99
|
end
|
100
100
|
|
101
101
|
=begin
|
@@ -117,15 +117,15 @@ class Physics < Bullet::TickListener
|
|
117
117
|
def add_rigid_body(rigid_body, collision_filter = nil)
|
118
118
|
@rigid_bodies.push(rigid_body)
|
119
119
|
if (collision_filter)
|
120
|
-
@dynamics_world.
|
120
|
+
@dynamics_world.add_rigid_body(rigid_body, collision_filter.group, collision_filter.mask)
|
121
121
|
else
|
122
|
-
@dynamics_world.
|
122
|
+
@dynamics_world.add_rigid_body(rigid_body)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
def contact_pair_test(colObjA, colObjB)
|
127
127
|
result = ContactResult.new
|
128
|
-
@dynamics_world.
|
128
|
+
@dynamics_world.contact_pair_test(colObjA, colObjB, result)
|
129
129
|
return result
|
130
130
|
end
|
131
131
|
|