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.
Files changed (49) hide show
  1. data/README.md +11 -6
  2. data/bin/teien +16 -2
  3. data/lib/teien/ai.rb +27 -0
  4. data/lib/teien/animation.rb +34 -0
  5. data/lib/teien/animation_operator.rb +6 -0
  6. data/lib/teien/controller.rb +30 -0
  7. data/lib/teien/dispatcher.rb +22 -0
  8. data/lib/teien/event.rb +60 -0
  9. data/lib/teien/event_router.rb +118 -0
  10. data/lib/teien/garden.rb +60 -172
  11. data/lib/teien/garden_base.rb +117 -0
  12. data/lib/teien/garden_object.rb +119 -136
  13. data/lib/teien/model.rb +34 -0
  14. data/lib/teien/network.rb +108 -0
  15. data/lib/teien/object_info.rb +21 -0
  16. data/lib/teien/physics.rb +47 -39
  17. data/lib/teien/physics_object.rb +57 -0
  18. data/lib/teien/physics_object_factory.rb +170 -0
  19. data/lib/teien/proxy_garden.rb +118 -0
  20. data/lib/teien/remote_info.rb +20 -0
  21. data/lib/teien/sky_dome.rb +15 -0
  22. data/lib/teien/smooth_mover.rb +31 -42
  23. data/lib/teien/synchronizer.rb +26 -0
  24. data/lib/teien/tools.rb +30 -2
  25. data/lib/teien/user_interface.rb +58 -5
  26. data/lib/teien/version.rb +1 -1
  27. data/lib/teien/view.rb +52 -33
  28. data/lib/teien/view_object.rb +67 -0
  29. data/lib/teien/view_object_factory.rb +210 -0
  30. data/lib/teien.rb +62 -14
  31. data/sample/actor/app/ais/actor_ai.rb +112 -0
  32. data/sample/actor/app/controllers/actor_controller.rb +182 -0
  33. data/sample/actor/app/helpers/sinbad/sinbad.rb +176 -0
  34. data/sample/actor/app/helpers/sinbad/sinbad_state.rb +224 -0
  35. data/sample/actor/app/helpers/user_event.rb +75 -0
  36. data/sample/actor/app/models/actor_model.rb +108 -0
  37. data/sample/actor/config/plugins.cfg +19 -0
  38. data/sample/actor/config/resources.cfg +24 -0
  39. data/sample/hello_garden/app/controllers/hello_garden_controller.rb +90 -0
  40. data/sample/hello_garden/app/helpers/user_event.rb +12 -0
  41. data/sample/{standalone/hello_garden/hello_garden.rb → hello_garden/app/models/hello_garden_model.rb} +29 -83
  42. data/sample/{standalone/hello_garden → hello_garden/config}/plugins.cfg +0 -0
  43. data/sample/{standalone/hello_garden → hello_garden/config}/resources.cfg +0 -0
  44. data/sample/hello_garden/run +6 -0
  45. data/teien.gemspec +2 -1
  46. metadata +52 -15
  47. data/lib/teien/light_object.rb +0 -36
  48. data/lib/teien/object_factory.rb +0 -308
  49. data/sample/standalone/hello_garden/run +0 -5
data/lib/teien/physics.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "teien/physics_object_factory.rb"
2
+
1
3
  module Teien
2
4
 
3
5
  CollisionFilter = Struct.new(:group, :mask)
@@ -5,6 +7,7 @@ CollisionFilter = Struct.new(:group, :mask)
5
7
  class ContactResult < Bullet::ContactResultCallback
6
8
  def initialize
7
9
  super
10
+
8
11
  @isCollided = false
9
12
  end
10
13
 
@@ -27,18 +30,23 @@ class Physics < Bullet::TickListener
27
30
  attr_accessor :fixed_time_step
28
31
  # attr_accessor :softBodyWorldInfo
29
32
 
30
- def initialize(garden)
33
+ def initialize()
31
34
  super()
32
- @garden = garden
35
+
36
+ @object_factory = PhysicsObjectFactory.new(self)
37
+ @rigid_bodies = []
33
38
 
34
39
  @max_sub_steps = 1
35
40
  @fixed_time_step = 1.0 / 60.0
41
+ end
36
42
 
