teien 0.0.1

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.
@@ -0,0 +1,68 @@
1
+ module Teien
2
+ #
3
+ # Key Listener
4
+ #
5
+ class KeyListener < OIS::KeyListener
6
+ def initialize(listener)
7
+ super()
8
+ @listener = listener
9
+ end
10
+
11
+ def keyPressed(key_event)
12
+ return @listener.key_pressed(key_event)
13
+ end
14
+
15
+ def keyReleased(key_event)
16
+ return @listener.key_released(key_event)
17
+ end
18
+ end
19
+
20
+ #
21
+ # Mouse Listener
22
+ #
23
+ class MouseListener < OIS::MouseListener
24
+ def initialize(listener)
25
+ super()
26
+ @listener = listener
27
+ end
28
+
29
+ def mouseMoved(evt)
30
+ return @listener.mouse_moved(evt)
31
+ end
32
+
33
+ def mousePressed(mouse_event, mouse_button_ID)
34
+ return @listener.mouse_pressed(mouse_event, mouse_button_ID)
35
+ end
36
+
37
+ def mouseReleased(mouse_event, mouse_button_ID)
38
+ return @listener.mouse_released(mouse_event, mouse_button_ID)
39
+ end
40
+ end
41
+
42
+ #
43
+ # Tray Listener
44
+ #
45
+ class TrayListener < OgreBites::SdkTrayListener
46
+ def initialize(listener)
47
+ super()
48
+ @listener = listener
49
+ end
50
+
51
+ def buttonHit(button)
52
+ @listener.button_Hit(button)
53
+ end
54
+
55
+ def itemSelected(menu)
56
+ @listener.item_Selected(menu)
57
+ end
58
+
59
+ def yesNoDialogClosed(name, bl)
60
+ @listener.yes_no_dialog_closed(name, bl)
61
+ end
62
+
63
+ def okDialogClosed(name)
64
+ @listener.ok_dialog_closed(name)
65
+ end
66
+ end
67
+
68
+ end # module
@@ -0,0 +1,201 @@
1
+ require 'teien/camera'
2
+
3
+ module Teien
4
+
5
+ class UserInterface
6
+ def initialize(view)
7
+ @view = view
8
+ @camera = Camera.new(view.camera)
9
+ end
10
+
11
+ def set_controller(controller)
12
+ @view.set_controller(controller)
13
+ end
14
+
15
+ def get_camera()
16
+ return @camera
17
+ end
18
+
19
+ def show_frame_stats(placement)
20
+ @view.tray_mgr.showFrameStats(placement)
21
+ end
22
+
23
+ def show_logo(placement)
24
+ @view.tray_mgr.showLogo(placement)
25
+ end
26
+
27
+ def show_cursor()
28
+ @view.tray_mgr.showCursor()
29
+ end
30
+
31
+ def hide_cursor()
32
+ @view.tray_mgr.hideCursor()
33
+ end
34
+
35
+ end
36
+
37
+ class UI < UserInterface
38
+ # Layout
39
+ TL_BOTTOMLEFT = OgreBites::TL_BOTTOMLEFT
40
+ TL_BOTTOMRIGHT = OgreBites::TL_BOTTOMRIGHT
41
+
42
+ # Keyboard
43
+ KC_UNASSIGNED = OIS::KC_UNASSIGNED
44
+ KC_ESCAPE = OIS::KC_ESCAPE
45
+ KC_1 = OIS::KC_1
46
+ KC_2 = OIS::KC_2
47
+ KC_3 = OIS::KC_3
48
+ KC_4 = OIS::KC_4
49
+ KC_5 = OIS::KC_5
50
+ KC_6 = OIS::KC_6
51
+ KC_7 = OIS::KC_7
52
+ KC_8 = OIS::KC_8
53
+ KC_9 = OIS::KC_9
54
+ KC_0 = OIS::KC_0
55
+ KC_MINUS = OIS::KC_MINUS
56
+ KC_EQUALS = OIS::KC_EQUALS
57
+ KC_BACK = OIS::KC_BACK
58
+ KC_TAB = OIS::KC_TAB
59
+ KC_Q = OIS::KC_Q
60
+ KC_W = OIS::KC_W
61
+ KC_E = OIS::KC_E
62
+ KC_R = OIS::KC_R
63
+ KC_T = OIS::KC_T
64
+ KC_Y = OIS::KC_Y
65
+ KC_U = OIS::KC_U
66
+ KC_I = OIS::KC_I
67
+ KC_O = OIS::KC_O
68
+ KC_P = OIS::KC_P
69
+ KC_LBRACKET = OIS::KC_LBRACKET
70
+ KC_RBRACKET = OIS::KC_RBRACKET
71
+ KC_RETURN = OIS::KC_RETURN
72
+ KC_LCONTROL = OIS::KC_LCONTROL
73
+ KC_A = OIS::KC_A
74
+ KC_S = OIS::KC_S
75
+ KC_D = OIS::KC_D
76
+ KC_F = OIS::KC_F
77
+ KC_G = OIS::KC_G
78
+ KC_H = OIS::KC_H
79
+ KC_J = OIS::KC_J
80
+ KC_K = OIS::KC_K
81
+ KC_L = OIS::KC_L
82
+ KC_SEMICOLON = OIS::KC_SEMICOLON
83
+ KC_APOSTROPHE = OIS::KC_APOSTROPHE
84
+ KC_GRAVE = OIS::KC_GRAVE
85
+ KC_LSHIFT = OIS::KC_LSHIFT
86
+ KC_BACKSLASH = OIS::KC_BACKSLASH
87
+ KC_Z = OIS::KC_Z
88
+ KC_X = OIS::KC_X
89
+ KC_C = OIS::KC_C
90
+ KC_V = OIS::KC_V
91
+ KC_B = OIS::KC_B
92
+ KC_N = OIS::KC_N
93
+ KC_M = OIS::KC_M
94
+ KC_COMMA = OIS::KC_COMMA
95
+ KC_PERIOD = OIS::KC_PERIOD
96
+ KC_SLASH = OIS::KC_SLASH
97
+ KC_RSHIFT = OIS::KC_RSHIFT
98
+ KC_MULTIPLY = OIS::KC_MULTIPLY
99
+ KC_LMENU = OIS::KC_LMENU
100
+ KC_SPACE = OIS::KC_SPACE
101
+ KC_CAPITAL = OIS::KC_CAPITAL
102
+ KC_F1 = OIS::KC_F1
103
+ KC_F2 = OIS::KC_F2
104
+ KC_F3 = OIS::KC_F3
105
+ KC_F4 = OIS::KC_F4
106
+ KC_F5 = OIS::KC_F5
107
+ KC_F6 = OIS::KC_F6
108
+ KC_F7 = OIS::KC_F7
109
+ KC_F8 = OIS::KC_F8
110
+ KC_F9 = OIS::KC_F9
111
+ KC_F10 = OIS::KC_F10
112
+ KC_NUMLOCK = OIS::KC_NUMLOCK
113
+ KC_SCROLL = OIS::KC_SCROLL
114
+ KC_NUMPAD7 = OIS::KC_NUMPAD7
115
+ KC_NUMPAD8 = OIS::KC_NUMPAD8
116
+ KC_NUMPAD9 = OIS::KC_NUMPAD9
117
+ KC_SUBTRACT = OIS::KC_SUBTRACT
118
+ KC_NUMPAD4 = OIS::KC_NUMPAD4
119
+ KC_NUMPAD5 = OIS::KC_NUMPAD5
120
+ KC_NUMPAD6 = OIS::KC_NUMPAD6
121
+ KC_ADD = OIS::KC_ADD
122
+ KC_NUMPAD1 = OIS::KC_NUMPAD1
123
+ KC_NUMPAD2 = OIS::KC_NUMPAD2
124
+ KC_NUMPAD3 = OIS::KC_NUMPAD3
125
+ KC_NUMPAD0 = OIS::KC_NUMPAD0
126
+ KC_DECIMAL = OIS::KC_DECIMAL
127
+ KC_OEM_102 = OIS::KC_OEM_102
128
+ KC_F11 = OIS::KC_F11
129
+ KC_F12 = OIS::KC_F12
130
+ KC_F13 = OIS::KC_F13
131
+ KC_F14 = OIS::KC_F14
132
+ KC_F15 = OIS::KC_F15
133
+ KC_KANA = OIS::KC_KANA
134
+ KC_ABNT_C1 = OIS::KC_ABNT_C1
135
+ KC_CONVERT = OIS::KC_CONVERT
136
+ KC_NOCONVERT = OIS::KC_NOCONVERT
137
+ KC_YEN = OIS::KC_YEN
138
+ KC_ABNT_C2 = OIS::KC_ABNT_C2
139
+ KC_NUMPADEQUALS= OIS::KC_NUMPADEQUALS
140
+ KC_PREVTRACK = OIS::KC_PREVTRACK
141
+ KC_AT = OIS::KC_AT
142
+ KC_COLON = OIS::KC_COLON
143
+ KC_UNDERLINE = OIS::KC_UNDERLINE
144
+ KC_KANJI = OIS::KC_KANJI
145
+ KC_STOP = OIS::KC_STOP
146
+ KC_AX = OIS::KC_AX
147
+ KC_UNLABELED = OIS::KC_UNLABELED
148
+ KC_NEXTTRACK = OIS::KC_NEXTTRACK
149
+ KC_NUMPADENTER = OIS::KC_NUMPADENTER
150
+ KC_RCONTROL = OIS::KC_RCONTROL
151
+ KC_MUTE = OIS::KC_MUTE
152
+ KC_CALCULATOR = OIS::KC_CALCULATOR
153
+ KC_PLAYPAUSE = OIS::KC_PLAYPAUSE
154
+ KC_MEDIASTOP = OIS::KC_MEDIASTOP
155
+ KC_VOLUMEDOWN = OIS::KC_VOLUMEDOWN
156
+ KC_VOLUMEUP = OIS::KC_VOLUMEUP
157
+ KC_WEBHOME = OIS::KC_WEBHOME
158
+ KC_NUMPADCOMMA = OIS::KC_NUMPADCOMMA
159
+ KC_DIVIDE = OIS::KC_DIVIDE
160
+ KC_SYSRQ = OIS::KC_SYSRQ
161
+ KC_RMENU = OIS::KC_RMENU
162
+ KC_PAUSE = OIS::KC_PAUSE
163
+ KC_HOME = OIS::KC_HOME
164
+ KC_UP = OIS::KC_UP
165
+ KC_PGUP = OIS::KC_PGUP
166
+ KC_LEFT = OIS::KC_LEFT
167
+ KC_RIGHT = OIS::KC_RIGHT
168
+ KC_END = OIS::KC_END
169
+ KC_DOWN = OIS::KC_DOWN
170
+ KC_PGDOWN = OIS::KC_PGDOWN
171
+ KC_INSERT = OIS::KC_INSERT
172
+ KC_DELETE = OIS::KC_DELETE
173
+ KC_LWIN = OIS::KC_LWIN
174
+ KC_RWIN = OIS::KC_RWIN
175
+ KC_APPS = OIS::KC_APPS
176
+ KC_POWER = OIS::KC_POWER
177
+ KC_SLEEP = OIS::KC_SLEEP
178
+ KC_WAKE = OIS::KC_WAKE
179
+ KC_WEBSEARCH = OIS::KC_WEBSEARCH
180
+ KC_WEBFAVORITES= OIS::KC_WEBFAVORITES
181
+ KC_WEBREFRESH = OIS::KC_WEBREFRESH
182
+ KC_WEBSTOP = OIS::KC_WEBSTOP
183
+ KC_WEBFORWARD = OIS::KC_WEBFORWARD
184
+ KC_WEBBACK = OIS::KC_WEBBACK
185
+ KC_MYCOMPUTER = OIS::KC_MYCOMPUTER
186
+ KC_MAIL = OIS::KC_MAIL
187
+ KC_MEDIASELECT = OIS::KC_MEDIASELECT
188
+
189
+ # Mouse
190
+ MB_Left = OIS::MB_Left
191
+ MB_Right = OIS::MB_Right
192
+ MB_Middle = OIS::MB_Middle
193
+ MB_Button3 = OIS::MB_Button3
194
+ MB_Button4 = OIS::MB_Button4
195
+ MB_Button5 = OIS::MB_Button5
196
+ MB_Button6 = OIS::MB_Button6
197
+ MB_Button7 = OIS::MB_Button7
198
+ end
199
+
200
+
201
+ end
@@ -0,0 +1,3 @@
1
+ module Teien
2
+ VERSION = "0.0.1"
3
+ end
data/lib/teien/view.rb ADDED
@@ -0,0 +1,244 @@
1
+ require 'teien/ui_listener'
2
+
3
+ module Teien
4
+
5
+ class View < Ogre::FrameListener
6
+ attr_accessor :root
7
+ attr_accessor :camera
8
+ attr_accessor :window
9
+ attr_accessor :mouse
10
+ attr_accessor :keyboard
11
+ attr_accessor :scene_mgr
12
+ attr_accessor :tray_mgr
13
+ attr_accessor :window_title
14
+
15
+
16
+ def initialize(garden)
17
+ super()
18
+ @garden = garden
19
+ @adjustFlag = false
20
+ @root = nil
21
+ @camera = nil
22
+ @window = nil
23
+ @mouse = nil
24
+ @keyboard = nil
25
+ @controller = nil
26
+ @scene_mgr = nil
27
+ @tray_mgr = nil
28
+ @inputManager = nil
29
+ @window_title = ""
30
+ end
31
+
32
+ def set_controller(controller)
33
+ @controller = controller
34
+ end
35
+
36
+ def setup
37
+ @plugins_cfg = @garden.plugins_cfg ? @garden.plugins_cfg : "plugins.cfg"
38
+ @resources_cfg = @garden.resources_cfg ? @garden.resources_cfg : "resources.cfg"
39
+
40
+ @root = Ogre::Root.new("")
41
+ load_plugins()
42
+
43
+ # return false unless (@root.restoreConfig())
44
+ return false unless (@root.showConfigDialog())
45
+
46
+ @window = @root.initialise(true, @window_title)
47
+
48
+ init_resources()
49
+ init_managers()
50
+
51
+ return true
52
+ end
53
+
54
+ def load_plugins
55
+ puts "PluginsCfgFile: #{@plugins_cfg}"
56
+ cfg = Ogre::ConfigFile.new
57
+ cfg.load(@plugins_cfg)
58
+
59
+ pluginDir = cfg.getSetting("PluginFolder")
60
+ pluginDir += "/" if (pluginDir.length > 0) && (pluginDir[-1] != '/')
61
+
62
+ cfg.each_Settings {|secName, keyName, valueName|
63
+ fullPath = pluginDir + valueName
64
+ fullPath.sub!("<ConfigFileFolder>", File.dirname(@garden.plugins_cfg)) if @garden.resources_cfg
65
+ fullPath.sub!("<SystemPluginFolder>", OgreConfig::getPluginFolder)
66
+ @root.loadPlugin(fullPath) if (keyName == "Plugin")
67
+ }
68
+ end
69
+
70
+ def init_resources
71
+ puts "ResourcesCfgFile: #{@resources_cfg}"
72
+ # Load resource paths from config file
73
+ cfg = Ogre::ConfigFile.new
74
+ cfg.load(@resources_cfg)
75
+
76
+ resourceDir = cfg.getSetting("ResourceFolder")
77
+ resourceDir += "/" if (resourceDir.length > 0) && (resourceDir[-1] != '/')
78
+
79
+ cfg.each_Settings {|secName, keyName, valueName|
80
+ next if (keyName == "ResourceFolder")
81
+
82
+ fullPath = resourceDir + valueName
83
+ if @garden.resources_cfg
84
+ fullPath.sub!("<ConfigFileFolder>", File.dirname(@garden.resources_cfg))
85
+ end
86
+ fullPath.sub!("<SystemResourceFolder>", OgreConfig::getResourceFolder)
87
+
88
+ Ogre::ResourceGroupManager::getSingleton().addResourceLocation(fullPath,
89
+ keyName,
90
+ secName)
91
+ }
92
+ end
93
+
94
+ def init_managers
95
+ @root.addFrameListener(self)
96
+
97
+ # initialize InputManager
98
+ windowHnd = Ogre::Intp.new
99
+ @window.getCustomAttribute("WINDOW", windowHnd)
100
+ windowHndStr = sprintf("%d", windowHnd.value())
101
+ pl = OIS::ParamList.new
102
+ pl["WINDOW"] = windowHndStr
103
+
104
+ # initialize input manager
105
+ @inputManager = OIS::InputManager::createInputSystem(pl)
106
+ @keyboard = @inputManager.createInputObject(OIS::OISKeyboard, true).toKeyboard()
107
+ @mouse = @inputManager.createInputObject(OIS::OISMouse, true).toMouse()
108
+
109
+ # initialize trayManager
110
+ Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Essential")
111
+ @tray_mgr = OgreBites::SdkTrayManager.new("Base", @window, @mouse);
112
+ ms = @mouse.getMouseState()
113
+ ms.width = @window.getWidth()
114
+ ms.height = @window.getHeight()
115
+ end
116
+
117
+ def start(script)
118
+ @script = script
119
+
120
+ # initialize scene_mgr
121
+ @scene_mgr = @root.createSceneManager(Ogre::ST_GENERIC)
122
+ @scene_mgr.setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE)
123
+
124
+ # initialize a camera
125
+ @camera = @scene_mgr.createCamera("FixCamera")
126
+ # Create one viewport, entire window
127
+ @vp = @window.addViewport(@camera);
128
+ @vp.setBackgroundColour(Ogre::ColourValue.new(0, 0, 0));
129
+ # Alter the camera aspect ratio to match the viewport
130
+ @camera.setAspectRatio(Float(@vp.getActualWidth()) / Float(@vp.getActualHeight()));
131
+
132
+ # set listeners.
133
+ @keyListener = KeyListener.new(self)
134
+ @keyboard.setEventCallback(@keyListener)
135
+ @mouseListener = MouseListener.new(self)
136
+ @mouse.setEventCallback(@mouseListener)
137
+ @trayListener = TrayListener.new(@script)
138
+ @tray_mgr.setListener(@trayListener)
139
+
140
+ # load resources into ResourceGroupManager.
141
+ @tray_mgr.showLoadingBar(1, 0)
142
+ Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General")
143
+ @tray_mgr.hideLoadingBar()
144
+ Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5)
145
+ end
146
+
147
+ def prepare_render_loop
148
+ @root.getRenderSystem()._initRenderTargets()
149
+ @root.clearEventTimes()
150
+ end
151
+
152
+ def stop
153
+ @scene_mgr.clearScene() if (@scene_mgr != nil)
154
+ @root.destroySceneManager(@scene_mgr) if (@scene_mgr != nil)
155
+ @scene_mgr = nil
156
+ @window.removeAllViewports()
157
+ @tray_mgr.destroyAllWidgets()
158
+ end
159
+
160
+ def finalize
161
+ stop()
162
+ if (@inputManger != nil)
163
+ @inputManager.destroyInputObject(@keyboard)
164
+ @inputManager.destroyInputObject(@mouse)
165
+ @inputManager = nil
166
+ end
167
+ @root.shutdown()
168
+ end
169
+
170
+ def create_scene_node(parent = nil)
171
+ if (parent == nil)
172
+ scene_node = @scene_mgr.getRootSceneNode().createChildSceneNode()
173
+ else
174
+ scene_node = parent.createChildSceneNode()
175
+ end
176
+ return scene_node
177
+ end
178
+
179
+ # Takes a screen shot.
180
+ def take_screen_shot(name)
181
+ @window.writeContentsToTimestampedFile(name + "_", ".png")
182
+ end
183
+
184
+ # Shows the animation infomation of the entity.
185
+ def show_all_animation(entity)
186
+ puts "Animations:"
187
+ animSet = entity.getAllAnimationStates()
188
+ animSet.each_AnimationState() {|state|
189
+ puts "name: #{state.getAnimationName()}, len: #{state.getLength()}"
190
+ }
191
+ end
192
+
193
+ # Called by the main loop periodically
194
+ def update(delta)
195
+ Ogre::WindowEventUtilities.messagePump()
196
+ return @root.renderOneFrame(delta)
197
+ end
198
+
199
+ # Called through @root.renderOneFrame(delta).
200
+ def frameRenderingQueued(evt)
201
+ @keyboard.capture()
202
+ @mouse.capture()
203
+ @controller.update(evt.timeSinceLastFrame) if @controller
204
+
205
+ @tray_mgr.frameRenderingQueued(evt)
206
+ if (@adjustFlag != true)
207
+ @tray_mgr.adjustTrays() # fix a caption invisible bug.
208
+ @adjustFlag = true
209
+ end
210
+
211
+ return @garden.updateInFrameRenderingQueued(evt.timeSinceLastFrame)
212
+ end
213
+
214
+ def key_pressed(keyEvent)
215
+ return true if @controller == nil
216
+ return @controller.key_pressed(keyEvent)
217
+ end
218
+
219
+ def key_released(keyEvent)
220
+ return true if @controller == nil
221
+ return @controller.key_released(keyEvent)
222
+ end
223
+
224
+ def mouse_moved(evt)
225
+ return true if @tray_mgr.injectMouseMove(evt)
226
+ return true if @controller == nil
227
+ return @controller.mouse_moved(evt)
228
+ end
229
+
230
+ def mouse_pressed(mouseEvent, mouseButtonID)
231
+ return true if @tray_mgr.injectMouseDown(mouseEvent, mouseButtonID)
232
+ return true if @controller == nil
233
+ return @controller.mouse_pressed(mouseEvent, mouseButtonID)
234
+ end
235
+
236
+ def mouse_released(mouseEvent, mouseButtonID)
237
+ return true if @tray_mgr.injectMouseUp(mouseEvent, mouseButtonID)
238
+ return true if @controller == nil
239
+ return @controller.mouse_released(mouseEvent, mouseButtonID)
240
+ end
241
+
242
+ end
243
+
244
+ end # module
data/lib/teien.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "teien/version"
2
+
3
+ require "Bullet.so"
4
+ require "Ogre.so"
5
+ require "Procedural.so"
6
+ require "OIS.so"
7
+ require "OgreBites.so"
8
+ require "Teienlib.so"
9
+
10
+ require "teien/tools.rb"
11
+ require 'teien/light_object'
12
+ require 'teien/object_info'
13
+ require 'teien/physics_info'
14
+ require 'teien/camera_mover'
15
+
16
+ module Teien
17
+
18
+ def create_garden(klass)
19
+ require "teien/garden.rb"
20
+
21
+ return Teien::Garden.new(klass)
22
+ end
23
+
24
+ =begin
25
+ def createServerGarden(url, klass)
26
+ require "teien/ServerGarden.rb"
27
+ require "ENet.so"
28
+
29
+ return MiniatureGarden::ServerGarden.new(url, klass)
30
+ end
31
+
32
+ def createClientGarden(uri, klass)
33
+ require "teien/ClientGarden.rb"
34
+ require "ENet.so"
35
+
36
+ return MiniatureGarden::ClientGarden.new(uri, klass)
37
+ end
38
+ =end
39
+
40
+ end
@@ -0,0 +1,155 @@
1
+ require 'teien'
2
+
3
+ include Teien
4
+
5
+ class HelloGarden
6
+ attr_accessor :info
7
+
8
+ def initialize(garden)
9
+ @garden = garden
10
+
11
+ @garden.set_window_title("SimpleGarden")
12
+
13
+ @quit = false
14
+
15
+ # set config files.
16
+ fileDir = File.dirname(File.expand_path(__FILE__))
17
+ @garden.plugins_cfg = "#{fileDir}/plugins.cfg"
18
+ @garden.resources_cfg = "#{fileDir}/resources.cfg"
19
+ end
20
+
21
+ def setup()
22
+ @ui = @garden.create_user_interface()
23
+
24
+ @garden.set_ambient_light(Color.new(0.1, 0.1, 0.1))
25
+ @garden.set_sky_dome(true, "Examples/CloudySky", 5, 8)
26
+ @garden.set_gravity(Vector3D.new(0.0, -9.8, 0.0))
27
+
28
+ @light = @garden.create_light("directionalLight")
29
+ @light.set_type(LightObject::DIRECTIONAL)
30
+ @light.set_diffuse_color(Color.new(1.0, 1.0, 1.0))
31
+ @light.set_specular_color(Color.new(0.25, 0.25, 0))
32
+ @light.set_direction(Vector3D.new( -1, -1, -1 ))
33
+
34
+ # create a floor.
35
+ object_info = FloorObjectInfo.new(50, 50, 0.5, 1, 1, 5, 5)
36
+ object_info.material_name = "Examples/Rockwall"
37
+ floor = @garden.create_object("Floor", object_info, PhysicsInfo.new(0))
38
+ floor.set_position(Vector3D.new(0, 0, 0))
39
+
40
+ # create a box.
41
+ object_info = BoxObjectInfo.new(Vector3D.new(1, 1, 1))
42
+ object_info.material_name = "Examples/BumpyMetal"
43
+ box = @garden.create_object("boxTest", object_info, PhysicsInfo.new(10))
44
+ box.set_position(Vector3D.new(0, 1.0, 0))
45
+
46
+ # create a sphere
47
+ object_info = SphereObjectInfo.new(1.0)
48
+ object_info.material_name = "Examples/SphereMappedRustySteel"
49
+ sphere = @garden.create_object("sphere", object_info, PhysicsInfo.new(10))
50
+ sphere.set_position(Vector3D.new(0, 1.0, -2))
51
+
52
+ # create a capsule
53
+ object_info = CapsuleObjectInfo.new(1.0, 2.0)
54
+ object_info.material_name = "Examples/RustySteel"
55
+ capsule = @garden.create_object("capsule", object_info, PhysicsInfo.new(10))
56
+ capsule.set_position(Vector3D.new(1, 5, 1))
57
+
58
+ # create a cone
59
+ object_info = ConeObjectInfo.new(1.0, 2.0)
60
+ object_info.material_name = "Examples/BeachStones"
61
+ cone = @garden.create_object("cone", object_info, PhysicsInfo.new(10))
62
+ cone.set_position(Vector3D.new(1, 10, 1))
63
+
64
+ # create a cylinder
65
+ object_info = CylinderObjectInfo.new(1.0, 2.0)
66
+ object_info.material_name = "Examples/BumpyMetal"
67
+ cylinder = @garden.create_object("cylinder", object_info, PhysicsInfo.new(10))
68
+ cylinder.set_position(Vector3D.new(-1, 10, -1))
69
+
70
+ # create a meshBB object
71
+ object_info = MeshBBObjectInfo.new("penguin.mesh", Vector3D.new(1.0, 1.0, 1.0))
72
+ object_info.scale = Vector3D.new(1.0 / 20.0, 1.0 / 20.0, 1.0 / 20.0)
73
+ object_info.physics_offset = Vector3D.new(0, 1.0, 0)
74
+ object_info.view_offset = Vector3D.new(0, 1.2, 0)
75
+ pen = @garden.create_object("pen", object_info, PhysicsInfo.new(10))
76
+ pen.set_position(Vector3D.new(1, 15, 0))
77
+
78
+ # create a mesh object
79
+ object_info = MeshObjectInfo.new("penguin.mesh")
80
+ object_info.scale = Vector3D.new(1.0 / 20.0, 1.0 / 20.0, 1.0 / 20.0)
81
+ pen = @garden.create_object("penpen", object_info, PhysicsInfo.new(10))
82
+ pen.set_position(Vector3D.new(1, 20, 0))
83
+
84
+ @ui.set_controller(self)
85
+
86
+ @camera_mover = @ui.get_camera().get_mover()
87
+ # @camera_mover.set_style(CameraMover::CS_FREELOOK)
88
+ # @camera_mover.set_style(CameraMover::CS_ORBIT)
89
+ @camera_mover.set_style(CameraMover::CS_TPS)
90
+ @camera_mover.set_target(floor)
91
+ @camera_mover.set_yaw_pitch_dist(Radian.new(Degree.new(0)), Radian.new(Degree.new(45)), 30.0)
92
+ # @camera_mover.set_position(Vector3D.new(20, 20, 20))
93
+ # @camera_mover.look_at(Vector3D.new(0, 0, 0))
94
+
95
+ @ui.show_frame_stats(UI::TL_BOTTOMLEFT)
96
+ @ui.show_logo(UI::TL_BOTTOMRIGHT)
97
+ @ui.hide_cursor()
98
+ end
99
+
100
+ def update(delta)
101
+ # print "Garden tick is called: ", evt.timeSinceLastFrame * 1000, "\n"
102
+ return false if (@quit) # end of mainloop
103
+
104
+ @camera_mover.update(delta)
105
+
106
+ return true
107
+ end
108
+
109
+ def key_pressed(keyEvent)
110
+ if (keyEvent.key == UI::KC_E)
111
+ @camera_mover.move_forward(true)
112
+ elsif (keyEvent.key == UI::KC_D)
113
+ @camera_mover.move_backward(true)
114
+ elsif (keyEvent.key == UI::KC_S)
115
+ @camera_mover.move_left(true)
116
+ elsif (keyEvent.key == UI::KC_F)
117
+ @camera_mover.move_right(true)
118
+ end
119
+ return true
120
+ end
121
+
122
+ def key_released(keyEvent)
123
+ if (keyEvent.key == UI::KC_ESCAPE)
124
+ @quit =true
125
+ elsif (keyEvent.key == UI::KC_E)
126
+ @camera_mover.move_forward(false)
127
+ elsif (keyEvent.key == UI::KC_D)
128
+ @camera_mover.move_backward(false)
129
+ elsif (keyEvent.key == UI::KC_S)
130
+ @camera_mover.move_left(false)
131
+ elsif (keyEvent.key == UI::KC_F)
132
+ @camera_mover.move_right(false)
133
+ end
134
+ return true
135
+ end
136
+
137
+ def mouse_moved(mouseEvent)
138
+ @camera_mover.mouse_moved(mouseEvent)
139
+ return true
140
+ end
141
+
142
+ def mouse_pressed(mouseEvent, mouseButtonID)
143
+ @camera_mover.mouse_pressed(mouseEvent, mouseButtonID)
144
+ return true
145
+ end
146
+
147
+ def mouse_released(mouseEvent, mouseButtonID)
148
+ @camera_mover.mouse_released(mouseEvent, mouseButtonID)
149
+ return true
150
+ end
151
+ end
152
+
153
+
154
+ garden = create_garden(HelloGarden)
155
+ garden.run()