shattered_pack 0.4.0.1 → 0.5.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.
- data/lib/shattered_model.rb +1 -4
- data/lib/shattered_pack/base.rb +1 -1
- data/lib/shattered_pack/keyboard_input/key_converter.rb +3 -3
- data/lib/shattered_pack/keyboard_input/keyboard_input.rb +3 -1
- data/lib/shattered_pack/pre_initialize/pre_initialize.rb +6 -1
- data/lib/shattered_pack.rb +2 -5
- data/lib/shattered_state/actor/actor.rb +5 -1
- data/lib/shattered_state/base.rb +31 -16
- data/lib/shattered_state.rb +1 -4
- data/lib/shattered_view/base.rb +106 -41
- data/lib/shattered_view/camera.rb +7 -7
- data/lib/shattered_view/resources.rb +18 -2
- data/lib/shattered_view.rb +3 -5
- metadata +10 -29
- data/lib/mock_objects/shattered_ogre/input.rb +0 -6
- data/lib/mock_objects/shattered_ogre/light.rb +0 -4
- data/lib/mock_objects/shattered_ogre/mesh.rb +0 -17
- data/lib/mock_objects/shattered_ogre/node.rb +0 -17
- data/lib/mock_objects/shattered_ogre/renderer.rb +0 -11
- data/lib/mock_objects/shattered_ogre/resource_handler.rb +0 -9
- data/lib/mock_objects/shattered_ogre/scene.rb +0 -28
- data/lib/shattered_model/fuzzy_logic.rb +0 -188
- data/lib/shattered_model/linear_interpolator.rb +0 -29
- data/lib/shattered_pack/runner.rb +0 -11
- data/lib/shattered_state/runner.rb +0 -39
- data/lib/shattered_view/extensions.rb +0 -10
- data/lib/shattered_view/light.rb +0 -29
- data/lib/shattered_view/mesh/animation.rb +0 -20
- data/lib/shattered_view/mesh/mesh.rb +0 -152
- data/lib/shattered_view/node.rb +0 -105
- data/lib/shattered_view/overlay.rb +0 -20
- data/lib/shattered_view/rmaterial.rb +0 -43
- data/lib/shattered_view/runner.rb +0 -48
- data/lib/shattered_view/vector.rb +0 -258
@@ -1,188 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
# This provides basic fuzzy logic. That is, it will tell you what properties any given
|
3
|
-
# attribute contains based upon previous definition.
|
4
|
-
#
|
5
|
-
# Example:
|
6
|
-
# player_logic.add_classification( :hp, :dieing, :hp, :max => 5, :min => 45 )
|
7
|
-
# player_logic.add_classification( :hp, :healthy, :max => 80, :min => 65 )
|
8
|
-
# player_logic.hp(15) => [[:dieing, 0.75], [:healthy, 0.0]]
|
9
|
-
class FuzzyLogic #:nodoc:
|
10
|
-
attr_reader :consequences
|
11
|
-
def initialize
|
12
|
-
@attributes = {}
|
13
|
-
@consequences = {}
|
14
|
-
end
|
15
|
-
|
16
|
-
def add_consequence( consequence, classifications={} )
|
17
|
-
@consequences[classifications] ||= []
|
18
|
-
@consequences[classifications] += [consequence]
|
19
|
-
end
|
20
|
-
|
21
|
-
def add_classification( attribute, classification, options = {} )
|
22
|
-
define_attribute(attribute) if(@attributes[attribute].nil?)
|
23
|
-
define_interpolator(attribute,classification,options)
|
24
|
-
end
|
25
|
-
|
26
|
-
def consequences_of(options={})
|
27
|
-
# transform the passed in attributes to probability sets
|
28
|
-
valid_sequences = []
|
29
|
-
options.each_pair do |attribute, value|
|
30
|
-
valid_sequences << {attribute => classifications_of(attribute,value)}
|
31
|
-
end
|
32
|
-
# combine the probability sets
|
33
|
-
valid_combinations = compile_consequence_combinations(valid_sequences)
|
34
|
-
# realize the consequences of the combined probability sets
|
35
|
-
return consequences_of_combinations(valid_combinations)
|
36
|
-
end
|
37
|
-
|
38
|
-
def parse_fuzzy_file( file_name )
|
39
|
-
file_name += ".yaml" if not(file_name =~ /\.yaml$/)
|
40
|
-
raise ArgumentError, "Cannot find #{file_name}" if not(File.file? file_name)
|
41
|
-
begin
|
42
|
-
fuzzy_file = YAML::load(File.open(file_name))
|
43
|
-
rescue ArgumentError => bang
|
44
|
-
raise ArgumentError, "Error when loading #{file_name} : #{bang.message}"
|
45
|
-
end
|
46
|
-
parse_attributes(fuzzy_file)
|
47
|
-
add_consequences_from_parsed(parse_consequences(fuzzy_file['consequences']))
|
48
|
-
end
|
49
|
-
|
50
|
-
# The algorithm always performs an action on update.
|
51
|
-
def update(object)
|
52
|
-
status = {}
|
53
|
-
@attributes.each_pair do |attribute, classifications|
|
54
|
-
status.merge!({attribute => object.send(attribute)})
|
55
|
-
end
|
56
|
-
consequences = consequences_of(status)
|
57
|
-
total_probability = 0
|
58
|
-
consequences.each_pair do |actions, probability|
|
59
|
-
total_probability+=probability
|
60
|
-
end
|
61
|
-
action_at_probability = rand*total_probability
|
62
|
-
total_probability = 0
|
63
|
-
consequences.each_pair do |actions, probability|
|
64
|
-
total_probability += probability
|
65
|
-
if( action_at_probability < total_probability )
|
66
|
-
actions.each do |action|
|
67
|
-
object.send(action)
|
68
|
-
end
|
69
|
-
break
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
# This function recursively moves through each valid combination of probabilities.
|
77
|
-
# It sums the probabilities by multiplication.
|
78
|
-
def compile_consequence_combinations(valid_sequences, compiled={}, probability=1.0)
|
79
|
-
retv = []
|
80
|
-
attribute = valid_sequences[0].keys[0]
|
81
|
-
classifications = valid_sequences[0][attribute]
|
82
|
-
classifications.each do |classification, chance|
|
83
|
-
next if chance == 0
|
84
|
-
nprobability=probability*chance
|
85
|
-
compiled[attribute]=classification
|
86
|
-
if(valid_sequences.length == 1)
|
87
|
-
retv << [compiled.dup, nprobability]
|
88
|
-
else
|
89
|
-
retv += compile_consequence_combinations(valid_sequences[1..-1],compiled,nprobability)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
return retv
|
93
|
-
end
|
94
|
-
|
95
|
-
def consequences_of_combinations(combinations)
|
96
|
-
consequences = {}
|
97
|
-
combinations.each do |combination, probability|
|
98
|
-
# where a = { {1 => 2}, 3 } and b = {1,2}, a[b] != 3
|
99
|
-
# in order to circumvent this (error?) we use the fact that
|
100
|
-
# a.keys[0] == b
|
101
|
-
@consequences.keys.each do |index|
|
102
|
-
next if index != combination
|
103
|
-
consequences[@consequences[index]] ||= 0
|
104
|
-
consequences[@consequences[index]]+=probability
|
105
|
-
end
|
106
|
-
end
|
107
|
-
return consequences
|
108
|
-
end
|
109
|
-
|
110
|
-
def parse_attributes(yaml)
|
111
|
-
yaml['attributes'].each_pair do |attribute, classifications|
|
112
|
-
classifications.each_pair do |classification, options|
|
113
|
-
options.keys.each do |key|
|
114
|
-
options[key.to_sym]=options.delete key
|
115
|
-
end
|
116
|
-
add_classification( attribute.to_sym, classification.to_sym, options )
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def parse_consequences(consequences,result={})
|
122
|
-
compilation = []
|
123
|
-
consequences.each_pair do |consequence, action|
|
124
|
-
nresult = result.dup
|
125
|
-
nresult.merge!(attribute_for(consequence.to_sym) => consequence.to_sym)
|
126
|
-
if action.is_a? String
|
127
|
-
compilation += [nresult => action.to_sym]
|
128
|
-
else
|
129
|
-
compilation+=parse_consequences(action,nresult)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
return compilation
|
133
|
-
end
|
134
|
-
|
135
|
-
def add_consequences_from_parsed(compilation)
|
136
|
-
compilation.each do |item|
|
137
|
-
item.each_pair do |index, action|
|
138
|
-
add_consequence(action, index)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def attribute_for(unknown_classification)
|
144
|
-
@attributes.each_pair do |attribute, classifications|
|
145
|
-
classifications.keys.each do |classification|
|
146
|
-
return attribute if classification == unknown_classification
|
147
|
-
end
|
148
|
-
end
|
149
|
-
return nil
|
150
|
-
end
|
151
|
-
|
152
|
-
def define_attribute(attribute)
|
153
|
-
@attributes[attribute] = {}
|
154
|
-
eval <<-EOF
|
155
|
-
class << self
|
156
|
-
define_method(:#{attribute}) do |at|
|
157
|
-
classifications_of(:#{attribute},at)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
EOF
|
161
|
-
end
|
162
|
-
|
163
|
-
def define_interpolator( attribute, classification,options )
|
164
|
-
interpolator = LinearInterpolator.new
|
165
|
-
@attributes[attribute][classification] = interpolator
|
166
|
-
|
167
|
-
add_point(interpolator, options[:max],1)
|
168
|
-
add_point(interpolator, options[:min],0)
|
169
|
-
end
|
170
|
-
|
171
|
-
def classifications_of( attribute, at )
|
172
|
-
retv = []
|
173
|
-
@attributes[attribute].each_pair do |classification,interpolator|
|
174
|
-
retv << [ classification, interpolator.value_at(at) ]
|
175
|
-
end
|
176
|
-
return retv.sort_by { |classification| (1.0-classification[1]) }
|
177
|
-
end
|
178
|
-
|
179
|
-
def add_point( interpolator, points, value )
|
180
|
-
if(points.is_a? Array)
|
181
|
-
points.each do |x|
|
182
|
-
interpolator.add_point(x,value)
|
183
|
-
end
|
184
|
-
else
|
185
|
-
interpolator.add_point(points,value)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# This provides basic linear interpolation between any number of arbitrarily defined points.
|
2
|
-
# It is used for fuzzy logic. Although, fuzzy logic based on a statistically normal curve
|
3
|
-
# provides best results, linear interpolation provides a "gud 'nuf" approach.
|
4
|
-
class LinearInterpolator #:nodoc:
|
5
|
-
def add_point(x,y)
|
6
|
-
@points ||= []
|
7
|
-
@points << [x,y]
|
8
|
-
@points = @points.sort_by { |x| x[0] }
|
9
|
-
end
|
10
|
-
def value_at(x)
|
11
|
-
return 0 if @points.nil?
|
12
|
-
return @points[0][1] if x < @points[0][0]
|
13
|
-
return @points[-1][1] if x > @points[-1][0]
|
14
|
-
|
15
|
-
after,before=nil,nil
|
16
|
-
@points.each_with_index do |point,i|
|
17
|
-
if(point[0] >= x)
|
18
|
-
after = point
|
19
|
-
before = @points[i-1]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
m=(before[1]-after[1])/(before[0]-after[0]).to_f
|
24
|
-
x-=before[0]
|
25
|
-
b=before[1]
|
26
|
-
|
27
|
-
return m*x+b
|
28
|
-
end
|
29
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
|
2
|
-
module ShatteredState
|
3
|
-
#The class Runner is present in model, view, and controller, and signifies the
|
4
|
-
#main entry point into the program. This is called by script/runner.rb
|
5
|
-
class Runner #:nodoc:
|
6
|
-
def initialize( options = {} )
|
7
|
-
@@environment ||= options
|
8
|
-
@@environment[:input] = ShatteredPack::KeyConverter.new(@@environment[:input])
|
9
|
-
end
|
10
|
-
|
11
|
-
#Every time this exits, a game dies.
|
12
|
-
def start_game(env)
|
13
|
-
@@environment = env
|
14
|
-
each_frame do |time_elapsed|
|
15
|
-
@@environment[:state].update_timers(time_elapsed)
|
16
|
-
@@environment[:input].flush
|
17
|
-
@@environment[:renderer].quit if @@environment[:quit]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def each_frame
|
22
|
-
yield @@environment[:renderer].timeSinceLastFrame while @@environment[:renderer].nextFrame
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.environment
|
26
|
-
begin
|
27
|
-
return @@environment
|
28
|
-
rescue NameError
|
29
|
-
return @@environment = mock_environment
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.mock_environment
|
34
|
-
retv = {}
|
35
|
-
retv[:camera] = ShatteredView::Node.new
|
36
|
-
return retv
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/shattered_view/light.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module ShatteredView
|
2
|
-
|
3
|
-
class Light
|
4
|
-
def light
|
5
|
-
@light ||= ShatteredOgre::Scene.getSingleton().createLight
|
6
|
-
end
|
7
|
-
def direction=(*direction)
|
8
|
-
light.setType(ShatteredOgre::Light::LT_DIRECTIONAL)
|
9
|
-
light.setDirection(direction.to_v3)
|
10
|
-
end
|
11
|
-
def diffuse=(r,g,b)
|
12
|
-
light.setDiffuseColour(r,g,b)
|
13
|
-
end
|
14
|
-
def specular=(r,g,b)
|
15
|
-
light.setSpecularColour(r,g,b)
|
16
|
-
end
|
17
|
-
def position=(pos)
|
18
|
-
light.setType(ShatteredOgre::Light::LT_POINT)
|
19
|
-
light.setPosition(pos.to_v3)
|
20
|
-
end
|
21
|
-
def ambient=(r,g,b)
|
22
|
-
ShatteredOgre::Scene.getSingleton().setAmbientLight(r,g,b);
|
23
|
-
end
|
24
|
-
def attenuation=(range, const, linear, quad)
|
25
|
-
light.setType(ShatteredOgre::Light::LT_POINT)
|
26
|
-
light.setAttenuation(range, const, linear, quad)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module ShatteredView
|
2
|
-
class Animation
|
3
|
-
def initialize(mesh, name)
|
4
|
-
@animation = mesh.getAnimation name
|
5
|
-
@animation.addAsFrameListener
|
6
|
-
end
|
7
|
-
def play
|
8
|
-
@animation.play
|
9
|
-
end
|
10
|
-
def stop
|
11
|
-
@animation.stop
|
12
|
-
end
|
13
|
-
def loop=(looping)
|
14
|
-
@animation.setLoop(looping);
|
15
|
-
end
|
16
|
-
def time_scale=(scale)
|
17
|
-
@animation.setTimeScale(scale);
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
-
|
4
|
-
require 'animation'
|
5
|
-
module ShatteredView
|
6
|
-
module Mesh
|
7
|
-
def self.included(base)
|
8
|
-
base.extend(ClassMethods)
|
9
|
-
base.send(:include, InstanceMethods)
|
10
|
-
end
|
11
|
-
|
12
|
-
module ClassMethods
|
13
|
-
# Meshes are the foundation for your world.
|
14
|
-
#
|
15
|
-
# They tie in to Ogre's .mesh file format, and display a 3d object onto the screen.
|
16
|
-
#
|
17
|
-
# Shattered has support for loading meshes, creating materials for those meshes (using RMaterials)
|
18
|
-
# and skeletal animation support.
|
19
|
-
#
|
20
|
-
# class DirtyRubyView
|
21
|
-
# mesh "dirty_ruby", :position => v(0,0,1)
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# When a Mesh is created, all animations found in that mesh are loaded, and added
|
25
|
-
# as functions to that mesh.
|
26
|
-
#
|
27
|
-
# example: Tim.mesh has animations kick and punch
|
28
|
-
#
|
29
|
-
# after loading Tim.mesh, View has the Mesh object tim
|
30
|
-
# tim.kick.play
|
31
|
-
# tim.animation(:kick).play
|
32
|
-
#
|
33
|
-
# See Rmaterials and Animation for more details.
|
34
|
-
def mesh(file, options = {})
|
35
|
-
before_init_call( :mesh, file, options )
|
36
|
-
end
|
37
|
-
|
38
|
-
# Note: The following is broken in 0.4.0.1
|
39
|
-
# Animations declare helper functions for mesh animations.
|
40
|
-
#
|
41
|
-
# class AnimatedRubyView < ...
|
42
|
-
# mesh :animated_ruby, ...
|
43
|
-
# animation "shatter"
|
44
|
-
#
|
45
|
-
# def initialize
|
46
|
-
# shatter # same as animated_ruby.shatter
|
47
|
-
# end
|
48
|
-
# end
|
49
|
-
#
|
50
|
-
# options can include any function in animation.rb
|
51
|
-
# and :alias => :alias_name
|
52
|
-
def animation(name, options = {})
|
53
|
-
play_alias = options.delete(:alias)
|
54
|
-
before_init_call(:animation, name, options)
|
55
|
-
unless play_alias.nil?
|
56
|
-
before_init_call(:animation_alias, name, play_alias)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
module InstanceMethods
|
62
|
-
|
63
|
-
public
|
64
|
-
|
65
|
-
#TODO - Should it be a list like this, or a hash with the name as the index?
|
66
|
-
def meshes
|
67
|
-
# children.collect { |child| child if child.is_a? Mesh }
|
68
|
-
@meshes
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
def mesh(file, options={})
|
73
|
-
mesh = Mesh.new(file)
|
74
|
-
name = mesh.name
|
75
|
-
attr_reader name.to_sym, mesh
|
76
|
-
|
77
|
-
call_object_function_for_each_key(name, options)
|
78
|
-
#keep track of the meshes we create
|
79
|
-
mesh.attach_to(node)
|
80
|
-
@meshes ||= []
|
81
|
-
@meshes << mesh
|
82
|
-
mesh
|
83
|
-
end
|
84
|
-
|
85
|
-
def animation(name, options={})
|
86
|
-
meshes.each do |mesh|
|
87
|
-
mesh.instance_eval <<-EOF
|
88
|
-
class << self
|
89
|
-
define_method(:#{name}) do
|
90
|
-
animation(:#{name})
|
91
|
-
end
|
92
|
-
end
|
93
|
-
EOF
|
94
|
-
call_object_function_for_each_key("#{mesh.name}.#{name}".to_sym, options)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def animation_alias(name, renamed)
|
99
|
-
define_method(renamed.to_sym) do
|
100
|
-
meshes.each do |mesh|
|
101
|
-
mesh.animation(name.to_sym).play
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# This Mesh class corresponds (almost 1 to 1) with ShatteredOgre's mesh class
|
108
|
-
class Mesh < ShatteredView::Node
|
109
|
-
attr_reader :name
|
110
|
-
|
111
|
-
def initialize( file, options = {} )
|
112
|
-
super( )
|
113
|
-
@name = file.underscore
|
114
|
-
@scene_node = ShatteredOgre::Scene.getSingleton.createMesh( [0,0,0].to_v3, "#{file}.mesh" )
|
115
|
-
# TODO Log this
|
116
|
-
# puts "Loading Mesh: #{scene_node} from #{file}.mesh"
|
117
|
-
populate_animations
|
118
|
-
end
|
119
|
-
|
120
|
-
# Access a given animation. Returns nil on failure.
|
121
|
-
def animation( animation )
|
122
|
-
return @animations[animation]
|
123
|
-
end
|
124
|
-
|
125
|
-
#Set the material on this mesh. Accepts a string or a rmaterial
|
126
|
-
def material=( material )
|
127
|
-
if material.is_a? RMaterial
|
128
|
-
scene_node.generateTangents if material.tangent_space
|
129
|
-
material = material.name
|
130
|
-
end
|
131
|
-
scene_node.setMaterial(material.to_s)
|
132
|
-
end
|
133
|
-
|
134
|
-
# Remove the Ogre Mesh from the scene
|
135
|
-
def remove_from_scene
|
136
|
-
scene_node.removeFromScene
|
137
|
-
end
|
138
|
-
private
|
139
|
-
|
140
|
-
# populate_animations queries ShatteredOgre and adds the found animations to the mesh.
|
141
|
-
def populate_animations
|
142
|
-
@animations = {}
|
143
|
-
(0...scene_node.getNumberOfAnimations).each do |idx|
|
144
|
-
name = scene_node.getAnimationName(idx)
|
145
|
-
@animations[name.downcase.to_sym] = ShatteredView::Animation.new(scene_node, name)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
data/lib/shattered_view/node.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
module ShatteredView
|
2
|
-
class Node
|
3
|
-
attr_reader :position
|
4
|
-
attr_accessor :scene_node
|
5
|
-
|
6
|
-
#Returns the SceneManager::RootNode wrapped in ShatteredView::Node
|
7
|
-
def Node.root
|
8
|
-
@@root ||= Node.new
|
9
|
-
@@root.scene_node = ShatteredOgre::Scene.getSingleton.getRootSceneNode
|
10
|
-
return @@root
|
11
|
-
end
|
12
|
-
|
13
|
-
#Everything attached to this object
|
14
|
-
def children
|
15
|
-
@children ||= []
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(parent = nil)
|
19
|
-
@position = v(0,0,0)
|
20
|
-
# Create an empty unassociated node.
|
21
|
-
@scene_node = ShatteredOgre::Scene.getSingleton.createSceneNode
|
22
|
-
attach_to(parent)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Use attach_to instead
|
26
|
-
def attach_child(child)
|
27
|
-
children << child
|
28
|
-
child.scene_node.attachTo(scene_node)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Use attach_to on the child node (with nil if you want to clear the parent)
|
32
|
-
def remove_child(child)
|
33
|
-
@children.delete child
|
34
|
-
end
|
35
|
-
|
36
|
-
#Set a new parent node for the object
|
37
|
-
def attach_to(new_parent)
|
38
|
-
@parent.remove_child(self) unless @parent.nil?
|
39
|
-
@parent = new_parent
|
40
|
-
new_parent.attach_child(self) unless new_parent.nil?
|
41
|
-
end
|
42
|
-
|
43
|
-
# Move the node a certain amount
|
44
|
-
def translate(v)
|
45
|
-
@position += v
|
46
|
-
synchronize
|
47
|
-
end
|
48
|
-
|
49
|
-
def position=(v)
|
50
|
-
@position = v.to_v
|
51
|
-
synchronize
|
52
|
-
end
|
53
|
-
|
54
|
-
# uses #look_at
|
55
|
-
def looking_at=( *look_toward )
|
56
|
-
look_toward = look_toward[0] if(look_toward.length == 1)
|
57
|
-
look_at(look_toward)
|
58
|
-
end
|
59
|
-
|
60
|
-
alias_method :look_at=, :looking_at=
|
61
|
-
|
62
|
-
# look_at a Vector, Mesh, or Actor.
|
63
|
-
def look_at( position )
|
64
|
-
position = position.position unless position.is_a?(ShatteredOgre::Vector3) || position.is_a?(Vector) || position.is_a?(Array)
|
65
|
-
position = position.to_v3 unless position.is_a?(ShatteredOgre::Vector3)
|
66
|
-
scene_node.lookAt(position)
|
67
|
-
# raise ArgumentError, "#{position.inspect} is not a Mesh, Actor, or Vector."
|
68
|
-
end
|
69
|
-
|
70
|
-
# rotate along axis, degrees amount
|
71
|
-
def rotate( axis, degrees )
|
72
|
-
axis = axis.to_v.normalize
|
73
|
-
scene_node.rotate(axis.to_v3, degrees)
|
74
|
-
end
|
75
|
-
|
76
|
-
def rotation=(axis, degrees)
|
77
|
-
rotate axis, degrees
|
78
|
-
end
|
79
|
-
|
80
|
-
def scale=(*scale)
|
81
|
-
scale = scale[0] if scale.length == 1
|
82
|
-
scale = [scale, scale, scale].to_v if scale.kind_of?(Numeric)
|
83
|
-
scale = scale.to_v
|
84
|
-
|
85
|
-
scene_node.scale scale.to_v3
|
86
|
-
end
|
87
|
-
|
88
|
-
def scale(amount)
|
89
|
-
amount = amount.to_v3 unless amount.is_a? Fixnum
|
90
|
-
scene_node.scale amount
|
91
|
-
end
|
92
|
-
|
93
|
-
def visible=(visible)
|
94
|
-
scene_node.setVisible(visible)
|
95
|
-
end
|
96
|
-
|
97
|
-
# Synchronize the position with C++, this is called every frame. However
|
98
|
-
# there are times where scene_node hasn't been initialized quite yet
|
99
|
-
# (such as right when a new actor is in the process of being created), so
|
100
|
-
# only synchronize if there's something to synchronize
|
101
|
-
def synchronize
|
102
|
-
@scene_node.setPosition(position.to_v3) unless @scene_node.nil?
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module ShatteredView
|
2
|
-
class Overlay
|
3
|
-
attr_reader :name
|
4
|
-
def initialize(name)
|
5
|
-
@name = name
|
6
|
-
hide
|
7
|
-
end
|
8
|
-
def show
|
9
|
-
ShatteredOgre::Scene::getSingleton.showOverlay(name)
|
10
|
-
@visible = true
|
11
|
-
end
|
12
|
-
def hide
|
13
|
-
ShatteredOgre::Scene::getSingleton.hideOverlay(name)
|
14
|
-
@visible = false
|
15
|
-
end
|
16
|
-
def visible?
|
17
|
-
@visible
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
module ShatteredView
|
4
|
-
class RMaterial
|
5
|
-
attr_reader :result, :name
|
6
|
-
def load!(file)
|
7
|
-
begin
|
8
|
-
evaluate!(File.open(file).readlines.join(''))
|
9
|
-
rescue Errno::ENOENT => bang
|
10
|
-
raise Errno::ENOENT, "RMaterial for #{name} not found: #{bang.message}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
def create_ogre_material!
|
14
|
-
ShatteredOgre::ResourceHandler.getSingleton.addCustomMaterial(name.to_s, result)
|
15
|
-
end
|
16
|
-
def create_ogre_material=(*args)
|
17
|
-
load!("#{SHATTERED_ROOT}/app/media/common/templates/#{template}.rmaterial")
|
18
|
-
create_ogre_material!
|
19
|
-
end
|
20
|
-
def method_missing(name, *args)
|
21
|
-
# Check if the method is a setter
|
22
|
-
if name.to_s[-1].chr == "="
|
23
|
-
name = name.to_s[0...-1].to_sym
|
24
|
-
# Set the instance variable to the sent variable
|
25
|
-
ivar = "@#{ name }".to_sym
|
26
|
-
instance_variable_set(ivar, args[0])
|
27
|
-
else
|
28
|
-
begin
|
29
|
-
return eval("@#{name}")
|
30
|
-
rescue StandardError => bang
|
31
|
-
raise NoMethodError, "Rmaterial could not find the #{name} attribute: #{bang.message}"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
def evaluate!(template)
|
36
|
-
evaluator = ERB.new(template)
|
37
|
-
return @result ||= evaluator.result(binding)
|
38
|
-
end
|
39
|
-
def tangent_space
|
40
|
-
false
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
module ShatteredView
|
4
|
-
class Runner #:nodoc:
|
5
|
-
def initialize(options = {})
|
6
|
-
generate_plugin_config
|
7
|
-
Resources.instance.add_resource_paths("/media", "/app/media", "/app/views")
|
8
|
-
@renderer = ShatteredOgre::Renderer.new
|
9
|
-
raise Error, "Renderer failed to initialize Ogre" if @renderer.failed
|
10
|
-
@scene = ShatteredOgre::Scene.new(translate_to_scene_type(options[:scene_manager]))
|
11
|
-
end
|
12
|
-
def generate_plugin_config
|
13
|
-
plugin_directory = SHATTERED_ROOT+"/config/"
|
14
|
-
generated_plugin = plugin_directory+ "plugins."
|
15
|
-
generator = plugin_directory + "ogre_plugins.rcfg"
|
16
|
-
if PLATFORM =~ /mswin/
|
17
|
-
generated_plugin += "win32"
|
18
|
-
elsif PLATFORM =~ /darwin/
|
19
|
-
generated_plugin += "darwin"
|
20
|
-
else
|
21
|
-
generated_plugin += "linux"
|
22
|
-
end
|
23
|
-
process_plugin(generator, generated_plugin+".cfg")
|
24
|
-
end
|
25
|
-
def process_plugin(base, generate_to)
|
26
|
-
puts "Generating #{generate_to} from #{base}, #{File.exists?(base)}"
|
27
|
-
return unless File.exists?(base)
|
28
|
-
generated_banner = "\n\r//=== This file is generated. Modify the .rcfg instead. ===\n\r\n\r"
|
29
|
-
to_write = generated_banner + ERB.new(File.open(base,"r").read).result + generated_banner
|
30
|
-
output = File.open(generate_to, "w")
|
31
|
-
output.syswrite(to_write)
|
32
|
-
output.close
|
33
|
-
end
|
34
|
-
def translate_to_scene_type( symbol )
|
35
|
-
return ShatteredOgre::Scene::Generic if(symbol == :general)
|
36
|
-
return ShatteredOgre::Scene::Terrain if(symbol == :terrain)
|
37
|
-
return ShatteredOgre::Scene::Nature if(symbol == :nature)
|
38
|
-
return ShatteredOgre::Scene::NaturePaging if(symbol == :paging)
|
39
|
-
return ShatteredOgre::Scene::Indoor if(symbol == :indoor)
|
40
|
-
end
|
41
|
-
def add_to_environment(environment)
|
42
|
-
environment[:scene]=@scene
|
43
|
-
environment[:renderer]=@renderer
|
44
|
-
environment[:camera]=Camera.new @scene
|
45
|
-
environment[:input]=ShatteredOgre::Input.new
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|