teien 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/bin/teien +49 -0
- data/lib/teien/animation_operator.rb +142 -0
- data/lib/teien/camera.rb +25 -0
- data/lib/teien/camera_mover.rb +193 -0
- data/lib/teien/garden.rb +203 -0
- data/lib/teien/garden_object.rb +314 -0
- data/lib/teien/light_object.rb +36 -0
- data/lib/teien/object_factory.rb +302 -0
- data/lib/teien/object_info.rb +171 -0
- data/lib/teien/physics.rb +150 -0
- data/lib/teien/physics_info.rb +23 -0
- data/lib/teien/smooth_mover.rb +108 -0
- data/lib/teien/tools.rb +261 -0
- data/lib/teien/ui_listener.rb +68 -0
- data/lib/teien/user_interface.rb +201 -0
- data/lib/teien/version.rb +3 -0
- data/lib/teien/view.rb +244 -0
- data/lib/teien.rb +40 -0
- data/sample/standalone/hello_garden/hello_garden.rb +155 -0
- data/sample/standalone/hello_garden/plugins.cfg +17 -0
- data/sample/standalone/hello_garden/resources.cfg +21 -0
- data/sample/standalone/hello_garden/run +5 -0
- data/teien.gemspec +22 -0
- metadata +107 -0
@@ -0,0 +1,314 @@
|
|
1
|
+
require "teien/tools.rb"
|
2
|
+
require "teien/animation_operator.rb"
|
3
|
+
|
4
|
+
module Teien
|
5
|
+
|
6
|
+
#
|
7
|
+
# GardenObject has a rigidBody(bullet physics), an entity and a sceneNode(ogre3d view).
|
8
|
+
#
|
9
|
+
class GardenObject < Bullet::BtMotionState
|
10
|
+
# object ID
|
11
|
+
attr_accessor :id
|
12
|
+
attr_accessor :name
|
13
|
+
attr_accessor :mode
|
14
|
+
|
15
|
+
attr_accessor :object_info
|
16
|
+
attr_accessor :physics_info
|
17
|
+
|
18
|
+
# Bullet accessor
|
19
|
+
attr_accessor :rigid_body # shows the center of this object.
|
20
|
+
attr_accessor :pivot_shape
|
21
|
+
attr_accessor :shape
|
22
|
+
|
23
|
+
# Ogre3D accessor
|
24
|
+
## center of view objects(sceneNode) and kept to equal with the rigid_body position.
|
25
|
+
attr_accessor :pivot_scene_node
|
26
|
+
attr_accessor :scene_node
|
27
|
+
attr_accessor :entity
|
28
|
+
|
29
|
+
MODE_FREE = 0
|
30
|
+
MODE_ATTACHED = 1
|
31
|
+
|
32
|
+
def initialize(garden)
|
33
|
+
super()
|
34
|
+
@id = -1
|
35
|
+
@garden = garden
|
36
|
+
@mode = MODE_FREE
|
37
|
+
|
38
|
+
@pivot_scene_node = nil
|
39
|
+
@scene_node = nil
|
40
|
+
@entity = nil
|
41
|
+
|
42
|
+
@rigid_body = nil
|
43
|
+
@transform = Bullet::BtTransform.new()
|
44
|
+
@transform.setIdentity()
|
45
|
+
@acceleration = Vector3D.new(0, 0, 0)
|
46
|
+
|
47
|
+
@maxHorizontalVelocity = 0
|
48
|
+
@maxVerticalVelocity = 0
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# The offset changes the local position of the created scene_node in Object.
|
53
|
+
#
|
54
|
+
def create_scene_node(entity, offset = Vector3D.new(0, 0, 0), rotate = Quaternion.new(0, 0, 0, 1.0))
|
55
|
+
if (@pivot_scene_node == nil)
|
56
|
+
@pivot_scene_node = @garden.view.scene_mgr.getRootSceneNode().createChildSceneNode()
|
57
|
+
end
|
58
|
+
@scene_node = @pivot_scene_node.createChildSceneNode(Vector3D.to_ogre(offset), Quaternion.to_ogre(rotate))
|
59
|
+
@pivot_scene_node.instance_variable_set(:@child, @scene_node) # prevent this from GC.
|
60
|
+
if entity
|
61
|
+
@scene_node.attachObject(entity)
|
62
|
+
@entity = entity
|
63
|
+
end
|
64
|
+
return @scene_node
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# The offset changes the local position of the shape(collision shape) in Object.
|
69
|
+
#
|
70
|
+
def create_rigid_body(mass, shape, inertia, offset = Vector3D.new(0, 0, 0))
|
71
|
+
# puts "offset(#{offset.x}, #{offset.y}, #{offset.z})"
|
72
|
+
@pivot_shape = Bullet::BtCompoundShape.new
|
73
|
+
localTrans = Bullet::BtTransform.new
|
74
|
+
localTrans.setIdentity()
|
75
|
+
localTrans.setOrigin(offset)
|
76
|
+
@pivot_shape.addChildShape(localTrans, shape)
|
77
|
+
@shape = shape
|
78
|
+
@rigid_body = @garden.physics.create_rigid_body(mass, self, @pivot_shape, inertia)
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_animation_operator()
|
82
|
+
return AnimationOperator.new(@entity)
|
83
|
+
end
|
84
|
+
|
85
|
+
def set_activation_state(state)
|
86
|
+
@rigid_body.setActivationState(state)
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Set a position.
|
91
|
+
#
|
92
|
+
# ==== Args
|
93
|
+
# [aPos: Vector3D]
|
94
|
+
def set_position(aPos)
|
95
|
+
@pivot_scene_node.setPosition(aPos.x, aPos.y, aPos.z) unless @garden.is_server
|
96
|
+
@transform.setOrigin(Bullet::BtVector3.new(aPos.x, aPos.y, aPos.z))
|
97
|
+
@rigid_body.setCenterOfMassTransform(@transform) if (@rigid_body != nil)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Set a linear velocity.
|
101
|
+
#
|
102
|
+
# ==== Args
|
103
|
+
# [aVel: Vector3D]
|
104
|
+
def set_linear_velocity(aVel)
|
105
|
+
@rigid_body.activate(true)
|
106
|
+
@rigid_body.setLinearVelocity(aVel)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Set an angular velocity.
|
110
|
+
#
|
111
|
+
# ==== Args
|
112
|
+
# [vel: Vector3D]
|
113
|
+
def set_angular_velocity(vel)
|
114
|
+
@rigid_body.setAngularVelocity(vel)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Set a max horizontal velocity.
|
118
|
+
#
|
119
|
+
# ==== Args
|
120
|
+
# [vel: Vector3D] vel is the max velocity. 0 means there is no limit.
|
121
|
+
def set_max_horizontal_velocity(vel_len)
|
122
|
+
@maxHorizontalVelocity = vel_len
|
123
|
+
end
|
124
|
+
|
125
|
+
# Set a max vertical velocity.
|
126
|
+
#
|
127
|
+
# ==== Args
|
128
|
+
# [vel: Vector3D] vel is the max velocity. 0 means there is no limit.
|
129
|
+
def set_max_vertical_velocity(vel_le)
|
130
|
+
@maxVerticalVelocity = vel_len
|
131
|
+
end
|
132
|
+
|
133
|
+
# Set the object's acceleration.
|
134
|
+
def set_acceleration(acc)
|
135
|
+
@acceleration = acc
|
136
|
+
end
|
137
|
+
|
138
|
+
def set_gravity(grav)
|
139
|
+
@rigid_body.setGravity(grav)
|
140
|
+
end
|
141
|
+
|
142
|
+
def set_rotation(quad)
|
143
|
+
transform = @rigid_body.getCenterOfMassTransform()
|
144
|
+
transform.setRotation(quad)
|
145
|
+
@rigid_body.setCenterOfMassTransform(transform)
|
146
|
+
end
|
147
|
+
|
148
|
+
def set_collision_filter(filter)
|
149
|
+
@garden.physics.dynamicsWorld.removeRigidBody(@rigid_body)
|
150
|
+
@garden.physics.dynamicsWorld.addRigidBody(@rigid_body, filter.group, filter.mask)
|
151
|
+
physics_info.collisionFilter = filter
|
152
|
+
end
|
153
|
+
|
154
|
+
def setWorldTransform(worldTrans)
|
155
|
+
# puts "setWorldTransform"
|
156
|
+
|
157
|
+
if (@mode == MODE_FREE)
|
158
|
+
# pos = worldTrans.getOrigin()
|
159
|
+
# puts "origin(#{pos.x}, #{pos.y}, #{pos.z})"
|
160
|
+
|
161
|
+
@transform = Bullet::BtTransform.new(worldTrans)
|
162
|
+
newPos = @transform.getOrigin()
|
163
|
+
newRot = @transform.getRotation()
|
164
|
+
# puts "newRot(#{id}: #{newRot.x}, #{newRot.y}, #{newRot.z}, #{newRot.w})"
|
165
|
+
# puts "newPos(#{id}: #{newPos.x}, #{newPos.y}, #{newPos.z})"
|
166
|
+
|
167
|
+
if (newRot.x.nan?)
|
168
|
+
return
|
169
|
+
end
|
170
|
+
|
171
|
+
unless @garden.is_server
|
172
|
+
@pivot_scene_node.setPosition(newPos.x, newPos.y, newPos.z)
|
173
|
+
@pivot_scene_node.setOrientation(newRot.w, newRot.x, newRot.y, newRot.z)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def getWorldTransform(worldTrans)
|
179
|
+
# puts "getWorldTransform"
|
180
|
+
end
|
181
|
+
|
182
|
+
def get_activation_state()
|
183
|
+
@rigid_body.getActivationState()
|
184
|
+
end
|
185
|
+
|
186
|
+
def get_mass()
|
187
|
+
return 1.0 / @rigid_body.getInvMass()
|
188
|
+
end
|
189
|
+
|
190
|
+
def get_inv_mass()
|
191
|
+
return @rigid_body.getInvMass()
|
192
|
+
end
|
193
|
+
|
194
|
+
def get_collision_mask()
|
195
|
+
@rigid_body.getBroadphaseHandle().m_collisionFilterMask
|
196
|
+
end
|
197
|
+
|
198
|
+
def get_position()
|
199
|
+
newPos = @transform.getOrigin()
|
200
|
+
return newPos
|
201
|
+
end
|
202
|
+
|
203
|
+
def get_linear_velocity()
|
204
|
+
return @rigid_body.getLinearVelocity()
|
205
|
+
end
|
206
|
+
|
207
|
+
def get_angular_velocity()
|
208
|
+
return @rigid_body.getAngularVelocity()
|
209
|
+
end
|
210
|
+
|
211
|
+
def get_acceleration()
|
212
|
+
return @acceleration
|
213
|
+
end
|
214
|
+
|
215
|
+
def get_gravity()
|
216
|
+
return @rigid_body.getGravity()
|
217
|
+
end
|
218
|
+
|
219
|
+
def get_rotation()
|
220
|
+
return @transform.getRotation()
|
221
|
+
end
|
222
|
+
|
223
|
+
def get_orientation()
|
224
|
+
return @transform.getRotation()
|
225
|
+
end
|
226
|
+
|
227
|
+
def limit_velocity(vel)
|
228
|
+
newVel = Bullet::BtVector3.new(vel.x, vel.y, vel.z)
|
229
|
+
|
230
|
+
hLen = Math::sqrt(vel.x * vel.x + vel.z * vel.z)
|
231
|
+
if (@maxHorizontalVelocity != 0 && hLen > @maxHorizontalVelocity)
|
232
|
+
newVel.x = vel.x / hLen * @maxHorizontalVelocity
|
233
|
+
newVel.z = vel.z / hLen * @maxHorizontalVelocity
|
234
|
+
end
|
235
|
+
|
236
|
+
vLen = vel.y
|
237
|
+
if (@maxVerticalVelocity != 0 && vLen > @maxVerticalVelocity)
|
238
|
+
newVel.y = @maxVerticalVelocity
|
239
|
+
end
|
240
|
+
|
241
|
+
# puts "newVel: (#{newVel.x}, #{newVel.y}, #{newVel.z})"
|
242
|
+
|
243
|
+
return newVel
|
244
|
+
end
|
245
|
+
|
246
|
+
def apply_impulse(imp, rel = Vector3D.new(0, 0, 0))
|
247
|
+
@rigid_body.activate(true)
|
248
|
+
@rigid_body.applyImpulse(imp, rel)
|
249
|
+
end
|
250
|
+
|
251
|
+
#
|
252
|
+
# ====Args
|
253
|
+
# [angle : radians] angle around y-axis.
|
254
|
+
# def yaw(angle, relativeTo=Ogre::Node::TS_LOCAL)
|
255
|
+
def yaw(angle)
|
256
|
+
rotate(Quaternion.new(Vector3D.new(0, 1.0, 0), angle))
|
257
|
+
end
|
258
|
+
|
259
|
+
def rotate(quat)
|
260
|
+
qnorm = Quaternion.new()
|
261
|
+
qnorm.copy(quat)
|
262
|
+
qnorm.normalize()
|
263
|
+
transform = @rigid_body.getCenterOfMassTransform()
|
264
|
+
curRot = transform.getRotation()
|
265
|
+
newRot = curRot * qnorm
|
266
|
+
transform.setRotation(newRot)
|
267
|
+
@rigid_body.setCenterOfMassTransform(transform)
|
268
|
+
|
269
|
+
@pivot_scene_node.setOrientation(Quaternion.to_ogre(newRot)) unless @garden.is_server
|
270
|
+
end
|
271
|
+
|
272
|
+
def attach_object_to_bone(boneName, obj)
|
273
|
+
obj.scene_node.detachObject(obj.entity)
|
274
|
+
tag = @entity.attachObjectToBone(boneName, obj.entity)
|
275
|
+
@garden.physics.dynamics_world.removeRigidBody(obj.rigid_body)
|
276
|
+
obj.mode = MODE_ATTACHED
|
277
|
+
return tag
|
278
|
+
end
|
279
|
+
|
280
|
+
def detach_object_from_bone(obj)
|
281
|
+
@entity.detachObjectFromBone(obj.entity)
|
282
|
+
obj.scene_node.attachObject(obj.entity)
|
283
|
+
if obj.physics_info.collisionFilter
|
284
|
+
@garden.physics.dynamics_world.addRigidBody(obj.rigid_body,
|
285
|
+
obj.physics_info.collisionFilter.group,
|
286
|
+
obj.physics_info.collisionFilter.mask)
|
287
|
+
else
|
288
|
+
@garden.physics.dynamics_world.addRigidBody(obj.rigid_body)
|
289
|
+
end
|
290
|
+
obj.mode = MODE_FREE
|
291
|
+
end
|
292
|
+
|
293
|
+
def update(delta)
|
294
|
+
end
|
295
|
+
|
296
|
+
def pull()
|
297
|
+
pos = get_position()
|
298
|
+
return [@id, pos.x, pos.y, pos.z].pack("NNNN")
|
299
|
+
end
|
300
|
+
|
301
|
+
def push(packedData)
|
302
|
+
data = packedData.unpack("NNNN")
|
303
|
+
posX = data[1]
|
304
|
+
posY = data[2]
|
305
|
+
posZ = data[3]
|
306
|
+
|
307
|
+
puts "#{@id}: (#{posX}, #{posY}, #{posZ})"
|
308
|
+
|
309
|
+
set_position(Vector3D.new(posX, posY, posZ))
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
|
314
|
+
end # module
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "teien/tools.rb"
|
2
|
+
|
3
|
+
class LightObject
|
4
|
+
POINT = Ogre::Light::LT_POINT
|
5
|
+
DIRECTIONAL = Ogre::Light::LT_DIRECTIONAL
|
6
|
+
SPOTLIGHT = Ogre::Light::LT_SPOTLIGHT
|
7
|
+
|
8
|
+
attr_accessor :name
|
9
|
+
attr_accessor :light
|
10
|
+
|
11
|
+
def initialize(garden, name)
|
12
|
+
@garden = garden
|
13
|
+
@name = name
|
14
|
+
@light = @garden.view.scene_mgr.createLight(@name);
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_type(type)
|
18
|
+
@light.setType(type)
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_diffuse_color(color)
|
22
|
+
@light.setDiffuseColour(color);
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_specular_color(color)
|
26
|
+
@light.setSpecularColour(color)
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_position(vec)
|
30
|
+
@light.setPosition(Vector3D.to_ogre(vec));
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_direction(vec)
|
34
|
+
@light.setDirection(Vector3D.to_ogre(vec));
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,302 @@
|
|
1
|
+
require 'teien/garden_object'
|
2
|
+
|
3
|
+
module Teien
|
4
|
+
|
5
|
+
class ObjectFactory
|
6
|
+
def initialize(garden)
|
7
|
+
@garden = garden
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_object(name, object_info, physics_info)
|
11
|
+
case object_info
|
12
|
+
when FloorObjectInfo
|
13
|
+
return create_floor_object(name, object_info, physics_info)
|
14
|
+
when BoxObjectInfo
|
15
|
+
return create_box_object(name, object_info, physics_info)
|
16
|
+
when SphereObjectInfo
|
17
|
+
return create_sphere_object(name, object_info, physics_info)
|
18
|
+
when CapsuleObjectInfo
|
19
|
+
return create_capsule_object(name, object_info, physics_info)
|
20
|
+
when ConeObjectInfo
|
21
|
+
return create_cone_object(name, object_info, physics_info)
|
22
|
+
when CylinderObjectInfo
|
23
|
+
return create_cylinder_object(name, object_info, physics_info)
|
24
|
+
when MeshBBObjectInfo
|
25
|
+
return create_meshBB_object(name, object_info, physics_info)
|
26
|
+
when MeshObjectInfo
|
27
|
+
return create_mesh_object(name, object_info, physics_info)
|
28
|
+
else
|
29
|
+
puts "Error: passed no supported object_info."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def create_floor_object(name, object_info, physics_info)
|
36
|
+
obj = GardenObject.new(@garden)
|
37
|
+
obj.name = name
|
38
|
+
obj.object_info = object_info
|
39
|
+
obj.physics_info = physics_info
|
40
|
+
|
41
|
+
unless @garden.is_server
|
42
|
+
# Setting an entity and a node of Ogre3d.
|
43
|
+
normal = Ogre::Vector3.new(0, 1, 0)
|
44
|
+
up = Ogre::Vector3.new(0, 0, 1)
|
45
|
+
Ogre::MeshManager::getSingleton().createPlane(name,
|
46
|
+
Ogre::ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
|
47
|
+
Ogre::Plane.new(normal, 0),
|
48
|
+
object_info.width * 2.0,
|
49
|
+
object_info.height * 2.0,
|
50
|
+
object_info.num_seg_x,
|
51
|
+
object_info.num_seg_y,
|
52
|
+
true, 1,
|
53
|
+
object_info.u_tile,
|
54
|
+
object_info.v_tile, up)
|
55
|
+
entity = @garden.view.scene_mgr.createEntity(name, name)
|
56
|
+
entity.setCastShadows(true)
|
57
|
+
entity.setMaterialName(object_info.material_name)
|
58
|
+
node = obj.create_scene_node(entity)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Setting a collision shape and rigid body of Bullet.
|
62
|
+
cShape = Bullet::BtBoxShape.new(Vector3D.new(object_info.width, object_info.depth, object_info.height))
|
63
|
+
rb = obj.create_rigid_body(0, cShape, Vector3D.new(0, 0, 0), Vector3D.new(0.0, -object_info.depth, 0.0))
|
64
|
+
rb.setAngularFactor(physics_info.angular_factor)
|
65
|
+
rb.setRestitution(physics_info.restitution)
|
66
|
+
rb.setFriction(physics_info.friction)
|
67
|
+
rb.setDamping(physics_info.linear_damping, physics_info.angular_damping)
|
68
|
+
|
69
|
+
@garden.add_object(obj)
|
70
|
+
|
71
|
+
return obj
|
72
|
+
end
|
73
|
+
|
74
|
+
def create_box_object(name, object_info, physics_info)
|
75
|
+
obj = GardenObject.new(@garden)
|
76
|
+
obj.name = name
|
77
|
+
obj.object_info = object_info
|
78
|
+
obj.physics_info = physics_info
|
79
|
+
|
80
|
+
unless @garden.is_server
|
81
|
+
gen = Procedural::BoxGenerator.new()
|
82
|
+
gen.setSizeX(object_info.size.x * 2.0).setSizeY(object_info.size.y * 2.0).setSizeZ(object_info.size.z * 2.0)
|
83
|
+
gen.setNumSegX(object_info.num_seg_x).setNumSegY(object_info.num_seg_y).setNumSegZ(object_info.num_seg_z)
|
84
|
+
gen.setUTile(object_info.u_tile).setVTile(object_info.v_tile).realizeMesh(name)
|
85
|
+
entity = @garden.view.scene_mgr.createEntity(name)
|
86
|
+
entity.setCastShadows(true)
|
87
|
+
entity.setMaterialName(object_info.material_name)
|
88
|
+
node = obj.create_scene_node(entity)
|
89
|
+
end
|
90
|
+
|
91
|
+
cShape = Bullet::BtBoxShape.new(Vector3D.new(object_info.size.x, object_info.size.y, object_info.size.z))
|
92
|
+
inertia = Bullet::BtVector3.new()
|
93
|
+
cShape.calculateLocalInertia(physics_info.mass, inertia)
|
94
|
+
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia)
|
95
|
+
rb.setAngularFactor(physics_info.angular_factor)
|
96
|
+
rb.setRestitution(physics_info.restitution)
|
97
|
+
rb.setFriction(physics_info.friction)
|
98
|
+
rb.setDamping(physics_info.linear_damping, physics_info.angular_damping)
|
99
|
+
|
100
|
+
|
101
|
+
@garden.add_object(obj)
|
102
|
+
|
103
|
+
return obj
|
104
|
+
end
|
105
|
+
|
106
|
+
def create_sphere_object(name, object_info, physics_info)
|
107
|
+
obj = GardenObject.new(@garden)
|
108
|
+
obj.name = name
|
109
|
+
obj.object_info = object_info
|
110
|
+
obj.physics_info = physics_info
|
111
|
+
|
112
|
+
unless @garden.is_server
|
113
|
+
gen = Procedural::SphereGenerator.new()
|
114
|
+
gen.setRadius(object_info.radius)
|
115
|
+
gen.setNumRings(object_info.num_rings)
|
116
|
+
gen.setNumSegments(object_info.num_segments)
|
117
|
+
gen.setUTile(object_info.u_tile).setVTile(object_info.v_tile).realizeMesh(name)
|
118
|
+
entity = @garden.view.scene_mgr.createEntity(name)
|
119
|
+
entity.setCastShadows(true)
|
120
|
+
entity.setMaterialName(object_info.material_name)
|
121
|
+
node = obj.create_scene_node(entity)
|
122
|
+
end
|
123
|
+
|
124
|
+
cShape = Bullet::BtSphereShape.new(object_info.radius)
|
125
|
+
inertia = Bullet::BtVector3.new()
|
126
|
+
cShape.calculateLocalInertia(physics_info.mass, inertia)
|
127
|
+
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia)
|
128
|
+
rb.setAngularFactor(physics_info.angular_factor)
|
129
|
+
rb.setRestitution(physics_info.restitution)
|
130
|
+
rb.setFriction(physics_info.friction)
|
131
|
+
rb.setDamping(physics_info.linear_damping, physics_info.angular_damping)
|
132
|
+
|
133
|
+
|
134
|
+
@garden.add_object(obj)
|
135
|
+
|
136
|
+
return obj
|
137
|
+
end
|
138
|
+
|
139
|
+
def create_capsule_object(name, object_info, physics_info)
|
140
|
+
obj = GardenObject.new(@garden)
|
141
|
+
obj.name = name
|
142
|
+
obj.object_info = object_info
|
143
|
+
obj.physics_info = physics_info
|
144
|
+
|
145
|
+
unless @garden.is_server
|
146
|
+
gen = Procedural::CapsuleGenerator.new()
|
147
|
+
gen.setRadius(object_info.radius).setHeight(object_info.height)
|
148
|
+
gen.setNumRings(object_info.num_rings).setNumSegments(object_info.num_segments).setNumSegHeight(object_info.num_seg_height)
|
149
|
+
gen.setUTile(object_info.u_tile).setVTile(object_info.v_tile).realizeMesh(name)
|
150
|
+
entity = @garden.view.scene_mgr.createEntity(name)
|
151
|
+
entity.setCastShadows(true)
|
152
|
+
entity.setMaterialName(object_info.material_name)
|
153
|
+
node = obj.create_scene_node(entity)
|
154
|
+
end
|
155
|
+
|
156
|
+
cShape = Bullet::BtCapsuleShape.new(object_info.radius, object_info.height)
|
157
|
+
inertia = Bullet::BtVector3.new()
|
158
|
+
cShape.calculateLocalInertia(physics_info.mass, inertia)
|
159
|
+
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia)
|
160
|
+
rb.setAngularFactor(physics_info.angular_factor)
|
161
|
+
rb.setRestitution(physics_info.restitution)
|
162
|
+
rb.setFriction(physics_info.friction)
|
163
|
+
rb.setDamping(physics_info.linear_damping, physics_info.angular_damping)
|
164
|
+
|
165
|
+
|
166
|
+
@garden.add_object(obj)
|
167
|
+
|
168
|
+
return obj
|
169
|
+
end
|
170
|
+
|
171
|
+
def create_cone_object(name, object_info, physics_info)
|
172
|
+
obj = GardenObject.new(@garden)
|
173
|
+
obj.name = name
|
174
|
+
obj.object_info = object_info
|
175
|
+
obj.physics_info = physics_info
|
176
|
+
|
177
|
+
unless @garden.is_server
|
178
|
+
gen = Procedural::ConeGenerator.new
|
179
|
+
gen.setRadius(object_info.radius).setHeight(object_info.height)
|
180
|
+
gen.setNumSegBase(object_info.num_seg_base).setNumSegHeight(object_info.num_seg_height)
|
181
|
+
gen.setUTile(object_info.u_tile).setVTile(object_info.v_tile).realizeMesh(name)
|
182
|
+
entity = @garden.view.scene_mgr.createEntity(name)
|
183
|
+
entity.setCastShadows(true)
|
184
|
+
entity.setMaterialName(object_info.material_name)
|
185
|
+
node = obj.create_scene_node(entity)
|
186
|
+
end
|
187
|
+
|
188
|
+
cShape = Bullet::BtConeShape.new(object_info.radius, object_info.height)
|
189
|
+
inertia = Bullet::BtVector3.new()
|
190
|
+
cShape.calculateLocalInertia(physics_info.mass, inertia)
|
191
|
+
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia, Vector3D.new(0, object_info.height / 2, 0))
|
192
|
+
rb.setAngularFactor(physics_info.angular_factor)
|
193
|
+
rb.setRestitution(physics_info.restitution)
|
194
|
+
rb.setFriction(physics_info.friction)
|
195
|
+
rb.setDamping(physics_info.linear_damping, physics_info.angular_damping)
|
196
|
+
|
197
|
+
|
198
|
+
@garden.add_object(obj)
|
199
|
+
|
200
|
+
return obj
|
201
|
+
end
|
202
|
+
|
203
|
+
def create_cylinder_object(name, object_info, physics_info)
|
204
|
+
obj = GardenObject.new(@garden)
|
205
|
+
obj.name = name
|
206
|
+
obj.object_info = object_info
|
207
|
+
obj.physics_info = physics_info
|
208
|
+
|
209
|
+
unless @garden.is_server
|
210
|
+
gen = Procedural::CylinderGenerator.new
|
211
|
+
gen.setRadius(object_info.radius).setHeight(object_info.height).setCapped(object_info.capped)
|
212
|
+
gen.setNumSegBase(object_info.num_seg_base).setNumSegHeight(object_info.num_seg_height)
|
213
|
+
gen.setUTile(object_info.u_tile).setVTile(object_info.v_tile).realizeMesh(name)
|
214
|
+
entity = @garden.view.scene_mgr.createEntity(name)
|
215
|
+
entity.setCastShadows(true)
|
216
|
+
entity.setMaterialName(object_info.material_name)
|
217
|
+
node = obj.create_scene_node(entity, Vector3D.new(0, -object_info.height / 2, 0))
|
218
|
+
end
|
219
|
+
|
220
|
+
cShape = Bullet::BtCylinderShape.new(Bullet::BtVector3.new(object_info.radius,
|
221
|
+
object_info.height / 2,
|
222
|
+
object_info.radius))
|
223
|
+
inertia = Bullet::BtVector3.new()
|
224
|
+
cShape.calculateLocalInertia(physics_info.mass, inertia)
|
225
|
+
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia)
|
226
|
+
rb.setAngularFactor(physics_info.angular_factor)
|
227
|
+
rb.setRestitution(physics_info.restitution)
|
228
|
+
rb.setFriction(physics_info.friction)
|
229
|
+
rb.setDamping(physics_info.linear_damping, physics_info.angular_damping)
|
230
|
+
|
231
|
+
@garden.add_object(obj)
|
232
|
+
|
233
|
+
return obj
|
234
|
+
end
|
235
|
+
|
236
|
+
def create_meshBB_object(name, object_info, physics_info)
|
237
|
+
obj = GardenObject.new(@garden)
|
238
|
+
obj.name = name
|
239
|
+
obj.object_info = object_info
|
240
|
+
obj.physics_info = physics_info
|
241
|
+
|
242
|
+
unless @garden.is_server
|
243
|
+
entity = @garden.view.scene_mgr.createEntity(name, object_info.mesh_path)
|
244
|
+
entity.setCastShadows(true)
|
245
|
+
entity.setMaterialName(object_info.material_name) if object_info.material_name
|
246
|
+
node = obj.create_scene_node(entity, object_info.view_offset, object_info.view_rotation)
|
247
|
+
node.setScale(object_info.size.x * object_info.scale.x,
|
248
|
+
object_info.size.y * object_info.scale.y,
|
249
|
+
object_info.size.z * object_info.scale.z)
|
250
|
+
end
|
251
|
+
|
252
|
+
cShape = Bullet::BtBoxShape.new(object_info.size)
|
253
|
+
inertia = Bullet::BtVector3.new()
|
254
|
+
cShape.calculateLocalInertia(physics_info.mass, inertia)
|
255
|
+
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia, object_info.physics_offset)
|
256
|
+
rb.setAngularFactor(physics_info.angular_factor)
|
257
|
+
rb.setRestitution(physics_info.restitution)
|
258
|
+
rb.setFriction(physics_info.friction)
|
259
|
+
rb.setDamping(physics_info.linear_damping, physics_info.angular_damping)
|
260
|
+
|
261
|
+
@garden.add_object(obj)
|
262
|
+
|
263
|
+
return obj
|
264
|
+
end
|
265
|
+
|
266
|
+
def create_mesh_object(name, object_info, physics_info)
|
267
|
+
obj = GardenObject.new(@garden)
|
268
|
+
obj.name = name
|
269
|
+
obj.object_info = object_info
|
270
|
+
obj.physics_info = physics_info
|
271
|
+
|
272
|
+
unless @garden.is_server
|
273
|
+
entity = @garden.view.scene_mgr.createEntity(name, object_info.mesh_path)
|
274
|
+
entity.setCastShadows(true)
|
275
|
+
entity.setMaterialName(object_info.material_name) if object_info.material_name
|
276
|
+
node = obj.create_scene_node(entity, object_info.view_offset)
|
277
|
+
node.setScale(object_info.scale.x, object_info.scale.y, object_info.scale.z)
|
278
|
+
strider = Teienlib::MeshStrider.new(entity.getMesh().get())
|
279
|
+
cShape = Bullet::BtGImpactMeshShape.new(strider)
|
280
|
+
cShape.setLocalScaling(Bullet::BtVector3.new(object_info.scale.x,
|
281
|
+
object_info.scale.y,
|
282
|
+
object_info.scale.z))
|
283
|
+
cShape.instance_variable_set(:@strider, strider) # prevent this from GC.
|
284
|
+
cShape.postUpdate()
|
285
|
+
cShape.updateBound()
|
286
|
+
inertia = Bullet::BtVector3.new()
|
287
|
+
cShape.calculateLocalInertia(physics_info.mass, inertia)
|
288
|
+
rb = obj.create_rigid_body(physics_info.mass, cShape, inertia, object_info.physics_offset)
|
289
|
+
rb.setAngularFactor(physics_info.angular_factor)
|
290
|
+
rb.setRestitution(physics_info.restitution)
|
291
|
+
rb.setFriction(physics_info.friction)
|
292
|
+
rb.setDamping(physics_info.linear_damping, physics_info.angular_damping)
|
293
|
+
end
|
294
|
+
|
295
|
+
@garden.add_object(obj)
|
296
|
+
|
297
|
+
return obj
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
end
|