37
- @rigid_bodies = []
43
+ def set_gravity(vec)
44
+ @dynamics_world.set_gravity(vec)
38
45
  end
39
46
 
40
- def setup
41
- @collision_config = Bullet::BtDefaultCollisionConfiguration.new();
47
+ def setup(garden)
48
+ @garden = garden
49
+ @collision_config = Bullet::BtDefaultCollisionConfiguration.new()
42
50
  @collision_dispatcher = Bullet::BtCollisionDispatcher.new(@collision_config)
43
51
 
44
52
  worldAabbMin = Bullet::BtVector3.new(-3000.0,-500.0, -3000.0)
@@ -77,6 +85,35 @@ class Physics < Bullet::TickListener
77
85
  # @dynamics_world.finalize()
78
86
  end
79
87
 
88
+ def add_physics_object(obj)
89
+ obj.physics_object = @object_factory.create_object(obj)
90
+
91
+ if (obj.physics_object.rigid_body != nil &&
92
+ obj.object_info.class != LightObjectInfo)
93
+
94
+ if (obj.physics_info.collision_filter)
95
+ add_rigid_body(obj.physics_object.rigid_body,
96
+ obj.physics_info.collision_filter)
97
+ else
98
+ add_rigid_body(obj.physics_object.rigid_body)
99
+ end
100
+ end
101
+ end
102
+
103
+ def add_rigid_body(rigid_body, collision_filter = nil)
104
+ @rigid_bodies.push(rigid_body)
105
+ if (collision_filter)
106
+ @dynamics_world.add_rigid_body(rigid_body, collision_filter.group, collision_filter.mask)
107
+ else
108
+ @dynamics_world.add_rigid_body(rigid_body)
109
+ end
110
+ end
111
+
112
+ def del_rigid_body(rigid_body)
113
+ @rigid_bodies.delete(rigid_body)
114
+ @dynamics_world.remove_rigid_body(rigid_body)
115
+ end
116
+
80
117
  def update(delta)
81
118
  @dynamics_world.step_simulation(delta, @max_sub_steps, @fixed_time_step)
82
119
  return true
@@ -94,56 +131,27 @@ class Physics < Bullet::TickListener
94
131
  @dynamics_world.get_dispatcher())
95
132
  end
96
133
 
97
- def set_gravity(vec)
98
- @dynamics_world.set_gravity(vec)
99
- end
100
-
101
- =begin
102
- def create_box_shape(size)
103
- return Bullet::BtBoxShape.new(size)
104
- end
105
-
106
- def createSphereShape(radius)
107
- return Bullet::BtSphereShape.new(radius)
108
- end
109
- =end
110
-
111
- def create_rigid_body(mass, motionState, colObj, inertia)
112
- rigid_body = Bullet::BtRigidBody.new(mass, motionState, colObj, inertia)
113
- rigid_body.instance_variable_set(:@collision_shape, colObj) # prevent this colObj from GC.
114
- return rigid_body
115
- end
116
-
117
- def add_rigid_body(rigid_body, collision_filter = nil)
118
- @rigid_bodies.push(rigid_body)
119
- if (collision_filter)
120
- @dynamics_world.add_rigid_body(rigid_body, collision_filter.group, collision_filter.mask)
121
- else
122
- @dynamics_world.add_rigid_body(rigid_body)
123
- end
124
- end
125
-
126
134
  def contact_pair_test(colObjA, colObjB)
127
135
  result = ContactResult.new
128
136
  @dynamics_world.contact_pair_test(colObjA, colObjB, result)
129
137
  return result
130
138
  end
131
139
 
132
- def preTickCallback(timeStep)
133
- # print "preTickCallback: ", timeStep * 1000, "ms\n"
140
+ def pre_tick_callback(timeStep)
141
+ # print "pre_tick_callback: ", timeStep * 1000, "ms\n"
134
142
  delta = Bullet::BtVector3.new(timeStep, timeStep, timeStep)
135
143
 
136
144
  @garden.objects.each {|name, obj|
137
145
  if (obj.get_mass() > 0)
138
- newVel = obj.get_linear_velocity() + obj.get_acceleration() * delta
146
+ newVel = obj.get_linear_velocity() + Vector3D.to_bullet(obj.get_acceleration()) * delta
139
147
  obj.set_linear_velocity(obj.limit_velocity(newVel))
140
148
  lastVel = obj.get_linear_velocity()
141
149
  end
142
150
  }
