teien 0.0.2 → 0.0.3
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/README.md +11 -6
- data/bin/teien +16 -2
- data/lib/teien/ai.rb +27 -0
- data/lib/teien/animation.rb +34 -0
- data/lib/teien/animation_operator.rb +6 -0
- data/lib/teien/controller.rb +30 -0
- data/lib/teien/dispatcher.rb +22 -0
- data/lib/teien/event.rb +60 -0
- data/lib/teien/event_router.rb +118 -0
- data/lib/teien/garden.rb +60 -172
- data/lib/teien/garden_base.rb +117 -0
- data/lib/teien/garden_object.rb +119 -136
- data/lib/teien/model.rb +34 -0
- data/lib/teien/network.rb +108 -0
- data/lib/teien/object_info.rb +21 -0
- data/lib/teien/physics.rb +47 -39
- data/lib/teien/physics_object.rb +57 -0
- data/lib/teien/physics_object_factory.rb +170 -0
- data/lib/teien/proxy_garden.rb +118 -0
- data/lib/teien/remote_info.rb +20 -0
- data/lib/teien/sky_dome.rb +15 -0
- data/lib/teien/smooth_mover.rb +31 -42
- data/lib/teien/synchronizer.rb +26 -0
- data/lib/teien/tools.rb +30 -2
- data/lib/teien/user_interface.rb +58 -5
- data/lib/teien/version.rb +1 -1
- data/lib/teien/view.rb +52 -33
- data/lib/teien/view_object.rb +67 -0
- data/lib/teien/view_object_factory.rb +210 -0
- data/lib/teien.rb +62 -14
- data/sample/actor/app/ais/actor_ai.rb +112 -0
- data/sample/actor/app/controllers/actor_controller.rb +182 -0
- data/sample/actor/app/helpers/sinbad/sinbad.rb +176 -0
- data/sample/actor/app/helpers/sinbad/sinbad_state.rb +224 -0
- data/sample/actor/app/helpers/user_event.rb +75 -0
- data/sample/actor/app/models/actor_model.rb +108 -0
- data/sample/actor/config/plugins.cfg +19 -0
- data/sample/actor/config/resources.cfg +24 -0
- data/sample/hello_garden/app/controllers/hello_garden_controller.rb +90 -0
- data/sample/hello_garden/app/helpers/user_event.rb +12 -0
- data/sample/{standalone/hello_garden/hello_garden.rb → hello_garden/app/models/hello_garden_model.rb} +29 -83
- data/sample/{standalone/hello_garden → hello_garden/config}/plugins.cfg +0 -0
- data/sample/{standalone/hello_garden → hello_garden/config}/resources.cfg +0 -0
- data/sample/hello_garden/run +6 -0
- data/teien.gemspec +2 -1
- metadata +52 -15
- data/lib/teien/light_object.rb +0 -36
- data/lib/teien/object_factory.rb +0 -308
- data/sample/standalone/hello_garden/run +0 -5
@@ -0,0 +1,117 @@
|
|
1
|
+
require "teien/garden_object.rb"
|
2
|
+
require "teien/sky_dome.rb"
|
3
|
+
require "teien/physics.rb"
|
4
|
+
#require "teien/user_interface.rb"
|
5
|
+
#require "teien/event_router.rb"
|
6
|
+
require "teien/dispatcher.rb"
|
7
|
+
|
8
|
+
require "eventmachine"
|
9
|
+
require "teien/network.rb"
|
10
|
+
|
11
|
+
module Teien
|
12
|
+
|
13
|
+
# This is a top object of 3D world.
|
14
|
+
class GardenBase
|
15
|
+
include Dispatcher
|
16
|
+
|
17
|
+
attr_accessor :resources_cfg
|
18
|
+
attr_accessor :plugins_cfg
|
19
|
+
attr_accessor :physics
|
20
|
+
attr_accessor :objects
|
21
|
+
attr_accessor :actors
|
22
|
+
|
23
|
+
attr_accessor :gravity
|
24
|
+
attr_accessor :ambient_light_color
|
25
|
+
|
26
|
+
#
|
27
|
+
# _script_klass_:: : set a user define class.
|
28
|
+
#
|
29
|
+
def initialize()
|
30
|
+
super()
|
31
|
+
|
32
|
+
@physics = Physics.new()
|
33
|
+
@actors = Hash.new()
|
34
|
+
|
35
|
+
@resources_cfg = nil
|
36
|
+
@plugins_cfg = nil
|
37
|
+
|
38
|
+
@objects = {}
|
39
|
+
@object_num = 0
|
40
|
+
|
41
|
+
@debug_draw = false
|
42
|
+
@quit = false
|
43
|
+
@last_time = 0
|
44
|
+
|
45
|
+
# environment value
|
46
|
+
@gravity = nil
|
47
|
+
@ambient_light_color = nil
|
48
|
+
@sky_dome = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# set the gravity of the world.
|
53
|
+
#
|
54
|
+
# _grav_ :: : set a vector(Vector3D) as the gravity.
|
55
|
+
#
|
56
|
+
def set_gravity(grav)
|
57
|
+
@gravity = grav
|
58
|
+
@physics.set_gravity(grav)
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# set the ambient light of the world.
|
63
|
+
#
|
64
|
+
# _color_:: : set a color(Color).
|
65
|
+
#
|
66
|
+
def set_ambient_light(color)
|
67
|
+
@ambient_light_color = color
|
68
|
+
notify(:set_ambient_light, color)
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_sky_dome(enable, materialName, curvature = 10, tiling = 8, distance = 4000)
|
72
|
+
@sky_dome = SkyDome.new(enable, materialName, curvature, tiling, distance)
|
73
|
+
notify(:set_sky_dome, enable, materialName, curvature, tiling, distance)
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_object(name, object_info, physics_info)
|
77
|
+
if (@objects[name])
|
78
|
+
#raise RuntimeError, "There is a object with the same name (#{obj.name})"
|
79
|
+
puts "There is a object with the same name (#{name})"
|
80
|
+
return @objects[name]
|
81
|
+
else
|
82
|
+
obj = GardenObject.new()
|
83
|
+
obj.name = name
|
84
|
+
obj.object_info = object_info
|
85
|
+
obj.physics_info = physics_info
|
86
|
+
|
87
|
+
obj.garden = @garden
|
88
|
+
@objects[obj.name] = obj
|
89
|
+
obj.id = @object_num
|
90
|
+
@object_num += 1
|
91
|
+
@physics.add_physics_object(obj)
|
92
|
+
notify(:create_object, obj)
|
93
|
+
return obj
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def add_actor(actor)
|
98
|
+
if (@actors[actor.name] == nil)
|
99
|
+
actors[name] = actor
|
100
|
+
notify(:add_actor, actor)
|
101
|
+
else
|
102
|
+
raise RuntimeError, "There is an actor with the same name (#{actor.name})"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def check_collision(objectA, objectB)
|
107
|
+
result = @physics.contact_pair_test(objectA.rigid_body, objectB.rigid_body)
|
108
|
+
return result.collided?()
|
109
|
+
end
|
110
|
+
|
111
|
+
# quit the current running garden.
|
112
|
+
def quit()
|
113
|
+
@quit = true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end # module
|
data/lib/teien/garden_object.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "teien/tools.rb"
|
2
|
-
require "teien/
|
2
|
+
require "teien/physics_object.rb"
|
3
|
+
require "teien/view_object.rb"
|
3
4
|
|
4
5
|
module Teien
|
5
6
|
|
@@ -14,76 +15,33 @@ class GardenObject < Bullet::BtMotionState
|
|
14
15
|
|
15
16
|
attr_accessor :object_info
|
16
17
|
attr_accessor :physics_info
|
18
|
+
attr_accessor :animation_info
|
17
19
|
|
18
|
-
|
19
|
-
attr_accessor :
|
20
|
-
attr_accessor :
|
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
|
20
|
+
attr_accessor :garden
|
21
|
+
attr_accessor :physics_object
|
22
|
+
attr_accessor :view_object
|
28
23
|
|
29
24
|
MODE_FREE = 0
|
30
25
|
MODE_ATTACHED = 1
|
31
26
|
|
32
|
-
def initialize(
|
27
|
+
def initialize()
|
33
28
|
super()
|
34
29
|
@id = -1
|
35
|
-
@garden = garden
|
36
30
|
@mode = MODE_FREE
|
37
31
|
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
41
|
-
|
42
|
-
@rigid_body = nil
|
43
|
-
@transform = Bullet::BtTransform.new()
|
44
|
-
@transform.set_identity()
|
45
|
-
@acceleration = Vector3D.new(0, 0, 0)
|
46
|
-
|
47
|
-
@maxHorizontalVelocity = 0
|
48
|
-
@maxVerticalVelocity = 0
|
32
|
+
@garden = nil
|
33
|
+
@physics_object = nil
|
34
|
+
@view_object = nil
|
35
|
+
@animation_info = Animation.new
|
49
36
|
end
|
50
37
|
|
51
|
-
|
52
|
-
|
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.get_root_scene_node().create_child_scene_node()
|
57
|
-
end
|
58
|
-
@scene_node = @pivot_scene_node.create_child_scene_node(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.attach_object(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.set_identity()
|
75
|
-
localTrans.set_origin(offset)
|
76
|
-
@pivot_shape.add_child_shape(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)
|
38
|
+
def finalize()
|
39
|
+
@view_object.finalize() if @view_object
|
40
|
+
@physics_object.finalize()
|
83
41
|
end
|
84
42
|
|
85
43
|
def set_activation_state(state)
|
86
|
-
@rigid_body.set_activation_state(state)
|
44
|
+
@physics_object.rigid_body.set_activation_state(state)
|
87
45
|
end
|
88
46
|
|
89
47
|
|
@@ -92,9 +50,25 @@ class GardenObject < Bullet::BtMotionState
|
|
92
50
|
# ==== Args
|
93
51
|
# [aPos: Vector3D]
|
94
52
|
def set_position(aPos)
|
95
|
-
|
96
|
-
@
|
97
|
-
@
|
53
|
+
|
54
|
+
# @pivot_scene_node.set_position(aPos.x, aPos.y, aPos.z) unless @garden.is_server
|
55
|
+
@physics_object.transform.set_origin(Bullet::BtVector3.new(aPos.x, aPos.y, aPos.z))
|
56
|
+
@physics_object.rigid_body.set_center_of_mass_transform(@physics_object.transform) if (@physics_object.rigid_body != nil)
|
57
|
+
|
58
|
+
# view
|
59
|
+
if (@view_object)
|
60
|
+
if (object_info.class == LightObjectInfo)
|
61
|
+
@view_object.entity.set_position(Vector3D.to_ogre(aPos))
|
62
|
+
else
|
63
|
+
@view_object.pivot_scene_node.set_position(aPos.x, aPos.y, aPos.z)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_position_with_interpolation(pos)
|
69
|
+
ip_pos = (get_position() + Vector3D.to_bullet(pos)) / 2
|
70
|
+
@physics_object.transform.set_origin(ip_pos)
|
71
|
+
@physics_object.rigid_body.set_center_of_mass_transform(@physics_object.transform) if (@physics_object.rigid_body != nil)
|
98
72
|
end
|
99
73
|
|
100
74
|
# Set a linear velocity.
|
@@ -102,8 +76,14 @@ class GardenObject < Bullet::BtMotionState
|
|
102
76
|
# ==== Args
|
103
77
|
# [aVel: Vector3D]
|
104
78
|
def set_linear_velocity(aVel)
|
105
|
-
@rigid_body.activate(true)
|
106
|
-
@rigid_body.set_linear_velocity(aVel)
|
79
|
+
@physics_object.rigid_body.activate(true)
|
80
|
+
@physics_object.rigid_body.set_linear_velocity(aVel)
|
81
|
+
end
|
82
|
+
|
83
|
+
def set_linear_velocity_with_interpolation(vel)
|
84
|
+
ip_vel = (get_linear_velocity() + Vector3D.to_bullet(vel)) / 2
|
85
|
+
@physics_object.rigid_body.activate(true)
|
86
|
+
@physics_object.rigid_body.set_linear_velocity(ip_vel)
|
107
87
|
end
|
108
88
|
|
109
89
|
# Set an angular velocity.
|
@@ -111,7 +91,14 @@ class GardenObject < Bullet::BtMotionState
|
|
111
91
|
# ==== Args
|
112
92
|
# [vel: Vector3D]
|
113
93
|
def set_angular_velocity(vel)
|
114
|
-
@rigid_body.
|
94
|
+
@physics_object.rigid_body.activate(true)
|
95
|
+
@physics_object.rigid_body.set_angular_velocity(vel)
|
96
|
+
end
|
97
|
+
|
98
|
+
def set_angular_velocity_with_interpolation(vel)
|
99
|
+
@physics_object.rigid_body.activate(true)
|
100
|
+
ip_vel = (get_angular_velocity() + Vector3D.to_bullet(vel)) / 2
|
101
|
+
@physics_object.rigid_body.set_angular_velocity(ip_vel)
|
115
102
|
end
|
116
103
|
|
117
104
|
# Set a max horizontal velocity.
|
@@ -119,7 +106,7 @@ class GardenObject < Bullet::BtMotionState
|
|
119
106
|
# ==== Args
|
120
107
|
# [vel: Vector3D] vel is the max velocity. 0 means there is no limit.
|
121
108
|
def set_max_horizontal_velocity(vel_len)
|
122
|
-
@maxHorizontalVelocity = vel_len
|
109
|
+
@physics_object.maxHorizontalVelocity = vel_len
|
123
110
|
end
|
124
111
|
|
125
112
|
# Set a max vertical velocity.
|
@@ -127,50 +114,60 @@ class GardenObject < Bullet::BtMotionState
|
|
127
114
|
# ==== Args
|
128
115
|
# [vel: Vector3D] vel is the max velocity. 0 means there is no limit.
|
129
116
|
def set_max_vertical_velocity(vel_le)
|
130
|
-
@maxVerticalVelocity = vel_len
|
117
|
+
@physics_object.maxVerticalVelocity = vel_len
|
131
118
|
end
|
132
119
|
|
133
120
|
# Set the object's acceleration.
|
134
121
|
def set_acceleration(acc)
|
135
|
-
@acceleration = acc
|
122
|
+
@physics_object.acceleration = acc
|
136
123
|
end
|
137
124
|
|
138
125
|
def set_gravity(grav)
|
139
|
-
@rigid_body.set_gravity(grav)
|
126
|
+
@physics_object.rigid_body.set_gravity(grav)
|
127
|
+
end
|
128
|
+
|
129
|
+
def set_damping(linear_damping, angular_damping)
|
130
|
+
@physics_object.rigid_body.set_damping(linear_damping, angular_damping)
|
131
|
+
@physics_info.linear_damping = linear_damping
|
132
|
+
@physics_info.angular_damping = angular_damping
|
133
|
+
# notify?
|
140
134
|
end
|
141
135
|
|
142
136
|
def set_rotation(quad)
|
143
|
-
|
144
|
-
transform.
|
145
|
-
@
|
137
|
+
@physics_object.rigid_body.activate(true)
|
138
|
+
@physics_object.transform = @physics_object.rigid_body.get_center_of_mass_transform()
|
139
|
+
@physics_object.transform.set_rotation(quad)
|
140
|
+
@physics_object.rigid_body.set_center_of_mass_transform(@physics_object.transform)
|
141
|
+
end
|
142
|
+
|
143
|
+
def set_rotation_with_interpolation(quad)
|
144
|
+
@physics_object.rigid_body.activate(true)
|
145
|
+
ip_quad = get_rotation().slerp(Quaternion.to_bullet(quad), 0.5)
|
146
|
+
@physics_object.transform = @physics_object.rigid_body.get_center_of_mass_transform()
|
147
|
+
@physics_object.transform.set_rotation(ip_quad)
|
148
|
+
@physics_object.rigid_body.set_center_of_mass_transform(@physics_object.transform)
|
146
149
|
end
|
147
150
|
|
148
151
|
def set_collision_filter(filter)
|
149
|
-
@garden.physics.dynamicsWorld.remove_rigid_body(@rigid_body)
|
150
|
-
@garden.physics.dynamicsWorld.add_rigid_body(@rigid_body, filter.group, filter.mask)
|
152
|
+
@garden.physics.dynamicsWorld.remove_rigid_body(@physics_object.rigid_body)
|
153
|
+
@garden.physics.dynamicsWorld.add_rigid_body(@physics_object.rigid_body, filter.group, filter.mask)
|
151
154
|
physics_info.collisionFilter = filter
|
152
155
|
end
|
153
156
|
|
154
157
|
def set_world_transform(worldTrans)
|
155
|
-
|
156
|
-
|
157
|
-
if (@
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
return
|
169
|
-
end
|
170
|
-
|
171
|
-
unless @garden.is_server
|
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)
|
158
|
+
@physics_object.transform = Bullet::BtTransform.new(worldTrans) if (@mode == MODE_FREE)
|
159
|
+
|
160
|
+
if (@view_object)
|
161
|
+
if (@mode == MODE_FREE)
|
162
|
+
newPos = @physics_object.transform.get_origin()
|
163
|
+
newRot = @physics_object.transform.get_rotation()
|
164
|
+
# puts "newRot(#{id}: #{newRot.x}, #{newRot.y}, #{newRot.z}, #{newRot.w})"
|
165
|
+
# puts "newPos(#{id}: #{newPos.x}, #{newPos.y}, #{newPos.z})"
|
166
|
+
|
167
|
+
return if (newRot.x.nan?)
|
168
|
+
|
169
|
+
@view_object.pivot_scene_node.set_position(newPos.x, newPos.y, newPos.z)
|
170
|
+
@view_object.pivot_scene_node.set_orientation(newRot.w, newRot.x, newRot.y, newRot.z)
|
174
171
|
end
|
175
172
|
end
|
176
173
|
end
|
@@ -180,62 +177,62 @@ class GardenObject < Bullet::BtMotionState
|
|
180
177
|
end
|
181
178
|
|
182
179
|
def get_activation_state()
|
183
|
-
@rigid_body.get_activation_state()
|
180
|
+
@physics_object.rigid_body.get_activation_state()
|
184
181
|
end
|
185
182
|
|
186
183
|
def get_mass()
|
187
|
-
return 1.0 / @rigid_body.get_inv_mass()
|
184
|
+
return 1.0 / @physics_object.rigid_body.get_inv_mass()
|
188
185
|
end
|
189
186
|
|
190
187
|
def get_inv_mass()
|
191
|
-
return @rigid_body.get_inv_mass()
|
188
|
+
return @physics_object.rigid_body.get_inv_mass()
|
192
189
|
end
|
193
190
|
|
194
191
|
def get_collision_mask()
|
195
|
-
@rigid_body.get_broadphase_handle().m_collisionFilterMask
|
192
|
+
@physics_object.rigid_body.get_broadphase_handle().m_collisionFilterMask
|
196
193
|
end
|
197
194
|
|
198
195
|
def get_position()
|
199
|
-
newPos = @transform.get_origin()
|
196
|
+
newPos = @physics_object.transform.get_origin()
|
200
197
|
return newPos
|
201
198
|
end
|
202
199
|
|
203
200
|
def get_linear_velocity()
|
204
|
-
return @rigid_body.get_linear_velocity()
|
201
|
+
return @physics_object.rigid_body.get_linear_velocity()
|
205
202
|
end
|
206
203
|
|
207
204
|
def get_angular_velocity()
|
208
|
-
return @rigid_body.get_angular_velocity()
|
205
|
+
return @physics_object.rigid_body.get_angular_velocity()
|
209
206
|
end
|
210
207
|
|
211
208
|
def get_acceleration()
|
212
|
-
return @acceleration
|
209
|
+
return @physics_object.acceleration
|
213
210
|
end
|
214
211
|
|
215
212
|
def get_gravity()
|
216
|
-
return @rigid_body.get_gravity()
|
213
|
+
return @physics_object.rigid_body.get_gravity()
|
217
214
|
end
|
218
215
|
|
219
216
|
def get_rotation()
|
220
|
-
return @transform.get_rotation()
|
217
|
+
return @physics_object.transform.get_rotation()
|
221
218
|
end
|
222
219
|
|
223
220
|
def get_orientation()
|
224
|
-
return @transform.get_rotation()
|
221
|
+
return @physics_object.transform.get_rotation()
|
225
222
|
end
|
226
223
|
|
227
224
|
def limit_velocity(vel)
|
228
225
|
newVel = Bullet::BtVector3.new(vel.x, vel.y, vel.z)
|
229
226
|
|
230
227
|
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
|
228
|
+
if (@physics_object.maxHorizontalVelocity != 0 && hLen > @physics_object.maxHorizontalVelocity)
|
229
|
+
newVel.x = vel.x / hLen * @physics_object.maxHorizontalVelocity
|
230
|
+
newVel.z = vel.z / hLen * @physics_object.maxHorizontalVelocity
|
234
231
|
end
|
235
232
|
|
236
233
|
vLen = vel.y
|
237
|
-
if (@maxVerticalVelocity != 0 && vLen > @maxVerticalVelocity)
|
238
|
-
newVel.y = @maxVerticalVelocity
|
234
|
+
if (@physics_object.maxVerticalVelocity != 0 && vLen > @physics_object.maxVerticalVelocity)
|
235
|
+
newVel.y = @physics_object.maxVerticalVelocity
|
239
236
|
end
|
240
237
|
|
241
238
|
# puts "newVel: (#{newVel.x}, #{newVel.y}, #{newVel.z})"
|
@@ -244,8 +241,8 @@ class GardenObject < Bullet::BtMotionState
|
|
244
241
|
end
|
245
242
|
|
246
243
|
def apply_impulse(imp, rel = Vector3D.new(0, 0, 0))
|
247
|
-
@rigid_body.activate(true)
|
248
|
-
@rigid_body.apply_impulse(imp, rel)
|
244
|
+
@physics_object.rigid_body.activate(true)
|
245
|
+
@physics_object.rigid_body.apply_impulse(imp, rel)
|
249
246
|
end
|
250
247
|
|
251
248
|
#
|
@@ -260,15 +257,18 @@ class GardenObject < Bullet::BtMotionState
|
|
260
257
|
qnorm = Quaternion.new()
|
261
258
|
qnorm.copy(quat)
|
262
259
|
qnorm.normalize()
|
263
|
-
transform = @rigid_body.get_center_of_mass_transform()
|
260
|
+
transform = @physics_object.rigid_body.get_center_of_mass_transform()
|
264
261
|
curRot = transform.get_rotation()
|
265
|
-
newRot = curRot * qnorm
|
266
|
-
transform.set_rotation(newRot)
|
267
|
-
@rigid_body.set_center_of_mass_transform(transform)
|
262
|
+
@newRot = curRot * qnorm
|
263
|
+
transform.set_rotation(@newRot)
|
264
|
+
@physics_object.rigid_body.set_center_of_mass_transform(transform)
|
268
265
|
|
269
|
-
@
|
266
|
+
if (@view_object)
|
267
|
+
@view_object.pivot_scene_node.set_orientation(Quaternion.to_ogre(@newRot))
|
268
|
+
end
|
270
269
|
end
|
271
|
-
|
270
|
+
|
271
|
+
=begin
|
272
272
|
def attach_object_to_bone(boneName, obj)
|
273
273
|
obj.scene_node.detach_object(obj.entity)
|
274
274
|
tag = @entity.attach_object_to_bone(boneName, obj.entity)
|
@@ -280,34 +280,17 @@ class GardenObject < Bullet::BtMotionState
|
|
280
280
|
def detach_object_from_bone(obj)
|
281
281
|
@entity.detach_object_from_bone(obj.entity)
|
282
282
|
obj.scene_node.attach_object(obj.entity)
|
283
|
-
if obj.physics_info.
|
283
|
+
if obj.physics_info.collision_filter
|
284
284
|
@garden.physics.dynamics_world.add_rigid_body(obj.rigid_body,
|
285
|
-
obj.physics_info.
|
286
|
-
obj.physics_info.
|
285
|
+
obj.physics_info.collision_filter.group,
|
286
|
+
obj.physics_info.collision_filter.mask)
|
287
287
|
else
|
288
288
|
@garden.physics.dynamics_world.add_rigid_body(obj.rigid_body)
|
289
289
|
end
|
290
290
|
obj.mode = MODE_FREE
|
291
291
|
end
|
292
|
+
=end
|
292
293
|
|
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
294
|
end
|
312
295
|
|
313
296
|
|
data/lib/teien/model.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'teien'
|
2
|
+
|
3
|
+
module Teien
|
4
|
+
|
5
|
+
class Model
|
6
|
+
@@models = Array.new
|
7
|
+
@@loaded_models = Array.new
|
8
|
+
|
9
|
+
@garden = nil
|
10
|
+
|
11
|
+
def initialize(garden)
|
12
|
+
@garden = garden
|
13
|
+
@garden.register_receiver(self)
|
14
|
+
|
15
|
+
=begin
|
16
|
+
# set config files.
|
17
|
+
fileDir = File.dirname(File.expand_path(__FILE__))
|
18
|
+
@garden.plugins_cfg = "#{fileDir}/plugins.cfg"
|
19
|
+
@garden.resources_cfg = "#{fileDir}/resources.cfg"
|
20
|
+
=end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.inherited(klass)
|
24
|
+
@@models.push(klass)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.load(garden)
|
28
|
+
@@models.each {|ctl|
|
29
|
+
@@loaded_models.push(ctl.new(garden))
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'teien/remote_info'
|
2
|
+
|
3
|
+
module Teien
|
4
|
+
|
5
|
+
class Network < EM::Connection
|
6
|
+
@@connected_clients = Hash.new
|
7
|
+
@@garden = nil
|
8
|
+
|
9
|
+
def initialize(garden)
|
10
|
+
@@garden = garden
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.connected_clients
|
14
|
+
@@connected_clients
|
15
|
+
end
|
16
|
+
|
17
|
+
def post_init
|
18
|
+
puts "A client has connected."
|
19
|
+
@@connected_clients[self] = RemoteInfo.new(self)
|
20
|
+
@@garden.receive_event(Event::ClientConnected.new, self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def unbind
|
24
|
+
puts "A client has unbinded."
|
25
|
+
@@garden.receive_event(Event::ClientUnbinded.new, self)
|
26
|
+
@@connected_clients.delete(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
include EM::P::ObjectProtocol
|
30
|
+
|
31
|
+
def receive_object(obj)
|
32
|
+
@@garden.receive_event(obj, self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.send_all(obj)
|
36
|
+
@@connected_clients.each_value { |c|
|
37
|
+
c.connection.send_object(obj)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
=begin
|
43
|
+
class ServerNetwork < EM::Connection
|
44
|
+
@@connected_clients = Array.new
|
45
|
+
|
46
|
+
def initialize(event_router)
|
47
|
+
@event_router = event_router
|
48
|
+
@event_router.register_receiver(Event::ToControllerGroup, self)
|
49
|
+
end
|
50
|
+
|
51
|
+
def receive_event(event)
|
52
|
+
send_all(event)
|
53
|
+
end
|
54
|
+
|
55
|
+
def post_init
|
56
|
+
puts "A client has connected."
|
57
|
+
@@connected_clients.push(self)
|
58
|
+
@event_router.notify(Event::ClientConnected.new)
|
59
|
+
end
|
60
|
+
|
61
|
+
def unbind
|
62
|
+
puts "A client has unbinded."
|
63
|
+
@@connected_clients.delete(self)
|
64
|
+
end
|
65
|
+
|
66
|
+
include EM::P::ObjectProtocol
|
67
|
+
|
68
|
+
def receive_object(obj)
|
69
|
+
@event_router.notify(obj)
|
70
|
+
# puts "A object is received"
|
71
|
+
# obj.print
|
72
|
+
end
|
73
|
+
|
74
|
+
def send_all(obj)
|
75
|
+
@@connected_clients.each { |c|
|
76
|
+
c.send_object(obj)
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class ClientNetwork < EM::Connection
|
82
|
+
def initialize(event_router)
|
83
|
+
@event_router = event_router
|
84
|
+
@event_router.register_receiver(Event::ToModelGroup, self)
|
85
|
+
end
|
86
|
+
|
87
|
+
def receive_event(event)
|
88
|
+
send_object(event)
|
89
|
+
end
|
90
|
+
|
91
|
+
def connection_completed
|
92
|
+
puts "The connection is completed."
|
93
|
+
end
|
94
|
+
|
95
|
+
def unbind
|
96
|
+
puts "The connection is closed."
|
97
|
+
end
|
98
|
+
|
99
|
+
include EM::P::ObjectProtocol
|
100
|
+
|
101
|
+
def receive_object(obj)
|
102
|
+
@event_router.notify(obj)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
=end
|
107
|
+
|
108
|
+
end
|
data/lib/teien/object_info.rb
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
module Teien
|
2
2
|
|
3
|
+
class LightObjectInfo
|
4
|
+
POINT = Ogre::Light::LT_POINT
|
5
|
+
DIRECTIONAL = Ogre::Light::LT_DIRECTIONAL
|
6
|
+
SPOTLIGHT = Ogre::Light::LT_SPOTLIGHT
|
7
|
+
|
8
|
+
attr_accessor :type
|
9
|
+
attr_accessor :diffuse_color
|
10
|
+
attr_accessor :specular_color
|
11
|
+
attr_accessor :direction
|
12
|
+
|
13
|
+
def initialize(type,
|
14
|
+
diffuse_color = Color.new(1.0, 1.0, 1.0),
|
15
|
+
specular_color = Color.new(0.25, 0.25, 0),
|
16
|
+
direction = Vector3D.new( -1, -1, -1 ))
|
17
|
+
@type = type
|
18
|
+
@diffuse_color = diffuse_color
|
19
|
+
@specular_color = specular_color
|
20
|
+
@direction = direction
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
3
24
|
class MeshBBObjectInfo
|
4
25
|
attr_accessor :mesh_path
|
5
26
|
attr_accessor :size # Loading mesh only: bounding box size
|