teien 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -5
- data/bin/teien +36 -37
- data/lib/teien/{smooth_mover.rb → action_model/smooth_moving.rb} +19 -3
- data/lib/teien/actor/actor.rb +21 -0
- data/{sample/actor/app/helpers/user_event.rb → lib/teien/actor/actor_event.rb} +41 -32
- data/lib/teien/actor/actor_factory.rb +20 -0
- data/lib/teien/actor/actor_info.rb +7 -0
- data/lib/teien/actor/actor_manager.rb +31 -0
- data/lib/teien/actor/actor_manager_proxy.rb +72 -0
- data/lib/teien/addon/addon.rb +25 -0
- data/lib/teien/{animation.rb → animation/animation.rb} +1 -0
- data/lib/teien/animation/animation_event.rb +17 -0
- data/lib/teien/animation/animation_manager.rb +23 -0
- data/lib/teien/animation/animation_manager_proxy.rb +27 -0
- data/lib/teien/application/application.rb +43 -0
- data/lib/teien/base_object/attachment_info.rb +15 -0
- data/lib/teien/{garden_object.rb → base_object/base_object.rb} +43 -52
- data/lib/teien/{event.rb → base_object/base_object_event.rb} +9 -12
- data/lib/teien/base_object/base_object_manager.rb +57 -0
- data/lib/teien/{garden_base.rb → base_object/base_object_manager_base.rb} +22 -31
- data/lib/teien/{proxy_garden.rb → base_object/base_object_manager_proxy.rb} +20 -62
- data/lib/teien/base_object/object_info.rb +21 -0
- data/lib/teien/{physics.rb → base_object/physics.rb} +4 -5
- data/lib/teien/{physics_info.rb → base_object/physics_info.rb} +1 -0
- data/lib/teien/base_object/physics_object_factory.rb +23 -0
- data/lib/teien/base_object/std_objects/box_object_info.rb +42 -0
- data/lib/teien/base_object/std_objects/capsule_object_info.rb +44 -0
- data/lib/teien/base_object/std_objects/cone_object_info.rb +41 -0
- data/lib/teien/base_object/std_objects/cylinder_object_info.rb +44 -0
- data/lib/teien/base_object/std_objects/floor_object_info.rb +45 -0
- data/lib/teien/base_object/std_objects/light_object_info.rb +40 -0
- data/lib/teien/base_object/std_objects/mesh_bb_object_info.rb +42 -0
- data/lib/teien/base_object/std_objects/mesh_object_info.rb +62 -0
- data/lib/teien/base_object/std_objects/sphere_object_info.rb +38 -0
- data/lib/teien/commands/browser_command.rb +46 -0
- data/lib/teien/commands/local_command.rb +21 -0
- data/lib/teien/commands/server_command.rb +39 -0
- data/lib/teien/commands/std_command.rb +71 -0
- data/lib/teien/core/client_network.rb +26 -0
- data/lib/teien/core/component_manager.rb +11 -0
- data/lib/teien/core/core_event.rb +7 -0
- data/lib/teien/core/dispatcher.rb +30 -0
- data/lib/teien/core/event_router.rb +116 -0
- data/lib/teien/core/launcher.rb +31 -0
- data/lib/teien/core/network.rb +28 -0
- data/lib/teien/{remote_info.rb → core/remote_info.rb} +6 -1
- data/lib/teien/core/server_network.rb +23 -0
- data/lib/teien/{tools.rb → core/tools.rb} +2 -2
- data/lib/teien/{camera.rb → ui/camera.rb} +1 -1
- data/lib/teien/{camera_mover.rb → ui/camera_mover.rb} +1 -2
- data/lib/teien/ui/std_objects/box_object_info.rb +29 -0
- data/lib/teien/ui/std_objects/capsule_object_info.rb +28 -0
- data/lib/teien/ui/std_objects/cone_object_info.rb +25 -0
- data/lib/teien/ui/std_objects/cylinder_object_info.rb +26 -0
- data/lib/teien/ui/std_objects/floor_object_info.rb +34 -0
- data/lib/teien/ui/std_objects/light_object_info.rb +23 -0
- data/lib/teien/ui/std_objects/mesh_bb_object_info.rb +24 -0
- data/lib/teien/ui/std_objects/mesh_object_info.rb +24 -0
- data/lib/teien/ui/std_objects/sphere_object_info.rb +26 -0
- data/lib/teien/{user_interface.rb → ui/user_interface.rb} +18 -13
- data/lib/teien/{view.rb → ui/view.rb} +42 -20
- data/lib/teien/ui/view_object.rb +142 -0
- data/lib/teien/ui/view_object_factory.rb +23 -0
- data/lib/teien/version.rb +1 -1
- data/lib/teien.rb +3 -78
- data/mods/actor/addons/sinbad/lib/sinbad/sinbad_info.rb +16 -0
- data/{sample/actor/app/helpers → mods/actor/addons/sinbad/lib}/sinbad/sinbad_state.rb +14 -39
- data/mods/actor/addons/sinbad/lib/sinbad.rb +180 -0
- data/mods/actor/apps/browser/browser_application.rb +185 -0
- data/mods/actor/apps/common/browser_event.rb +68 -0
- data/mods/actor/apps/server/server_application.rb +101 -0
- data/{sample/actor/app/ais → mods/actor/commands/ai}/actor_ai.rb +8 -3
- data/mods/actor/commands/ai_command.rb +20 -0
- data/{sample/actor/config → mods/actor/configs}/plugins.cfg +4 -4
- data/{sample/hello_garden/app/controllers/hello_garden_controller.rb → mods/hello_garden/apps/browser/browser_application.rb} +48 -25
- data/mods/hello_garden/apps/common/browser_event.rb +58 -0
- data/{sample/hello_garden/app/models/hello_garden_model.rb → mods/hello_garden/apps/server/server_application.rb} +35 -26
- data/teien.gemspec +3 -1
- metadata +114 -55
- data/lib/teien/ai.rb +0 -27
- data/lib/teien/controller.rb +0 -30
- data/lib/teien/dispatcher.rb +0 -22
- data/lib/teien/event_router.rb +0 -118
- data/lib/teien/garden.rb +0 -91
- data/lib/teien/model.rb +0 -34
- data/lib/teien/network.rb +0 -108
- data/lib/teien/object_info.rb +0 -192
- data/lib/teien/physics_object_factory.rb +0 -170
- data/lib/teien/synchronizer.rb +0 -26
- data/lib/teien/view_object.rb +0 -67
- data/lib/teien/view_object_factory.rb +0 -210
- data/sample/actor/app/controllers/actor_controller.rb +0 -182
- data/sample/actor/app/helpers/sinbad/sinbad.rb +0 -176
- data/sample/actor/app/models/actor_model.rb +0 -108
- data/sample/hello_garden/app/helpers/user_event.rb +0 -12
- /data/lib/teien/{animation_operator.rb → animation/animation_operator.rb} +0 -0
- /data/lib/teien/{physics_object.rb → base_object/physics_object.rb} +0 -0
- /data/lib/teien/{sky_dome.rb → base_object/sky_dome.rb} +0 -0
- /data/lib/teien/{ui_listener.rb → ui/ui_listener.rb} +0 -0
- /data/{sample/actor/config → mods/actor/configs}/resources.cfg +0 -0
- /data/{sample/hello_garden/config → mods/hello_garden/configs}/plugins.cfg +0 -0
- /data/{sample/hello_garden/config → mods/hello_garden/configs}/resources.cfg +0 -0
- /data/{sample → mods}/hello_garden/run +0 -0
@@ -0,0 +1,142 @@
|
|
1
|
+
require "teien/animation/animation_operator.rb"
|
2
|
+
|
3
|
+
module Teien
|
4
|
+
|
5
|
+
class ViewObject
|
6
|
+
# Ogre3D accessor
|
7
|
+
## center of view objects(sceneNode) and kept to equal with the rigid_body position.
|
8
|
+
attr_accessor :pivot_scene_node
|
9
|
+
attr_accessor :scene_node
|
10
|
+
attr_accessor :entity
|
11
|
+
attr_accessor :animation_operators
|
12
|
+
|
13
|
+
attr_accessor :object
|
14
|
+
|
15
|
+
def initialize(view)
|
16
|
+
@view = view
|
17
|
+
@pivot_scene_node = nil
|
18
|
+
@scene_node = nil
|
19
|
+
@entity = nil
|
20
|
+
@animation_operators = Hash.new
|
21
|
+
@attached_objects = Hash.new
|
22
|
+
@base_object_manager = Teien::get_component("base_object_manager")
|
23
|
+
end
|
24
|
+
|
25
|
+
def finalize()
|
26
|
+
@pivot_scene_node.remove_child(@scene_node)
|
27
|
+
@view.scene_mgr.destroySceneNode(@scene_node)
|
28
|
+
@view.scene_mgr.get_root_scene_node.remove_child(@pivot_scene_node)
|
29
|
+
@view.scene_mgr.destroySceneNode(@pivot_scene_node)
|
30
|
+
@view.scene_mgr.destroyEntity(@entity)
|
31
|
+
end
|
32
|
+
|
33
|
+
def update_attached_objects(view)
|
34
|
+
# attached
|
35
|
+
@object.attached_objects.each_pair {|key, info|
|
36
|
+
unless @attached_objects[key]
|
37
|
+
attached_object = @base_object_manager.objects[info.object_name]
|
38
|
+
attached_entity = view.objects[attached_object.name].entity
|
39
|
+
attached_scene_node = view.objects[attached_object.name].scene_node
|
40
|
+
|
41
|
+
puts "attached: #{info.bone_name}, #{attached_entity}"
|
42
|
+
|
43
|
+
attached_scene_node.detach_object(attached_entity)
|
44
|
+
tag = @entity.attach_object_to_bone(info.bone_name, attached_entity)
|
45
|
+
# @manager.physics.dynamics_world.remove_rigid_body(obj.rigid_body)
|
46
|
+
attached_object.mode = Teien::BaseObject::MODE_ATTACHED
|
47
|
+
@attached_objects[key] = info
|
48
|
+
end
|
49
|
+
}
|
50
|
+
|
51
|
+
# detached
|
52
|
+
@attached_objects.each_pair {|key, info|
|
53
|
+
unless @object.attached_objects[key]
|
54
|
+
detached_object = @base_object_manager.objects[info.object_name]
|
55
|
+
detached_entity = view.objects[detached_object.name]
|
56
|
+
detached_scene_node = view.objects[detached_object.name].scene_node
|
57
|
+
|
58
|
+
@entity.detach_object_from_bone(detached_entity)
|
59
|
+
detached_scene_node.attach_object(obj.entity)
|
60
|
+
=begin
|
61
|
+
if obj.physics_info.collision_filter
|
62
|
+
@manager.physics.dynamics_world.add_rigid_body(obj.rigid_body,
|
63
|
+
obj.physics_info.collision_filter.group,
|
64
|
+
obj.physics_info.collision_filter.mask)
|
65
|
+
else
|
66
|
+
@manager.physics.dynamics_world.add_rigid_body(obj.rigid_body)
|
67
|
+
end
|
68
|
+
=end
|
69
|
+
detached_object.mode = Teien::BaseObject::MODE_FREE
|
70
|
+
@attached_objects.delete(key)
|
71
|
+
end
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def update_animation(delta, animation)
|
78
|
+
animation.operators.each_pair{|key, value|
|
79
|
+
unless @animation_operators[key]
|
80
|
+
@entity.get_skeleton().set_blend_mode(animation.blend_mode)
|
81
|
+
ani_ope = AnimationOperator.new(@entity)
|
82
|
+
ani_ope.init(value.name, value.loop)
|
83
|
+
@animation_operators[key] = ani_ope
|
84
|
+
end
|
85
|
+
|
86
|
+
if (value.name != @animation_operators[key].name ||
|
87
|
+
value.loop != @animation_operators[key].loop)
|
88
|
+
@animation_operators[key].play(value.name, value.loop)
|
89
|
+
end
|
90
|
+
@animation_operators[key].add_time(delta * value.speed)
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# The offset changes the local position of the created scene_node in Object.
|
96
|
+
#
|
97
|
+
def set_scene_node(entity, offset = Vector3D.new(0, 0, 0), rotate = Quaternion.new(0, 0, 0, 1.0))
|
98
|
+
if (@pivot_scene_node == nil)
|
99
|
+
@pivot_scene_node = @view.scene_mgr.get_root_scene_node().create_child_scene_node()
|
100
|
+
end
|
101
|
+
@scene_node = @pivot_scene_node.create_child_scene_node(Vector3D.to_ogre(offset),
|
102
|
+
Quaternion.to_ogre(rotate))
|
103
|
+
@pivot_scene_node.instance_variable_set(:@child, @scene_node) # prevent this from GC.
|
104
|
+
|
105
|
+
if entity
|
106
|
+
@scene_node.attach_object(entity)
|
107
|
+
@entity = entity
|
108
|
+
end
|
109
|
+
|
110
|
+
return @scene_node
|
111
|
+
end
|
112
|
+
|
113
|
+
#
|
114
|
+
# handlers of BaseObject
|
115
|
+
|
116
|
+
def set_position(aPos)
|
117
|
+
if @pivot_scene_node
|
118
|
+
@pivot_scene_node.set_position(aPos.x, aPos.y, aPos.z)
|
119
|
+
else
|
120
|
+
# object_info.class == LightObjectInfo
|
121
|
+
@entity.set_position(Vector3D.to_ogre(aPos))
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def set_world_transform(transform)
|
126
|
+
newPos = transform.get_origin()
|
127
|
+
newRot = transform.get_rotation()
|
128
|
+
# puts "newRot(#{id}: #{newRot.x}, #{newRot.y}, #{newRot.z}, #{newRot.w})"
|
129
|
+
# puts "newPos(#{id}: #{newPos.x}, #{newPos.y}, #{newPos.z})"
|
130
|
+
|
131
|
+
return if (newRot.x.nan?)
|
132
|
+
|
133
|
+
@pivot_scene_node.set_position(newPos.x, newPos.y, newPos.z)
|
134
|
+
@pivot_scene_node.set_orientation(newRot.w, newRot.x, newRot.y, newRot.z)
|
135
|
+
end
|
136
|
+
|
137
|
+
def set_rotation(rot)
|
138
|
+
@pivot_scene_node.set_orientation(Quaternion.to_ogre(rot))
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'teien/base_object/base_object'
|
2
|
+
require 'teien/ui/view_object'
|
3
|
+
|
4
|
+
module Teien
|
5
|
+
|
6
|
+
class ViewObjectFactory
|
7
|
+
@creators = Hash.new
|
8
|
+
|
9
|
+
def self.create_object(obj, view)
|
10
|
+
if @creators[obj.object_info.class] != nil
|
11
|
+
return @creators[obj.object_info.class].call(obj, view)
|
12
|
+
else
|
13
|
+
puts "not a supported object: #{obj.object_info.class}"
|
14
|
+
return nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.set_creator(info_klass, creator)
|
19
|
+
@creators[info_klass] = creator
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/teien/version.rb
CHANGED
data/lib/teien.rb
CHANGED
@@ -7,82 +7,7 @@ require "ois.so"
|
|
7
7
|
require "ogrebites.so"
|
8
8
|
require "teienlib.so"
|
9
9
|
|
10
|
-
require "teien/tools.rb"
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require 'teien/animation'
|
14
|
-
require 'teien/smooth_mover'
|
15
|
-
require "teien/garden.rb"
|
16
|
-
require "teien/model.rb"
|
17
|
-
require "teien/controller.rb"
|
18
|
-
require "teien/ai.rb"
|
10
|
+
require "teien/core/tools.rb"
|
11
|
+
require "teien/core/component_manager"
|
12
|
+
require "teien/core/event_router"
|
19
13
|
|
20
|
-
module Teien
|
21
|
-
|
22
|
-
def self.start_server_garden(ip, port, sync_period = 0.5)
|
23
|
-
require "teien/synchronizer"
|
24
|
-
|
25
|
-
cwd = Dir.getwd
|
26
|
-
Dir.glob("#{cwd}/app/models/*.rb") {|file|
|
27
|
-
require "#{file}"
|
28
|
-
}
|
29
|
-
|
30
|
-
garden = Teien::Garden.new()
|
31
|
-
Teien::Model::load(garden)
|
32
|
-
# garden_script = garden_script_klass.new(garden)
|
33
|
-
sync = Synchronizer.new(garden, sync_period)
|
34
|
-
garden.run(ip, port)
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.start_client_garden(ip, port)
|
38
|
-
require "teien/proxy_garden.rb"
|
39
|
-
require 'teien/user_interface'
|
40
|
-
|
41
|
-
cwd = Dir.getwd
|
42
|
-
Dir.glob("#{cwd}/app/controllers/*.rb") {|file|
|
43
|
-
require "#{file}"
|
44
|
-
}
|
45
|
-
|
46
|
-
garden = Teien::ProxyGarden.new()
|
47
|
-
ui = Teien::UserInterface.new(garden)
|
48
|
-
Teien::Controller::load(garden, ui)
|
49
|
-
# controller_script = controller_script_klass.new(garden, ui)
|
50
|
-
garden.run(ip, port)
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.start_ai_garden(ip, port)
|
54
|
-
require "teien/proxy_garden.rb"
|
55
|
-
|
56
|
-
cwd = Dir.getwd
|
57
|
-
Dir.glob("#{cwd}/app/ais/*.rb") {|file|
|
58
|
-
require "#{file}"
|
59
|
-
}
|
60
|
-
|
61
|
-
garden = Teien::ProxyGarden.new()
|
62
|
-
Teien::Ai::load(garden)
|
63
|
-
garden.run(ip, port)
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
def self.start_local_garden()
|
68
|
-
require_relative 'teien/user_interface'
|
69
|
-
|
70
|
-
pid = Process.fork {
|
71
|
-
start_server_garden("0.0.0.0", 11922, 0.1)
|
72
|
-
}
|
73
|
-
begin
|
74
|
-
start_client_garden("0.0.0.0", 11922)
|
75
|
-
ensure
|
76
|
-
Process.kill("TERM", pid)
|
77
|
-
end
|
78
|
-
|
79
|
-
=begin
|
80
|
-
garden = Teien::Garden.new()
|
81
|
-
ui = Teien::UserInterface.new(garden)
|
82
|
-
garden_script = garden_script_klass.new(garden)
|
83
|
-
controller_script = controller_script_klass.new(garden, ui)
|
84
|
-
garden.run
|
85
|
-
=end
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "teien/actor/actor_info"
|
2
|
+
|
3
|
+
class SinbadInfo < Teien::ActorInfo
|
4
|
+
attr_accessor :object_name
|
5
|
+
|
6
|
+
def initialize(actor_name)
|
7
|
+
@actor_name = actor_name
|
8
|
+
@object_name = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.create_actor(sinbad_info)
|
12
|
+
Sinbad.new(sinbad_info)
|
13
|
+
end
|
14
|
+
|
15
|
+
Teien::ActorFactory::register_creator(self, self.method(:create_actor))
|
16
|
+
end
|
@@ -5,13 +5,11 @@ class SinbadState
|
|
5
5
|
@stateHash = {}
|
6
6
|
@stateHash["Stop"] = Stop.new(parent)
|
7
7
|
@stateHash["Run"] = Run.new(parent)
|
8
|
-
@stateHash["GravityFree"] = GravityFree.new(parent)
|
9
8
|
@stateHash["InAir"] = InAir.new(parent)
|
10
9
|
@stateHash["Jump"] = Jump.new(parent)
|
11
10
|
@stateHash["JumpLoop"] = JumpLoop.new(parent)
|
12
11
|
@stateHash["JumpEnd"] = JumpEnd.new(parent)
|
13
12
|
set_state("Stop")
|
14
|
-
|
15
13
|
end
|
16
14
|
|
17
15
|
def set_state(state)
|
@@ -20,9 +18,7 @@ class SinbadState
|
|
20
18
|
@state.fini() if (@state != nil)
|
21
19
|
@prevState = @state
|
22
20
|
@state = nextState
|
23
|
-
|
24
|
-
puts state
|
25
|
-
|
21
|
+
# puts state
|
26
22
|
@state.init() if(@state != nil)
|
27
23
|
return true
|
28
24
|
end
|
@@ -58,7 +54,7 @@ class SinbadState
|
|
58
54
|
def init()
|
59
55
|
@parent.play_top_animation("IdleTop")
|
60
56
|
@parent.play_base_animation("IdleBase")
|
61
|
-
|
57
|
+
@parent.object.set_damping(0.9, 0)
|
62
58
|
end
|
63
59
|
def update(delta)
|
64
60
|
unless @parent.check_on_ground()
|
@@ -83,11 +79,16 @@ class SinbadState
|
|
83
79
|
def init()
|
84
80
|
@parent.play_top_animation("RunTop")
|
85
81
|
@parent.play_base_animation("RunBase")
|
86
|
-
|
82
|
+
@parent.object.set_damping(0.0, 0)
|
87
83
|
@parent.object.set_max_horizontal_velocity(17.0)
|
88
84
|
end
|
89
85
|
|
90
86
|
def update(delta)
|
87
|
+
unless @parent.check_on_ground()
|
88
|
+
@parent.state.set_state("InAir")
|
89
|
+
return
|
90
|
+
end
|
91
|
+
|
91
92
|
@parent.mover.update_target(delta)
|
92
93
|
unless (@parent.mover.moving?())
|
93
94
|
@parent.state.set_state("Stop")
|
@@ -98,33 +99,6 @@ class SinbadState
|
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
101
|
-
class GravityFree
|
102
|
-
def initialize(parent)
|
103
|
-
@parent = parent
|
104
|
-
end
|
105
|
-
|
106
|
-
def init()
|
107
|
-
@parent.play_top_animation("IdleTop")
|
108
|
-
@parent.play_base_animation("IdleBase")
|
109
|
-
# @parent.object.set_damping(0, 0)
|
110
|
-
|
111
|
-
grav = @parent.object.get_gravity()
|
112
|
-
puts "gravity: (#{grav.x}, #{grav.y}, #{grav.z})"
|
113
|
-
@parent.object.set_gravity(Vector3D.new(0, 0, 0))
|
114
|
-
|
115
|
-
@parent.mover = @parent.grav_mover
|
116
|
-
end
|
117
|
-
|
118
|
-
def update(delta)
|
119
|
-
@parent.mover.update_target(delta)
|
120
|
-
end
|
121
|
-
|
122
|
-
def fini()
|
123
|
-
@parent.object.set_gravity(Vector3D.new(0, -9.8, 0))
|
124
|
-
@parent.mover = @parent.sm_mover
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
102
|
class InAir
|
129
103
|
def initialize(parent)
|
130
104
|
@parent = parent
|
@@ -133,7 +107,7 @@ class SinbadState
|
|
133
107
|
def init()
|
134
108
|
@parent.play_top_animation("IdleTop")
|
135
109
|
@parent.play_base_animation("IdleBase")
|
136
|
-
|
110
|
+
@parent.object.set_damping(0, 0)
|
137
111
|
|
138
112
|
@parent.object.set_gravity(Vector3D.new(0, -9.8, 0))
|
139
113
|
end
|
@@ -156,10 +130,11 @@ class SinbadState
|
|
156
130
|
def init()
|
157
131
|
@parent.play_top_animation("IdleTop")
|
158
132
|
@parent.play_base_animation("JumpStart")
|
159
|
-
|
133
|
+
@parent.object.set_damping(0, 0)
|
160
134
|
|
161
135
|
@parent.object.set_gravity(Vector3D.new(0, -9.8, 0))
|
162
|
-
@parent.object.set_acceleration(Vector3D.new(0, 39.8, 0))
|
136
|
+
# @parent.object.set_acceleration(Vector3D.new(0, 39.8, 0))
|
137
|
+
@parent.object.set_acceleration(Vector3D.new(0, 60, 0))
|
163
138
|
@timer = 0
|
164
139
|
end
|
165
140
|
|
@@ -184,7 +159,7 @@ class SinbadState
|
|
184
159
|
def init()
|
185
160
|
@parent.play_top_animation("IdleTop")
|
186
161
|
@parent.play_base_animation("JumpLoop")
|
187
|
-
|
162
|
+
@parent.object.set_damping(0, 0)
|
188
163
|
@parent.object.set_acceleration(Vector3D.new(0, 0.0, 0))
|
189
164
|
end
|
190
165
|
|
@@ -207,7 +182,7 @@ class SinbadState
|
|
207
182
|
def init()
|
208
183
|
@parent.play_top_animation("IdleTop")
|
209
184
|
@parent.play_base_animation("JumpEnd")
|
210
|
-
|
185
|
+
@parent.object.set_damping(0, 0)
|
211
186
|
|
212
187
|
@parent.object.set_gravity(Vector3D.new(0, -9.8, 0))
|
213
188
|
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require_relative "sinbad/sinbad_state"
|
2
|
+
require_relative "sinbad/sinbad_info"
|
3
|
+
|
4
|
+
class ClosestNotMe < Bullet::ClosestRayResultCallback
|
5
|
+
def initialize(rb)
|
6
|
+
super(Bullet::BtVector3.new(0.0, 0.0, 0.0), Bullet::BtVector3.new(0.0, 0.0, 0.0))
|
7
|
+
@rigidBody = rb
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_single_result(rayResult, normalInWorldSpace)
|
11
|
+
return 1.0 if (rayResult.m_collisionObject == @rigedBody)
|
12
|
+
return super(rayResult, normalInWorldSpace)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
include Teien
|
18
|
+
|
19
|
+
require "teien/action_model/smooth_moving"
|
20
|
+
|
21
|
+
class Sinbad < Teien::Actor
|
22
|
+
attr_accessor :object
|
23
|
+
attr_accessor :actor
|
24
|
+
attr_accessor :mover
|
25
|
+
attr_accessor :state
|
26
|
+
|
27
|
+
def initialize(sinbad_info)
|
28
|
+
@base_object_manager = Teien::get_component("base_object_manager")
|
29
|
+
|
30
|
+
build_object(sinbad_info)
|
31
|
+
|
32
|
+
@mover = SmoothMoving.new(@object.name)
|
33
|
+
@mover.acceleration = 50
|
34
|
+
|
35
|
+
@state = SinbadState.new(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
def finalize()
|
39
|
+
@base_object_manager.objects.delete(@object.name)
|
40
|
+
@base_object_manager.objects.delete("SinbadSword1")
|
41
|
+
@base_object_manager.objects.delete("SinbadSword2")
|
42
|
+
@object.finalize()
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def dump_event()
|
47
|
+
return Event::SyncSinbad.new(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def self.load_event(base_object_manager, actors, event)
|
52
|
+
actor = actors[event.actor_name]
|
53
|
+
if actor == nil
|
54
|
+
actor = Sinbad.new(base_object_manager, event.actor_name)
|
55
|
+
else
|
56
|
+
actor = actors[event.actor_name]
|
57
|
+
end
|
58
|
+
|
59
|
+
return actor
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_object(sinbad_info)
|
63
|
+
@name = sinbad_info.actor_name
|
64
|
+
|
65
|
+
if sinbad_info.object_name
|
66
|
+
@object = @base_object_manager.objects[sinbad_info.object_name]
|
67
|
+
@animation = Teien::get_component("animation_manager").animations[@object.name]
|
68
|
+
else
|
69
|
+
object_info = MeshBBObjectInfo.new("sinbad.mesh", Vector3D.new(1.0, 1.0, 1.0))
|
70
|
+
object_info.scale = Vector3D.new(1.0 / 2.0, 1.0 / 2.0, 1.0 / 2.0)
|
71
|
+
object_info.physics_offset = Vector3D.new(0, 1.0, 0)
|
72
|
+
object_info.view_offset = Vector3D.new(0, 2.5, 0)
|
73
|
+
object_info.view_rotation = Quaternion.new(Vector3D.new(0, 1, 0), Ogre::Degree.new(180.0).value_radians)
|
74
|
+
physics_info = PhysicsInfo.new(1.0)
|
75
|
+
physics_info.angular_factor = 0
|
76
|
+
physics_info.restitution = 0.5
|
77
|
+
physics_info.friction = 0.5
|
78
|
+
physics_info.linear_damping = 0.5
|
79
|
+
physics_info.angular_damping = 0
|
80
|
+
@object = @base_object_manager.create_object(@name, object_info, physics_info)
|
81
|
+
@object.set_position(Vector3D.new(0, 0, 0))
|
82
|
+
|
83
|
+
event = Teien::Event::BaseObject::SyncObject.new(@object)
|
84
|
+
Teien::get_component("event_router").send_event(event)
|
85
|
+
|
86
|
+
@animation = Teien::get_component("animation_manager").create_animation(@object.name)
|
87
|
+
@animation.create_operator("TopAnim", "IdeleTop", 1.0, true)
|
88
|
+
@animation.create_operator("BaseAnim", "IdleBase", 1.0, true)
|
89
|
+
@animation.create_operator("HandsAnim", "HandsRelaxed", 1.0, true)
|
90
|
+
|
91
|
+
event = Teien::Event::Animation::SyncAnimation.new(@object.name, @animation)
|
92
|
+
Teien::get_component("event_router").send_event(event)
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
# swords
|
97
|
+
object_info = MeshObjectInfo.new("Sword.mesh")
|
98
|
+
object_info.scale = Vector3D.new(1.0 / 2.0, 1.0 / 2.0, 1.0 / 2.0)
|
99
|
+
@sword1 = @base_object_manager.create_object("SinbadSword1", object_info)
|
100
|
+
@object.attach_object_to_bone("Sheath.L", @sword1)
|
101
|
+
|
102
|
+
object_info = MeshObjectInfo.new("Sword.mesh")
|
103
|
+
object_info.scale = Vector3D.new(1.0 / 2.0, 1.0 / 2.0, 1.0 / 2.0)
|
104
|
+
@sword2 = @base_object_manager.create_object("SinbadSword2", object_info)
|
105
|
+
@object.attach_object_to_bone("Sheath.R", @sword2)
|
106
|
+
end
|
107
|
+
|
108
|
+
def receive_event(event, from)
|
109
|
+
end
|
110
|
+
|
111
|
+
def update(delta)
|
112
|
+
@state.update(delta) if @state
|
113
|
+
end
|
114
|
+
|
115
|
+
def check_on_ground()
|
116
|
+
rayCallback = ClosestNotMe.new(@object.physics_object.rigid_body)
|
117
|
+
rayCallback.m_closestHitFraction = 1.0
|
118
|
+
src = @object.get_position() + Vector3D.new(0, 0.1, 0)
|
119
|
+
tgt = src + Vector3D.new(0, -0.2, 0)
|
120
|
+
|
121
|
+
# puts "src(#{src.x}, #{src.y}, #{src.z})"
|
122
|
+
# puts "tgt(#{tgt.x}, #{tgt.y}, #{tgt.z})"
|
123
|
+
|
124
|
+
@base_object_manager.physics.dynamics_world.ray_test(src, tgt, rayCallback)
|
125
|
+
return true if (rayCallback.has_hit())
|
126
|
+
return false
|
127
|
+
end
|
128
|
+
|
129
|
+
def set_forward_direction(dir)
|
130
|
+
@mover.set_forward_direction(dir)
|
131
|
+
end
|
132
|
+
|
133
|
+
def move_forward(bl)
|
134
|
+
@mover.move_forward(bl)
|
135
|
+
end
|
136
|
+
|
137
|
+
def move_backward(bl)
|
138
|
+
@mover.move_backward(bl)
|
139
|
+
end
|
140
|
+
|
141
|
+
def move_left(bl)
|
142
|
+
@mover.move_left(bl)
|
143
|
+
end
|
144
|
+
|
145
|
+
def move_right(bl)
|
146
|
+
@mover.move_right(bl)
|
147
|
+
end
|
148
|
+
|
149
|
+
def jump(bl)
|
150
|
+
if bl
|
151
|
+
unless @state.state?("JumpLoop")
|
152
|
+
@state.set_state("Jump")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def action_left()
|
158
|
+
@object.detach_object_from_bone(@sword1)
|
159
|
+
#@state.set_state("Kick")
|
160
|
+
end
|
161
|
+
|
162
|
+
def action_right
|
163
|
+
@state.set_state("Attack")
|
164
|
+
end
|
165
|
+
|
166
|
+
def play_top_animation(name, loop = true)
|
167
|
+
@animation.operators["TopAnim"].name = name
|
168
|
+
@animation.operators["TopAnim"].loop = loop
|
169
|
+
end
|
170
|
+
|
171
|
+
def play_base_animation(name, loop = true)
|
172
|
+
@animation.operators["BaseAnim"].name = name
|
173
|
+
@animation.operators["BaseAnim"].loop = loop
|
174
|
+
end
|
175
|
+
|
176
|
+
def play_hands_animation(name, loop = true)
|
177
|
+
@animation.operators["HandsAnim"].name = name
|
178
|
+
@animation.operators["HnadsAnim"].loop = loop
|
179
|
+
end
|
180
|
+
end
|