143
151
  end
144
152
 
145
- def tickCallback(timeStep)
146
- # print "tickCallback: ", timeStep * 1000, "ms\n"
153
+ def tick_callback(timeStep)
154
+ # print "tick_callback: ", timeStep * 1000, "ms\n"
147
155
  end
148
156
  end
149
157
 
@@ -0,0 +1,57 @@
1
+ module Teien
2
+
3
+ class PhysicsObject
4
+ # Bullet accessor
5
+ attr_accessor :rigid_body # shows the center of this object.
6
+ attr_accessor :transform
7
+ attr_accessor :pivot_shape
8
+ attr_accessor :shape
9
+ attr_accessor :acceleration
10
+ attr_accessor :maxHorizontalVelocity
11
+ attr_accessor :maxVerticalVelocity
12
+
13
+ def initialize(physics)
14
+ @physics = physics
15
+ @rigid_body = nil
16
+ @transform = Bullet::BtTransform.new()
17
+ @transform.set_identity()
18
+ @acceleration = Vector3D.new(0, 0, 0)
19
+
20
+ @maxHorizontalVelocity = 0
21
+ @maxVerticalVelocity = 0
22
+ end
23
+
24
+ def finalize()
25
+ @physics.del_rigid_body(@rigid_body)
26
+ end
27
+
28
+ #
29
+ # The offset changes the local position of the shape(collision shape) in Object.
30
+ #
31
+ def set_rigid_body(obj, shape, inertia, offset = Vector3D.new(0, 0, 0))
32
+ # puts "offset(#{offset.x}, #{offset.y}, #{offset.z})"
33
+ @pivot_shape = Bullet::BtCompoundShape.new
34
+ localTrans = Bullet::BtTransform.new
35
+ localTrans.set_identity()
36
+ localTrans.set_origin(offset)
37
+ @pivot_shape.add_child_shape(localTrans, shape)
38
+ @shape = shape
39
+ # @rigid_body = @physics.create_rigid_body(obj.physics_info.mass, obj, @pivot_shape, inertia)
40
+ @rigid_body = create_rigid_body(obj.physics_info.mass, obj, @pivot_shape, inertia)
41
+ @rigid_body.set_angular_factor(obj.physics_info.angular_factor)
42
+ @rigid_body.set_restitution(obj.physics_info.restitution)
43
+ @rigid_body.set_friction(obj.physics_info.friction)
44
+ @rigid_body.set_damping(obj.physics_info.linear_damping,
45
+ obj.physics_info.angular_damping)
46
+ return @rigid_body
47
+ end
48
+
49
+ def create_rigid_body(mass, motionState, colObj, inertia)
50
+ rigid_body = Bullet::BtRigidBody.new(mass, motionState, colObj, inertia)
51
+ rigid_body.instance_variable_set(:@collision_shape, colObj) # prevent this colObj from GC.
52
+ return rigid_body
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,170 @@
1
+ require 'teien/garden_object'
2
+
3
+ module Teien
4
+
5
+ class PhysicsObjectFactory
6
+ def initialize(physics)
7
+ @physics = physics
8
+ end
9
+
10
+ def create_object(obj)
11
+ case obj.object_info
12
+ when LightObjectInfo
13
+ return create_light_object(obj)
14
+ when FloorObjectInfo
15
+ return create_floor_object(obj)
16
+ when BoxObjectInfo
17
+ return create_box_object(obj)
18
+ when SphereObjectInfo
19
+ return create_sphere_object(obj)
20
+ when CapsuleObjectInfo
21
+ return create_capsule_object(obj)
22
+ when ConeObjectInfo
23
+ return create_cone_object(obj)
24
+ when CylinderObjectInfo
25
+ return create_cylinder_object(obj)
26
+ when MeshBBObjectInfo
27
+ return create_meshBB_object(obj)
28
+ when MeshObjectInfo
29
+ return create_mesh_object(obj)
30
+ else
31
+ puts "Error: passed no supported object_info."
32
+ return nil
33
+ end
34
+ end
35
+
36
+ def create_light_object(obj)
37
+ physics_object = PhysicsObject.new(@physics)
38
+ cShape = Bullet::BtSphereShape.new(0.1)
39
+ inertia = Bullet::BtVector3.new()
40
+ cShape.calculate_local_inertia(0, inertia)
41
+ physics_object.set_rigid_body(obj, cShape, inertia)
42
+ return physics_object
43
+ end
44
+
45
+ #
46
+ # Floor Object
47
+ #
48
+
49
+ # Setting a collision shape and a rigid body of Bullet.
50
+ def create_floor_object(obj)
51
+ physics_object = PhysicsObject.new(@physics)
52
+ cShape = Bullet::BtBoxShape.new(Vector3D.new(obj.object_info.width,
53
+ obj.object_info.depth,
54
+ obj.object_info.height))
55
+ physics_object.set_rigid_body(obj, cShape,
56
+ Vector3D.new(0, 0, 0),
57
+ Vector3D.new(0.0, -obj.object_info.depth, 0.0))
58
+ return physics_object
59
+ end
60
+
61
+ #
62
+ # Box Object
63
+ #
64
+
65
+ def create_box_object(obj)
66
+ physics_object = PhysicsObject.new(@physics)
67
+ cShape = Bullet::BtBoxShape.new(Vector3D.new(obj.object_info.size.x,
68
+ obj.object_info.size.y,
69
+ obj.object_info.size.z))
70
+ inertia = Bullet::BtVector3.new()
71
+ cShape.calculate_local_inertia(obj.physics_info.mass, inertia)
72
+ physics_object.set_rigid_body(obj, cShape, inertia)
73
+ return physics_object
74
+ end
75
+
76
+ #
77
+ # Sphere Object
78
+ #
79
+
80
+ def create_sphere_object(obj)
81
+ physics_object = PhysicsObject.new(@physics)
82
+ cShape = Bullet::BtSphereShape.new(obj.object_info.radius)
83
+ inertia = Bullet::BtVector3.new()
84
+ cShape.calculate_local_inertia(obj.physics_info.mass, inertia)
85
+ physics_object.set_rigid_body(obj, cShape, inertia)
86
+ return physics_object
87
+ end
88
+
89
+ #
90
+ # Capsule Object
91
+ #
92
+
93
+ def create_capsule_object(obj)
94
+ physics_object = PhysicsObject.new(@physics)
95
+ cShape = Bullet::BtCapsuleShape.new(obj.object_info.radius,
96
+ obj.object_info.height)
97
+ inertia = Bullet::BtVector3.new()
98
+ cShape.calculate_local_inertia(obj.physics_info.mass, inertia)
99
+ physics_object.set_rigid_body(obj, cShape, inertia)
100
+ return physics_object
101
+ end
102
+
103
+ #
104
+ # Cone Object
105
+ #
106
+
107
+ def create_cone_object(obj)
108
+ physics_object = PhysicsObject.new(@physics)
109
+ cShape = Bullet::BtConeShape.new(obj.object_info.radius, obj.object_info.height)
110
+ inertia = Bullet::BtVector3.new()
111
+ cShape.calculate_local_inertia(obj.physics_info.mass, inertia)
112
+ physics_object.set_rigid_body(obj, cShape, inertia,
113
+ Vector3D.new(0, obj.object_info.height / 2, 0))
114
+ return physics_object
115
+ end
116
+
117
+ #
118
+ # Cylinder Object
119
+ #
120
+
121
+ def create_cylinder_object(obj)
122
+ physics_object = PhysicsObject.new(@physics)
123
+ cShape = Bullet::BtCylinderShape.new(Bullet::BtVector3.new(obj.object_info.radius,
124
+ obj.object_info.height / 2,
125
+ obj.object_info.radius))
126
+ inertia = Bullet::BtVector3.new()
127
+ cShape.calculate_local_inertia(obj.physics_info.mass, inertia)
128
+ physics_object.set_rigid_body(obj, cShape, inertia)
129
+ return physics_object
130
+ end
131
+
132
+ #
133
+ # MeshBB Object
134
+ #
135
+
136
+ def create_meshBB_object(obj)
137
+ physics_object = PhysicsObject.new(@physics)
138
+ cShape = Bullet::BtBoxShape.new(obj.object_info.size)
139
+ inertia = Bullet::BtVector3.new()
140
+ cShape.calculate_local_inertia(obj.physics_info.mass, inertia)
141
+ physics_object.set_rigid_body(obj, cShape, inertia, obj.object_info.physics_offset)
142
+ return physics_object
143
+ end
144
+
145
+ #
146
+ # Mesh Object
147
+ #
148
+
149
+ # This method needs the obj.entity to create a collision shape.
150
+ # So it's not support to use this method on server(physics only) currently.
151
+ def add_mesh_object(obj)
152
+ physics_object = PhysicsObject.new(@physics)
153
+ strider = Teienlib::MeshStrider.new(obj.entity.get_mesh().get())
154
+ cShape = Bullet::BtGImpactMeshShape.new(strider)
155
+ cShape.set_local_scaling(Bullet::BtVector3.new(obj.object_info.scale.x,
156
+ obj.object_info.scale.y,
157
+ obj.object_info.scale.z))
158
+ cShape.instance_variable_set(:@strider, strider) # prevent this from GC.
159
+ cShape.post_update()
160
+ cShape.update_bound()
161
+ inertia = Bullet::BtVector3.new()
162
+ cShape.calculate_local_inertia(obj.physics_info.mass, inertia)
163
+ physics_object.set_rigid_body(obj, cShape, inertia,
164
+ obj.object_info.physics_offset)
165
+ return physics_object
166
+ end
167
+ end
168
+
169
+
170
+ end
@@ -0,0 +1,118 @@
1
+ require "teien/garden_base.rb"
2
+
3
+ module Teien
4
+
5
+ class ProxyGarden < GardenBase
6
+ attr_accessor :view
7
+ attr_accessor :ui
8
+
9
+ def initialize()
10
+ super
11
+ end
12
+
13
+ def set_window_title(title)
14
+ @view.window_title = title
15
+ end
16
+
17
+ #
18
+ # mainloop
19
+ #
20
+ def run(ip = nil, port = 11922)
21
+ return false unless setup()
22
+
23
+ EM.run do
24
+ EM.add_periodic_timer(0.001) do
25
+ @last_time = Time.now.to_f if @last_time == 0
26
+
27
+ now_time = Time.now.to_f
28
+ delta = now_time - @last_time
29
+ @last_time = now_time
30
+
31
+ unless update(delta)
32
+ EM.stop
33
+ self.finalize()
34
+ end
35
+ end
36
+
37
+ Signal.trap("INT") { EM.stop; self.finalize() }
38
+ Signal.trap("TERM") { EM.stop; self.finalize() }
39
+
40
+ if (ip)
41
+ EM.connect(ip, port, Network, self)
42
+ end
43
+ end
44
+ end
45
+
46
+ def setup()
47
+ @physics.setup(self)
48
+ notify(:setup, self)
49
+ return true
50
+ end
51
+
52
+ def update(delta)
53
+ @physics.update(delta)
54
+ @actors.each_value {|actor|
55
+ actor.update(delta)
56
+ }
57
+ notify(:update, delta)
58
+ return !@quit
59
+ end
60
+
61
+ def receive_event(event, from)
62
+ case event
63
+ when Event::SyncEnv
64
+ # puts "SyncEnv"
65
+ set_gravity(event.gravity)
66
+ set_ambient_light(event.ambient_light_color)
67
+ set_sky_dome(event.sky_dome.enable, event.sky_dome.materialName)
68
+ when Event::SyncObject
69
+ if @objects[event.name]
70
+ # puts "sync"
71
+ sync_object_with_event(event, @objects[event.name])
72
+ else
73
+ # puts "add"
74
+ create_object_from_event(event)
75
+ end
76
+
77
+ end
78
+ notify(:receive_event, event, from)
79
+ end
80
+
81
+ def send_event(event, to = nil)
82
+ if (to)
83
+ to.send_object(event)
84
+ else
85
+ Network::send_all(event)
86
+ end
87
+ end
88
+
89
+ def create_object_from_event(event)
90
+ obj = create_object(event.name, event.object_info, event.physics_info)
91
+ obj.set_position(event.pos)
92
+ obj.set_linear_velocity(event.linear_vel)
93
+ obj.set_angular_velocity(event.angular_vel)
94
+ obj.set_rotation(event.quat)
95
+ obj.set_acceleration(event.accel)
96
+ # obj.animation_info = event.animation_info
97
+ end
98
+
99
+ def sync_object_with_event(event, obj)
100
+ obj.set_position_with_interpolation(event.pos)
101
+ obj.set_linear_velocity(event.linear_vel)
102
+ # obj.set_linear_velocity_with_interpolation(event.linear_vel)
103
+ # obj.set_angular_velocity(event.angular_vel)
104
+ obj.set_angular_velocity_with_interpolation(event.angular_vel)
105
+ obj.set_rotation(event.quat)
106
+ obj.set_acceleration(event.accel)
107
+ # obj.animation_info = event.animation_info
108
+ end
109
+
110
+ # called by Garden class.
111
+ # clear all managers.
112
+ def finalize()
113
+ @physics.finalize()
114
+ @objects = {}
115
+ end
116
+ end
117
+
118
+ end
@@ -0,0 +1,20 @@
1
+ module Teien
2
+
3
+ class RemoteInfo
4
+ @@total_cnt = 0
5
+ attr_accessor :id
6
+ attr_accessor :ip
7
+ attr_accessor :port
8
+ attr_accessor :connection
9
+
10
+ def initialize(con)
11
+ @ip = nil
12
+ @port = 0
13
+ @port, @ip = Socket.unpack_sockaddr_in(con.get_peername) if con.get_peername
14
+ @connection = con
15
+ @id = @@total_cnt
16
+ @@total_cnt += 1
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,15 @@
1
+ class SkyDome
2
+ attr_accessor :enable
3
+ attr_accessor :materialName
4
+ attr_accessor :curvature
5
+ attr_accessor :tiling
6
+ attr_accessor :distance
7
+
8
+ def initialize(enable, materialName, curvature = 10, tiling = 8, distance = 4000)
9
+ @enable = enable
10
+ @materialName = materialName
11
+ @curvature = curvature
12
+ @tiling = tiling
13
+ @distance = distance
14
+ end
15
+ end
@@ -3,22 +3,18 @@ class SmoothMover
3
3
  TURN_SPEED = 500.0
