ogre.rb 0.1-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/README +79 -0
- data/Rakefile +291 -0
- data/doc_src/ogre.rb +246 -0
- data/doc_src/ois.rb +67 -0
- data/lib/application.rb +146 -0
- data/lib/application_frame_listener.rb +302 -0
- data/lib/application_loading_bar.rb +115 -0
- data/lib/constants.rb +51 -0
- data/lib/method_fixes.rb +42 -0
- data/lib/ogre.dll +0 -0
- data/lib/ruby_ois.dll +0 -0
- data/ogre.rb +25 -0
- data/platform.rb +23 -0
- data/samples/Ogre.log +279 -0
- data/samples/bsp.rb +76 -0
- data/samples/cg.dll +0 -0
- data/samples/grass.rb +325 -0
- data/samples/js3250.dll +0 -0
- data/samples/lighting.rb +138 -0
- data/samples/media/materials/programs/Grass.cg +30 -0
- data/samples/media/materials/programs/OffsetMapping.cg +97 -0
- data/samples/media/materials/programs/OffsetMapping.hlsl +135 -0
- data/samples/media/materials/programs/OffsetMappingFp.glsl +69 -0
- data/samples/media/materials/programs/OffsetMappingVp.glsl +54 -0
- data/samples/media/materials/programs/OffsetMapping_specular.asm +44 -0
- data/samples/media/materials/scripts/CloudySky.material +17 -0
- data/samples/media/materials/scripts/CubeMapping.material +34 -0
- data/samples/media/materials/scripts/Flare.material +17 -0
- data/samples/media/materials/scripts/Grass.material +63 -0
- data/samples/media/materials/scripts/Knot.material +14 -0
- data/samples/media/materials/scripts/MorningSkyBox.material +17 -0
- data/samples/media/materials/scripts/Offset.material +124 -0
- data/samples/media/materials/scripts/Ogre.material +119 -0
- data/samples/media/materials/scripts/RZR-002.material +15 -0
- data/samples/media/materials/scripts/Razor.material +14 -0
- data/samples/media/materials/scripts/Ribbon.material +19 -0
- data/samples/media/materials/scripts/RustySteel.material +14 -0
- data/samples/media/materials/scripts/SpaceSkyBox.material +17 -0
- data/samples/media/materials/scripts/SpaceSkyPlane.material +17 -0
- data/samples/media/materials/scripts/TextureEffects.material +15 -0
- data/samples/media/materials/scripts/dragon.material +42 -0
- data/samples/media/materials/scripts/smoke.material +18 -0
- data/samples/media/materials/textures/GreenSkin.jpg +0 -0
- data/samples/media/materials/textures/MtlPlat2.jpg +0 -0
- data/samples/media/materials/textures/RZR-002.png +0 -0
- data/samples/media/materials/textures/RustedMetal.jpg +0 -0
- data/samples/media/materials/textures/RustySteel.jpg +0 -0
- data/samples/media/materials/textures/Thumbs.db +0 -0
- data/samples/media/materials/textures/Water02.jpg +0 -0
- data/samples/media/materials/textures/WeirdEye.png +0 -0
- data/samples/media/materials/textures/clouds.jpg +0 -0
- data/samples/media/materials/textures/cursor.png +0 -0
- data/samples/media/materials/textures/dirt01.jpg +0 -0
- data/samples/media/materials/textures/flare.png +0 -0
- data/samples/media/materials/textures/gras_02.png +0 -0
- data/samples/media/materials/textures/grass_1024.jpg +0 -0
- data/samples/media/materials/textures/ogreborder.png +0 -0
- data/samples/media/materials/textures/ogreborderUp.png +0 -0
- data/samples/media/materials/textures/ribbonband.png +0 -0
- data/samples/media/materials/textures/rockwall.tga +0 -0
- data/samples/media/materials/textures/rockwall_NH.tga +0 -0
- data/samples/media/materials/textures/smoke.png +0 -0
- data/samples/media/materials/textures/smokecolors.png +0 -0
- data/samples/media/materials/textures/spacesky.jpg +0 -0
- data/samples/media/materials/textures/spheremap.png +0 -0
- data/samples/media/materials/textures/texmap2.jpg +0 -0
- data/samples/media/models/RZR-002.mesh +0 -0
- data/samples/media/models/geosphere4500.mesh +0 -0
- data/samples/media/models/geosphere8000.mesh +0 -0
- data/samples/media/models/knot.mesh +0 -0
- data/samples/media/models/ogrehead.mesh +0 -0
- data/samples/media/models/razor.mesh +0 -0
- data/samples/media/models/sphere.mesh +0 -0
- data/samples/media/overlays/CubeMapping.overlay +139 -0
- data/samples/media/packs/OgreCore.zip +0 -0
- data/samples/media/packs/chiropteraDM.pk3 +0 -0
- data/samples/media/packs/chiropteraDM.txt +99 -0
- data/samples/media/packs/cubemap.zip +0 -0
- data/samples/media/packs/cubemapsJS.zip +0 -0
- data/samples/media/packs/dragon.zip +0 -0
- data/samples/media/packs/skybox.zip +0 -0
- data/samples/media/particles/smoke.particle +43 -0
- data/samples/media.cfg +22 -0
- data/samples/ogre.cfg +19 -0
- data/samples/plugins.cfg +12 -0
- data/samples/quake3settings.cfg +2 -0
- data/samples/render_to_texture.rb +161 -0
- data/samples/resources.cfg +16 -0
- data/samples/sky_box.rb +107 -0
- data/samples/sky_dome.rb +86 -0
- data/samples/sky_plane.rb +27 -0
- data/samples/smoke.rb +23 -0
- data/samples/work/cube_mapping.rb +686 -0
- metadata +149 -0
data/lib/application.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
$:.push('..')
|
2
|
+
|
3
|
+
require 'ogre'
|
4
|
+
require 'application_frame_listener'
|
5
|
+
|
6
|
+
module Ogre
|
7
|
+
|
8
|
+
# Application is a Ruby port of ExampleApplication. It is written so that there's nothing new
|
9
|
+
# to learn here, but you do have to watch out for Ruby version of names
|
10
|
+
# (createScene vs create_scene).
|
11
|
+
#
|
12
|
+
# All you need to do is define your own createScene. An example Application subclass (sky_plane.rb):
|
13
|
+
#
|
14
|
+
# require 'ogre'
|
15
|
+
# include Ogre
|
16
|
+
#
|
17
|
+
# class SkyPlaneApplication < Application
|
18
|
+
#
|
19
|
+
# def create_scene
|
20
|
+
# scene_manager.set_ambient_light(ColourValue.new(0.5, 0.5, 0.5))
|
21
|
+
#
|
22
|
+
# plane = Plane.new
|
23
|
+
# plane.d = 5000
|
24
|
+
# plane.normal = -Vector3.UNIT_Y
|
25
|
+
# scene_manager.set_sky_plane(true, plane, "SpaceSkyPlane", 10000, 3)
|
26
|
+
#
|
27
|
+
# light = scene_manager.create_light("MainLight")
|
28
|
+
# light.set_position(20, 80, 50)
|
29
|
+
#
|
30
|
+
# dragon = scene_manager.create_entity("dragon", "dragon.mesh")
|
31
|
+
# scene_manager.root_scene_node.attach_object(dragon)
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# app = SkyPlaneApplication.new
|
36
|
+
# app.go
|
37
|
+
#
|
38
|
+
# Any of the protected methods in this class are free for overriding.
|
39
|
+
class Application
|
40
|
+
|
41
|
+
attr_accessor :root, :frame_listener, :window, :scene_manager, :camera
|
42
|
+
|
43
|
+
def initialize
|
44
|
+
@frame_listener = nil
|
45
|
+
@root = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
# This starts off everything.
|
49
|
+
def go
|
50
|
+
return unless setup
|
51
|
+
|
52
|
+
@root.start_rendering
|
53
|
+
|
54
|
+
destroy_scene
|
55
|
+
|
56
|
+
@frame_listener.shutdown
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def setup
|
62
|
+
@root = Root.new("plugins.cfg", "ogre.cfg", "Ogre.log")
|
63
|
+
|
64
|
+
setup_resources
|
65
|
+
|
66
|
+
return unless configure
|
67
|
+
|
68
|
+
choose_scene_manager
|
69
|
+
create_camera
|
70
|
+
create_viewports
|
71
|
+
|
72
|
+
TextureManager.instance.set_default_num_mipmaps 5
|
73
|
+
|
74
|
+
create_resource_listener
|
75
|
+
load_resources
|
76
|
+
create_scene
|
77
|
+
create_frame_listener
|
78
|
+
true
|
79
|
+
end
|
80
|
+
|
81
|
+
# Shows the configuration dialog and initializes our
|
82
|
+
# render window
|
83
|
+
def configure
|
84
|
+
return false unless @root.show_config_dialog
|
85
|
+
@window = @root.initialise(true)
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
def choose_scene_manager
|
90
|
+
@scene_manager = @root.create_scene_manager(ST_GENERIC, "ExampleSMInstance")
|
91
|
+
end
|
92
|
+
|
93
|
+
def create_camera
|
94
|
+
@camera = @scene_manager.create_camera("PlayerCam")
|
95
|
+
|
96
|
+
@camera.set_position(0, 0, 500)
|
97
|
+
# Look along the -Z axis
|
98
|
+
@camera.look_at(Vector3.new(0, 0, -300))
|
99
|
+
@camera.set_near_clip_distance 5
|
100
|
+
end
|
101
|
+
|
102
|
+
def create_frame_listener
|
103
|
+
@frame_listener = ApplicationFrameListener.new(@root, @window, @camera)
|
104
|
+
@frame_listener.show_debug_overlay(true)
|
105
|
+
end
|
106
|
+
|
107
|
+
def create_scene
|
108
|
+
raise "Please redefine #create_scene in your application"
|
109
|
+
end
|
110
|
+
|
111
|
+
def destroy_scene
|
112
|
+
end
|
113
|
+
|
114
|
+
def create_viewports
|
115
|
+
vp = @window.add_viewport(@camera)
|
116
|
+
vp.set_background_colour ColourValue.new(0,0,0)
|
117
|
+
|
118
|
+
@camera.set_aspect_ratio( (vp.get_actual_width * 1.0) / (vp.get_actual_height * 1.0) )
|
119
|
+
end
|
120
|
+
|
121
|
+
def setup_resources
|
122
|
+
section = "General"
|
123
|
+
File.open("resources.cfg", "r") do |config_file|
|
124
|
+
config_file.each do |line|
|
125
|
+
line.chomp!
|
126
|
+
next if line =~ /^#/ || line.empty?
|
127
|
+
if line =~ /^\[(.+?)\]/
|
128
|
+
section = $1
|
129
|
+
next
|
130
|
+
end
|
131
|
+
|
132
|
+
key, value = line.split("=")
|
133
|
+
ResourceGroupManager.instance.add_resource_location(value, key, section)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def create_resource_listener
|
139
|
+
end
|
140
|
+
|
141
|
+
def load_resources
|
142
|
+
ResourceGroupManager.instance.initialise_all_resource_groups
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,302 @@
|
|
1
|
+
module Ogre
|
2
|
+
# Define a listener for certain window events, such as resizing, closing,
|
3
|
+
# and changes of focus
|
4
|
+
#
|
5
|
+
# Currently not used
|
6
|
+
#
|
7
|
+
class ApplicationWindowListener < WindowEventListenerProxy #:nodoc:
|
8
|
+
def initialize(input_manager, window, keyboard, mouse, joy_stick)
|
9
|
+
super(window)
|
10
|
+
@input_manager = input_manager
|
11
|
+
@keyboard = keyboard
|
12
|
+
@mouse = mouse
|
13
|
+
@window = window
|
14
|
+
@joy_stick = joy_stick
|
15
|
+
end
|
16
|
+
|
17
|
+
# Adjust the mouse clipping area when the window has been resized
|
18
|
+
def windowResized(window)
|
19
|
+
width = height = depth = left = top = 0
|
20
|
+
window.getMetrics(width, height, depth, left, top)
|
21
|
+
|
22
|
+
mouse_state = @mouse.getMouseState
|
23
|
+
mouse_state.width = width
|
24
|
+
mouse_state.height = height
|
25
|
+
end
|
26
|
+
|
27
|
+
# Shut everything down nicely when we're done
|
28
|
+
def windowClosed(window)
|
29
|
+
if @window == window
|
30
|
+
if @input_manager
|
31
|
+
@input_manager.destroy_input_object(@mouse)
|
32
|
+
@input_manager.destroy_input_object(@keyboard)
|
33
|
+
@input_manager.destroy_input_object(@joy_stick)
|
34
|
+
|
35
|
+
OIS::InputManager.destroyInputSystem(@input_manager)
|
36
|
+
@input_manager = nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# In the same way Application is the port of ExampleApplication, ApplicationFrameListener
|
43
|
+
# is the Ruby port of ExampleFrameListener. This class gives us a very helpful starting
|
44
|
+
# point for input management and a few Overlays for information. The default ApplicationFrameListener
|
45
|
+
# gives the WASD movement (through OIS), as well as the well-known Ogre overlay showing triangle count, FPS, etc.
|
46
|
+
#
|
47
|
+
# Usage is just as easy as can be expected:
|
48
|
+
#
|
49
|
+
# require 'application'
|
50
|
+
# include Ogre
|
51
|
+
#
|
52
|
+
# class AppListener < ApplicationFrameListener
|
53
|
+
#
|
54
|
+
# def frame_started(event)
|
55
|
+
# return false unless super(event)
|
56
|
+
#
|
57
|
+
# ... frame event / input handling ...
|
58
|
+
#
|
59
|
+
# true
|
60
|
+
# end
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# class MyApplication < Application
|
64
|
+
#
|
65
|
+
# def create_scene
|
66
|
+
# ...
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# def create_frame_listener
|
70
|
+
# frame_listener = AppListener.new(root, window, camera)
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# app = MyApplication.new
|
75
|
+
# app.go
|
76
|
+
#
|
77
|
+
# Do take note of create_frame_listener in the example above. The FrameListener actually takes in
|
78
|
+
# the Root object, instead of the application calling root.addFrameListener. We do this because the process
|
79
|
+
# of using Ruby C++ subclasses in C++ functions doesn't really work, and may not even be possible.
|
80
|
+
# The fix for this is to build a Proxy class in C++ that is given the Root on construction. It then
|
81
|
+
# registers itself with the passed in Root. See OgreProxys for this definition
|
82
|
+
#
|
83
|
+
class ApplicationFrameListener < FrameListenerProxy
|
84
|
+
|
85
|
+
attr_accessor :keyboard, :mouse, :joy_stick, :input_manager, :camera, :window
|
86
|
+
|
87
|
+
def initialize(root, render_window, camera, buffered_keys = false,
|
88
|
+
buffered_mouse = false, buffered_joy = false)
|
89
|
+
super(root)
|
90
|
+
@camera = camera
|
91
|
+
@window = render_window
|
92
|
+
@move_speed = 100
|
93
|
+
@rotate_speed = 36
|
94
|
+
@move_scale = 0.0
|
95
|
+
@rot_scale = 0.0
|
96
|
+
@translate_vector = Vector3.ZERO
|
97
|
+
@rot_x = Degree.new(0)
|
98
|
+
@rot_y = Degree.new(0)
|
99
|
+
@debug_text = ""
|
100
|
+
|
101
|
+
@debug_overlay = OverlayManager.instance.get_by_name("Core/DebugOverlay")
|
102
|
+
|
103
|
+
LogManager.instance.log_message("*** Initializing OIS ***")
|
104
|
+
|
105
|
+
windowHnd = @window.get_custom_attribute_unsigned_long("WINDOW")
|
106
|
+
|
107
|
+
@input_manager = OIS::InputManager.create_input_system({"WINDOW" => "#{windowHnd}"})
|
108
|
+
@keyboard = @input_manager.create_input_object( OIS::OISKeyboard, buffered_keys)
|
109
|
+
@mouse = @input_manager.create_input_object( OIS::OISMouse, buffered_mouse)
|
110
|
+
|
111
|
+
# Most likely won't have a joystick here, so just throw away any exceptions
|
112
|
+
@joy_stick = nil
|
113
|
+
begin
|
114
|
+
@joy_stick = @input_manager.create_input_object( OIS::OISJoyStick, buffered_joy)
|
115
|
+
rescue
|
116
|
+
end
|
117
|
+
|
118
|
+
show_debug_overlay(true)
|
119
|
+
|
120
|
+
# Currently doesn't work, it's the Ruby subclass back into C++ problem
|
121
|
+
#puts "Setting window listener"
|
122
|
+
#@window_event_listener = ApplicationWindowListener.new(@input_manager, @window,
|
123
|
+
#@keyboard, @mouse,
|
124
|
+
#@joy_stick)
|
125
|
+
|
126
|
+
# Done in proxy constructor
|
127
|
+
# WindowEventUtilities.addWindowEventListener(@window, @window_event_listener)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Ruby doesn't have destructors, just manually call shutdown to clean this up
|
131
|
+
def shutdown
|
132
|
+
#WindowEventUtilities::removeWindowEventListener(@window, @window_event_listener)
|
133
|
+
#@window_event_listener.windowClosed(@window)
|
134
|
+
|
135
|
+
# Clean up our input objects
|
136
|
+
@input_manager.destroy_input_object(@mouse)
|
137
|
+
@input_manager.destroy_input_object(@keyboard)
|
138
|
+
@input_manager.destroy_input_object(@joy_stick)
|
139
|
+
|
140
|
+
OIS::InputManager.destroy_input_system(@input_manager)
|
141
|
+
@input_manager = nil
|
142
|
+
end
|
143
|
+
|
144
|
+
# Keyboard processing
|
145
|
+
def process_unbuffered_key_input(event)
|
146
|
+
# Start with basic movement, add overlay stuff later
|
147
|
+
|
148
|
+
# Left
|
149
|
+
if @keyboard.key_down?(OIS::KC_A)
|
150
|
+
@translate_vector.x = -@move_scale
|
151
|
+
end
|
152
|
+
|
153
|
+
# Right
|
154
|
+
if @keyboard.key_down?(OIS::KC_D)
|
155
|
+
@translate_vector.x = @move_scale
|
156
|
+
end
|
157
|
+
|
158
|
+
# Forward
|
159
|
+
if @keyboard.key_down?(OIS::KC_UP) || @keyboard.key_down?(OIS::KC_W)
|
160
|
+
@translate_vector.z = -@move_scale
|
161
|
+
end
|
162
|
+
|
163
|
+
# Back
|
164
|
+
if @keyboard.key_down?(OIS::KC_DOWN) || @keyboard.key_down?(OIS::KC_S)
|
165
|
+
@translate_vector.z = @move_scale
|
166
|
+
end
|
167
|
+
|
168
|
+
# Up
|
169
|
+
if @keyboard.key_down?(OIS::KC_PGUP)
|
170
|
+
@translate_vector.y = @move_scale
|
171
|
+
end
|
172
|
+
|
173
|
+
# Down
|
174
|
+
if @keyboard.key_down?(OIS::KC_PGDOWN)
|
175
|
+
@translate_vector.y = -@move_scale
|
176
|
+
end
|
177
|
+
|
178
|
+
# Turn Right
|
179
|
+
if @keyboard.key_down?(OIS::KC_RIGHT)
|
180
|
+
@camera.yaw(-@rot_scale)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Turn Left
|
184
|
+
if @keyboard.key_down?(OIS::KC_LEFT)
|
185
|
+
@camera.yaw(@rot_scale)
|
186
|
+
end
|
187
|
+
|
188
|
+
# Quit
|
189
|
+
if @keyboard.key_down?(OIS::KC_ESCAPE) || @keyboard.key_down?(OIS::KC_Q)
|
190
|
+
return false;
|
191
|
+
end
|
192
|
+
|
193
|
+
# Keep rendering
|
194
|
+
true
|
195
|
+
end
|
196
|
+
|
197
|
+
def process_unbuffered_mouse_input(event)
|
198
|
+
state = @mouse.mouse_state
|
199
|
+
|
200
|
+
if state.button_down?(OIS::MB_Right)
|
201
|
+
@translate_vector.x += state.X.rel * 0.13
|
202
|
+
@translate_vector.y -= state.Y.rel * 0.13
|
203
|
+
else
|
204
|
+
@rot_x = Degree.new(-state.X.rel * 0.13)
|
205
|
+
@rot_y = Degree.new(-state.Y.rel * 0.13)
|
206
|
+
end
|
207
|
+
|
208
|
+
true
|
209
|
+
end
|
210
|
+
|
211
|
+
# Process the movement we've calculated this frame
|
212
|
+
def move_camera
|
213
|
+
@camera.yaw(@rot_x)
|
214
|
+
@camera.pitch(@rot_y)
|
215
|
+
@camera.move_relative(@translate_vector)
|
216
|
+
end
|
217
|
+
|
218
|
+
# Toggle debug overlay if one exists
|
219
|
+
def show_debug_overlay(show)
|
220
|
+
if @debug_overlay
|
221
|
+
if show
|
222
|
+
@debug_overlay.show
|
223
|
+
else
|
224
|
+
@debug_overlay.hide
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# Ogre callback, called at the beginning of every frame
|
230
|
+
def frame_started(event)
|
231
|
+
return false if @window.closed?
|
232
|
+
|
233
|
+
# Need to capture input from each device
|
234
|
+
@keyboard.capture
|
235
|
+
@mouse.capture
|
236
|
+
@joy_stick.capture if @joy_stick
|
237
|
+
|
238
|
+
buffered_joy = @joy_stick.nil? ? true : @joy_stick.buffered
|
239
|
+
|
240
|
+
if !@mouse.buffered || !@keyboard.buffered || !buffered_joy
|
241
|
+
# If this is the first frame, pick a speed
|
242
|
+
if event.time_since_last_frame == 0
|
243
|
+
@move_scale = 1
|
244
|
+
@rot_scale = 0.1
|
245
|
+
else
|
246
|
+
# ~100 units / second
|
247
|
+
@move_scale = @move_speed * event.time_since_last_frame
|
248
|
+
# ~10 seconds for full rotation
|
249
|
+
@rot_scale = @rotate_speed * event.time_since_last_frame
|
250
|
+
end
|
251
|
+
|
252
|
+
@rot_x = Degree.new 0
|
253
|
+
@rot_y = Degree.new 0
|
254
|
+
|
255
|
+
@translate_vector = Vector3.ZERO
|
256
|
+
end
|
257
|
+
|
258
|
+
if !@keyboard.buffered
|
259
|
+
return false unless process_unbuffered_key_input(event)
|
260
|
+
end
|
261
|
+
|
262
|
+
if !@mouse.buffered
|
263
|
+
return false unless process_unbuffered_mouse_input(event)
|
264
|
+
end
|
265
|
+
|
266
|
+
if !@mouse.buffered || !@keyboard.buffered || !buffered_joy
|
267
|
+
move_camera
|
268
|
+
end
|
269
|
+
|
270
|
+
# Keep rendering!
|
271
|
+
true
|
272
|
+
end
|
273
|
+
|
274
|
+
def frame_ended(event)
|
275
|
+
update_stats
|
276
|
+
true
|
277
|
+
end
|
278
|
+
|
279
|
+
protected
|
280
|
+
|
281
|
+
def update_stats
|
282
|
+
gui_avg = OverlayManager.instance.get_overlay_element("Core/AverageFps")
|
283
|
+
gui_curr = OverlayManager.instance.get_overlay_element("Core/CurrFps")
|
284
|
+
gui_best = OverlayManager.instance.get_overlay_element("Core/BestFps")
|
285
|
+
gui_worst = OverlayManager.instance.get_overlay_element("Core/WorstFps")
|
286
|
+
gui_tris = OverlayManager.instance.get_overlay_element("Core/NumTris")
|
287
|
+
gui_batches = OverlayManager.instance.get_overlay_element("Core/NumBatches")
|
288
|
+
gui_debug = OverlayManager.instance.get_overlay_element("Core/DebugText")
|
289
|
+
|
290
|
+
stats = @window.get_statistics
|
291
|
+
|
292
|
+
gui_curr.set_caption("Current FPS: #{"%.3f" % stats.last_fps}")
|
293
|
+
gui_avg.set_caption("Average FPS: #{"%.3f" % stats.avg_fps}")
|
294
|
+
gui_best.set_caption("Best FPS: #{"%.3f" % stats.best_fps}")
|
295
|
+
gui_worst.set_caption("Worst FPS: #{"%.3f" % stats.worst_fps}")
|
296
|
+
gui_tris.set_caption("Triangle Count: #{stats.triangle_count}")
|
297
|
+
gui_batches.set_caption("Batch Count: #{stats.batch_count}")
|
298
|
+
|
299
|
+
gui_debug.set_caption("#{@debug_text}")
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module Ogre
|
2
|
+
|
3
|
+
# From Ogre's ExampleLoadingBar:
|
4
|
+
#
|
5
|
+
# Defines an example loading progress bar which you can use during
|
6
|
+
# startup, level changes etc to display loading progress.
|
7
|
+
#
|
8
|
+
# Basically you just need to create an instance of this class, call start()
|
9
|
+
# before loading and finish() afterwards. You may also need to stop areas of
|
10
|
+
# your scene rendering in between since this method will call
|
11
|
+
# RenderWindow::update() to update the display of the bar - we advise using
|
12
|
+
# SceneManager's 'special case render queues' for this, see
|
13
|
+
# SceneManager::addSpecialCaseRenderQueue for details.
|
14
|
+
#
|
15
|
+
# This progress bar relies on you having the OgreCore.zip package already
|
16
|
+
# added to a resource group called 'Bootstrap' - this provides the basic
|
17
|
+
# resources required for the progress bar and will be loaded automatically.
|
18
|
+
class ApplicationLoadingBar < ResourceGroupListenerProxy
|
19
|
+
|
20
|
+
def start(window, num_groups_init = 1, num_groups_load = 1, initial_proportion = 0.7)
|
21
|
+
@window = window
|
22
|
+
@num_groups_init = num_groups_init
|
23
|
+
@num_groups_load = num_groups_load
|
24
|
+
@initial_proportion = initial_proportion
|
25
|
+
|
26
|
+
ResourceGroupManager.instance.initialise_resource_group("Bootstrap")
|
27
|
+
|
28
|
+
overlay_mgr = OverlayManager.instance
|
29
|
+
@load_overlay = overlay_mgr.get_by_name("Core/LoadOverlay")
|
30
|
+
|
31
|
+
unless @load_overlay
|
32
|
+
raise "Cannot find loading overlay"
|
33
|
+
end
|
34
|
+
|
35
|
+
@load_overlay.show
|
36
|
+
|
37
|
+
# Save links the loading text elements
|
38
|
+
@loading_bar_element = overlay_mgr.get_overlay_element("Core/LoadPanel/Bar/Progress")
|
39
|
+
@loading_comment_element = overlay_mgr.get_overlay_element("Core/LoadPanel/Comment")
|
40
|
+
@loading_description_element = overlay_mgr.get_overlay_element("Core/LoadPanel/Description")
|
41
|
+
|
42
|
+
bar = overlay_mgr.get_overlay_element("Core/LoadPanel/Bar")
|
43
|
+
@progress_bar_max_size = bar.get_width
|
44
|
+
@loading_bar_element.set_width(0)
|
45
|
+
|
46
|
+
# See superclass
|
47
|
+
register_as_listener
|
48
|
+
end
|
49
|
+
|
50
|
+
def finish
|
51
|
+
@load_overlay.hide
|
52
|
+
|
53
|
+
# See superclass
|
54
|
+
unregister_as_listener
|
55
|
+
end
|
56
|
+
|
57
|
+
def resource_group_scripting_started(group_name, count)
|
58
|
+
unless @num_groups_init > 0
|
59
|
+
raise "You are initializing groups when you said you would not, failing before causing x / 0 error"
|
60
|
+
end
|
61
|
+
|
62
|
+
@progress_bar_inc = @progress_bar_max_size * @initial_proportion / (count * 1.0)
|
63
|
+
@progress_bar_inc /= @num_groups_init
|
64
|
+
|
65
|
+
@loading_description_element.set_caption("Parsing scripts...")
|
66
|
+
@window.update
|
67
|
+
end
|
68
|
+
|
69
|
+
def script_parse_started(script_name)
|
70
|
+
@loading_comment_element.set_caption(script_name)
|
71
|
+
@window.update
|
72
|
+
end
|
73
|
+
|
74
|
+
def script_parse_ended(script_name)
|
75
|
+
@loading_bar_element.set_width(@loading_bar_element.get_width + @progress_bar_inc)
|
76
|
+
@window.update
|
77
|
+
end
|
78
|
+
|
79
|
+
def resource_group_scripting_ended(group_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
def resource_group_load_started(group_name, count)
|
83
|
+
puts "", "", "Resource group started #{group_name}", "", ""
|
84
|
+
unless @num_groups_load > 0
|
85
|
+
raise "You are initializing groups when you said you would not, failing before causing x / 0 error"
|
86
|
+
end
|
87
|
+
|
88
|
+
@progress_bar_inc = @progress_bar_max_size * (1 - @initial_proportion) / (count * 1.0)
|
89
|
+
@progress_bar_inc /= @num_groups_load
|
90
|
+
@loading_description_element.set_caption("Loading resources...")
|
91
|
+
@window.update
|
92
|
+
end
|
93
|
+
|
94
|
+
def resource_load_started(resource)
|
95
|
+
@loading_comment_element.set_caption(resource.get_name)
|
96
|
+
@window.update
|
97
|
+
end
|
98
|
+
|
99
|
+
def resource_load_ended()
|
100
|
+
end
|
101
|
+
|
102
|
+
def world_geometry_stage_started(description)
|
103
|
+
@loading_comment_element.set_caption(description)
|
104
|
+
@window.update
|
105
|
+
end
|
106
|
+
|
107
|
+
def world_geometry_stage_ended
|
108
|
+
@loading_bar_element.set_width(@loading_bar_element.get_width + @progress_bar_inc)
|
109
|
+
@window.update
|
110
|
+
end
|
111
|
+
|
112
|
+
def resource_group_load_ended(name)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/lib/constants.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Ogre
|
2
|
+
class Vector3
|
3
|
+
def self.ZERO
|
4
|
+
Vector3.new(0, 0, 0)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.UNIT_X
|
8
|
+
Vector3.new(1, 0, 0)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.UNIT_Y
|
12
|
+
Vector3.new(0, 1, 0)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.UNIT_Z
|
16
|
+
Vector3.new(0, 0, 1)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.NEGATIVE_UNIT_X
|
20
|
+
Vector3.new(-1, 0, 0)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.NEGATIVE_UNIT_Y
|
24
|
+
Vector3.new(0, -1, 0)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.NEGATIVE_UNIT_Z
|
28
|
+
Vector3.new(0, 0, -1)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.UNIT_SCALE
|
32
|
+
Vector3.new(1, 1, 1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Vector4
|
37
|
+
def self.ZERO
|
38
|
+
Vector4.new(0,0,0,0)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Quaternion
|
43
|
+
def self.ZERO
|
44
|
+
Quaternion.new(0.0,0.0,0.0,0.0)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.IDENTITY
|
48
|
+
Quaternion.new(1.0,0.0,0.0,0.0)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/method_fixes.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Ogre
|
2
|
+
|
3
|
+
class SubMesh
|
4
|
+
alias_method :use_shared_vertices?, :useSharedVertices
|
5
|
+
alias_method :use_shared_vertices=, :useSharedVertices=
|
6
|
+
|
7
|
+
alias_method :vertex_data, :vertexData
|
8
|
+
alias_method :vertex_data=, :vertexData=
|
9
|
+
|
10
|
+
alias_method :index_data, :indexData
|
11
|
+
alias_method :index_data=, :indexData=
|
12
|
+
|
13
|
+
# SubMesh is a friend of Mesh, not a subclass...
|
14
|
+
#alias_method :shared_vertex_data, :sharedVertexData
|
15
|
+
#alias_method :shared_vertex_data=, :sharedVertexData=
|
16
|
+
end
|
17
|
+
|
18
|
+
class VertexData
|
19
|
+
alias_method :vertex_declaration, :vertexDeclaration
|
20
|
+
alias_method :vertex_declaration=, :vertexDeclaration=
|
21
|
+
|
22
|
+
alias_method :vertex_buffer_binding, :vertexBufferBinding
|
23
|
+
alias_method :vertex_buffer_binding=, :vertexBufferBinding=
|
24
|
+
|
25
|
+
alias_method :vertex_start, :vertexStart
|
26
|
+
alias_method :vertex_start=, :vertexStart=
|
27
|
+
|
28
|
+
alias_method :vertex_count, :vertexCount
|
29
|
+
alias_method :vertex_count=, :vertexCount=
|
30
|
+
end
|
31
|
+
|
32
|
+
class IndexData
|
33
|
+
alias_method :index_buffer, :indexBuffer
|
34
|
+
alias_method :index_buffer=, :indexBuffer=
|
35
|
+
|
36
|
+
alias_method :index_start, :indexStart
|
37
|
+
alias_method :index_start=, :indexStart=
|
38
|
+
|
39
|
+
alias_method :index_count, :indexCount
|
40
|
+
alias_method :index_count=, :indexCount=
|
41
|
+
end
|
42
|
+
end
|
data/lib/ogre.dll
ADDED
Binary file
|
data/lib/ruby_ois.dll
ADDED
Binary file
|
data/ogre.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/platform'
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/lib")
|
5
|
+
|
6
|
+
# Ruby always looks for .so first, instead of .dll if on windows.
|
7
|
+
# So, force .dll on windows environments
|
8
|
+
if Platform.windows?
|
9
|
+
require 'lib/ogre.dll'
|
10
|
+
require 'lib/ruby_ois.dll'
|
11
|
+
# require 'lib/navi.dll'
|
12
|
+
|
13
|
+
else
|
14
|
+
require 'lib/ogre'
|
15
|
+
require 'lib/ruby_ois'
|
16
|
+
end
|
17
|
+
|
18
|
+
# Ick, fix this? Doing this because the native OIS binary is infact
|
19
|
+
# named OIS.dll, and was causing conflicts on my system.
|
20
|
+
module OIS
|
21
|
+
include Ruby_ois
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'constants'
|
25
|
+
require 'method_fixes'
|
data/platform.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Helper functions for determining platform
|
2
|
+
|
3
|
+
class Platform
|
4
|
+
def self.mac?
|
5
|
+
return PLATFORM =~ /darwin/
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.windows?
|
9
|
+
return PLATFORM =~ /mswin/
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.linux?
|
13
|
+
PLATFORM =~ /linux/
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Used to get around stupid windows STL issues when ruby.h is included first.
|
18
|
+
# NOTE: It would better to do this with SWIG, but I could not figure out how.
|
19
|
+
def insert_headers(file)
|
20
|
+
contents = File.open(file).read
|
21
|
+
header = yield+"\n"
|
22
|
+
File.open(file, "w").write(header+contents)
|
23
|
+
end
|