shattered_pack 0.5.0.2 → 0.5.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.
- data/lib/shattered_model/base.rb +4 -0
- data/lib/shattered_state/base.rb +43 -40
- data/lib/shattered_view/base.rb +3 -1
- metadata +2 -2
data/lib/shattered_model/base.rb
CHANGED
@@ -105,6 +105,10 @@ module ShatteredModel #:nodoc:
|
|
105
105
|
raise NoMethodError, "#{self.class} has no method defined '#{method}'" if self.view.nil?
|
106
106
|
self.view.send(method, *args, &block)
|
107
107
|
end
|
108
|
+
|
109
|
+
def inspect
|
110
|
+
"#{self.class}:#{self.object_id}"
|
111
|
+
end
|
108
112
|
end
|
109
113
|
end
|
110
114
|
|
data/lib/shattered_state/base.rb
CHANGED
@@ -6,27 +6,43 @@ module ShatteredState
|
|
6
6
|
base.extend(ClassMethods)
|
7
7
|
end
|
8
8
|
module ClassMethods
|
9
|
+
# Cameras are the renderers of the world.
|
10
|
+
# Scene managers can have many cameras - for example, in a first person racing game you could have
|
11
|
+
# a camera facing forward, and a camera facing backwards, rendering to the rear view window.
|
12
|
+
#
|
13
|
+
#
|
9
14
|
# In order to set the initial position of the camera, and any other attributes you would like,
|
10
15
|
# use the following format.
|
11
16
|
# class CameraTestState < ShatteredState::Base
|
12
|
-
# camera :position => v(10,0,0), :
|
17
|
+
# camera :position => v(10,0,0), :near_clip => 10, :far_clip => 100
|
13
18
|
# end
|
14
|
-
#
|
15
|
-
# If you pass a symbol as a value, the symbol will be evaluated.
|
16
|
-
#
|
17
|
-
# This allows for things such as:
|
18
19
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# The valid options are any public functions within camera that ends in =
|
27
|
-
# (such as position=, looking_at=) See ShatteredView::Camera for more.
|
20
|
+
# Additional Options:
|
21
|
+
# :position => v(0,0,0) # The initial position of the camera
|
22
|
+
# :name => "StateName" # Internal name within Ogre, usually defaults to the state name.
|
23
|
+
# :look_at => (none) # Looks at a given direction. Will behave as expected with a :position passed in.
|
24
|
+
# :near_clip => 1 # The clip distance when near objects begin to disappear.
|
25
|
+
# :far_clip => 10000 # The clip distance when far objects begin to disappear.
|
26
|
+
# Initially set to just a large number.
|
28
27
|
def camera(options = {})
|
29
|
-
|
28
|
+
before_init_call( 'create', :camera, options.delete(:name) || self.to_s, options )
|
29
|
+
end
|
30
|
+
|
31
|
+
# The different types of scene managers provided by Ogre are:
|
32
|
+
# :general, :terrain, :nature, :paging, :indoor
|
33
|
+
def scene_manager(type)
|
34
|
+
before_init_call( 'create', :scene_manager, type)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# Viewports are your windows into the world.
|
39
|
+
# Cameras can have many viewports, but usually the relationship is 1-1.
|
40
|
+
#
|
41
|
+
# TODO: There are many more viewport options to take care of, including :dimensions, etc.
|
42
|
+
# Options:
|
43
|
+
# :color => rgb(0,0,0) # The background color of the viewport.
|
44
|
+
def viewport(options = {})
|
45
|
+
before_init_call( 'create', :viewport, options)
|
30
46
|
end
|
31
47
|
|
32
48
|
end
|
@@ -36,7 +52,7 @@ module ShatteredState
|
|
36
52
|
# You can choose your starting state in config/environment.rb
|
37
53
|
class Base < ShatteredPack::Base
|
38
54
|
before_init_call :activate_state
|
39
|
-
attr_reader :actors, :scene_manager
|
55
|
+
attr_reader :actors, :scene_manager, :camera, :viewport
|
40
56
|
|
41
57
|
def activate_state #:nodoc:
|
42
58
|
Shatter::GameLoader.instance.current_state = self
|
@@ -54,32 +70,17 @@ module ShatteredState
|
|
54
70
|
# The main method for creating new objects,
|
55
71
|
# IE: create(:light)
|
56
72
|
def create(type, *args)
|
57
|
-
|
58
|
-
name = args[0] unless args.empty?
|
59
|
-
|
60
|
-
object = self.send(:"create_#{type}", name)
|
73
|
+
object = self.send(:"create_#{type}", *args)
|
61
74
|
return object
|
62
75
|
end
|
63
76
|
|
64
77
|
# Returns the camera used in the state. See ShatteredState::ClassMethods#camera
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
options = args[0]
|
73
|
-
|
74
|
-
# Cameras are special, in that we have to have the position
|
75
|
-
# called before looking_at or the view matrix gets way messed up
|
76
|
-
# TODO: replace with create(:camera)
|
77
|
-
# call_object_function :camera, :position=, options.delete(:position) if options.has_key?(:position)
|
78
|
-
# call_object_function :camera, :looking_at=, options.delete(:looking_at) if options.has_key?(:looking_at)
|
79
|
-
|
80
|
-
# Call the other methods
|
81
|
-
# TODO: uncomment when camera is populated
|
82
|
-
# call_object_function_for_each_key(:camera, options)
|
78
|
+
def create_camera(name, options)
|
79
|
+
@camera = scene_manager.create_camera(name)
|
80
|
+
@camera.set_near_clip_distance(options[:near_clip] || 1)
|
81
|
+
@camera.set_far_clip_distance(options[:far_clip] || 10000)
|
82
|
+
@camera.position = options[:position] if options[:position]
|
83
|
+
@camera.look_at(options[:look_at]) if options[:look_at]
|
83
84
|
end
|
84
85
|
|
85
86
|
# Creates a scene manager for Ogre to use.
|
@@ -88,8 +89,10 @@ module ShatteredState
|
|
88
89
|
@scene_manager = root.create_scene_manager(ShatteredOgre.translate_to_scene_type(type), "#{root.to_s}.scene_manager(#{type})")
|
89
90
|
end
|
90
91
|
|
91
|
-
|
92
|
-
|
92
|
+
# Creates a viewport based off of the Camera.
|
93
|
+
def create_viewport(options)
|
94
|
+
@viewport = Shatter::GameLoader.instance.render_window.add_viewport(camera)
|
95
|
+
@viewport.set_background_colour(options[:color] || rgb(0,0,0))
|
93
96
|
end
|
94
97
|
|
95
98
|
def quit
|
data/lib/shattered_view/base.rb
CHANGED
@@ -158,7 +158,9 @@ module ShatteredView #:nodoc:
|
|
158
158
|
#Create a light and add it to the lights array
|
159
159
|
def create_light(name, options={})
|
160
160
|
light_number = @lights.length
|
161
|
-
|
161
|
+
light_entity = scene_manager.create_light("#{self.to_s}.light(#{light_number})")
|
162
|
+
light = Ogre::LightInstance.new(node, scene_manager, "", :entity => light_entity)
|
163
|
+
|
162
164
|
@lights << light
|
163
165
|
return light
|
164
166
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: shattered_pack
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.5.1
|
7
|
+
date: 2007-08-20 00:00:00 -06:00
|
8
8
|
summary: "Shattered Pack: The combination of model/view/controllers and the domain specific language for each."
|
9
9
|
require_paths:
|
10
10
|
- lib
|