4
4
 
5
5
  attr_accessor :acceleration
6
- attr_accessor :turnSpeed
6
+ attr_accessor :turn_speed
7
7
  attr_accessor :movable
8
8
 
9
- def initialize(targetObject)
10
- @targetObject = targetObject
11
-
9
+ def initialize(target_object)
10
+ @target_object = target_object
12
11
  @acceleration = ACCELERATION
13
- @turnSpeed = TURN_SPEED
14
-
15
- clearAction()
16
-
12
+ @turn_speed = TURN_SPEED
13
+ @move_dir = Ogre::Vector3.new(0, 0, 0)
14
+ @forward_dir = Ogre::Vector3.new(0, 0, 0)
15
+ @zero_vector = Vector3D.new(0, 0, 0)
16
+ clear_action()
17
17
  @movable = true
18
-
19
- @zeroVector = Bullet::BtVector3.new(0, 0, 0)
20
- @moveDir = Ogre::Vector3.new(0, 0, 0)
21
- @cameraDir = Ogre::Vector3.new(0, 0, 0)
22
18
  end
23
19
 
24
20
  def clear_action()
@@ -28,10 +24,17 @@ class SmoothMover
28
24
  @right = false
29
25
  end
30
26
 
31
- def is_move()
27
+ def moving?()
32
28
  return (@forward || @backward || @left || @right)
33
29
  end
34
30
 
31
+ #
32
+ # This direction is the forward.
33
+ #
34
+ def set_forward_direction(forward_dir)
35
+ @forward_dir = forward_dir
36
+ end
37
+
35
38
  def move_forward(bool)
36
39
  @forward = bool
37
40
  end
@@ -48,61 +51,47 @@ class SmoothMover
48
51
  @right = bool
49
52
  end
50
53
 
51
- #
52
- # This direction is the forward.
53
- #
54
- def move_camera_direction(cameraDir)
55
- @cameraDir = cameraDir
56
- end
57
54
 
58
55
  def update_target(delta)
59
- @moveDir.x = 0
60
- @moveDir.y = 0
61
- @moveDir.z = 0
56
+ @move_dir.x = 0
57
+ @move_dir.y = 0
58
+ @move_dir.z = 0
62
59
 
63
60
  # update target's acceleration
64
61
  if (@forward)
65
- @moveDir += Ogre::Vector3.new(@cameraDir.x, @cameraDir.y, @cameraDir.z)
62
+ @move_dir += Ogre::Vector3.new(@forward_dir.x, @forward_dir.y, @forward_dir.z)
66
63
  end
67
64
  if (@backward)
68
- @moveDir += Ogre::Vector3.new(-@cameraDir.x, -@cameraDir.y, -@cameraDir.z)
65
+ @move_dir += Ogre::Vector3.new(-@forward_dir.x, -@forward_dir.y, -@forward_dir.z)
69
66
  end
70
67
  if (@left)
71
- @moveDir += Ogre::Vector3.new(@cameraDir.z, 0, -@cameraDir.x)
68
+ @move_dir += Ogre::Vector3.new(@forward_dir.z, 0, -@forward_dir.x)
72
69
  end
73
70
  if (@right)
74
- @moveDir += Ogre::Vector3.new(-@cameraDir.z, 0, @cameraDir.x)
71
+ @move_dir += Ogre::Vector3.new(-@forward_dir.z, 0, @forward_dir.x)
75
72
  end
76
73
 
77
- @moveDir.y = 0
78
- @moveDir.normalise()
74
+ @move_dir.y = 0
75
+ @move_dir.normalise()
79
76
 
80
77
  if (@movable)
81
- newAcc = @moveDir * @acceleration
82
- @targetObject.set_acceleration(Vector3D::to_bullet(newAcc))
78
+ newAcc = @move_dir * @acceleration
79
+ @target_object.set_acceleration(Vector3D.to_self(newAcc))
83
80
  else
84
- @targetObject.set_acceleration(@zeroVector)
81
+ @target_object.set_acceleration(@zero_vector)
85
82
  end
86
83
 
87
84
  # update target's direction
88
- =begin
89
- ogreDir = -@targetObject.pivotSceneNode.getOrientation().zAxis()
90
- bulletDir = -@targetObject.getOrientation().zAxis()
91
- puts "OgreDir: (#{ogreDir.x}, #{ogreDir.y}, #{ogreDir.z})"
92
- puts "BulletDir: (#{bulletDir.x}, #{bulletDir.y}, #{bulletDir.z})"
93
- =end
94
-
95
- toGoal = Vector3D.to_ogre(-@targetObject.get_orientation().z_axis()).get_rotation_to(@moveDir)
85
+ toGoal = Vector3D.to_ogre(-@target_object.get_orientation().z_axis()).get_rotation_to(@move_dir)
96
86
  yawToGoal = toGoal.get_yaw().value_degrees()
97
- yawAtSpeed = yawToGoal / yawToGoal.abs * delta * @turnSpeed
87
+ yawAtSpeed = yawToGoal / yawToGoal.abs * delta * @turn_speed
98
88
 
99
89
  if (yawToGoal < 0)
100
90
  yawToGoal = [0, [yawToGoal, yawAtSpeed].max].min
101
-
102
91
  elsif (yawToGoal > 0)
103
92
  yawToGoal = [0, [yawToGoal, yawAtSpeed].min].max
104
93
  end
105
94
 
106
- @targetObject.yaw(Ogre::Degree.new(yawToGoal).value_radians())
95
+ @target_object.yaw(Ogre::Degree.new(yawToGoal).value_radians())
107
96
  end
108
97
  end
@@ -0,0 +1,26 @@
1
+ module Teien
2
+
3
+ class Synchronizer
4
+ def initialize(garden, sync_period)
5
+ @garden = garden
6
+ @garden.register_receiver(self)
7
+ @sync_period = sync_period
8
+ @sync_timer = sync_period
9
+ end
10
+
11
+ def setup(garden)
12
+ end
13
+
14
+ def update(delta)
15
+ @sync_timer += delta
16
+ if (@sync_timer > @sync_period)
17
+ @garden.notify_objects()
18
+ @sync_timer = 0
19
+ end
20
+ end
21
+
22
+ def add_actor(actor)
23
+ end
24
+ end
25
+
26
+ end