Class: View
Overview
A lightweight view
Constant Summary collapse
- SHADOW_COLOR =
[ 0.25, 0.25, 0.25 ]
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#model ⇒ Object
Returns the value of attribute model.
-
#object ⇒ Object
Returns the value of attribute object.
-
#shadow ⇒ Object
Returns the value of attribute shadow.
Instance Method Summary collapse
- #draw ⇒ Object
- #drawObject ⇒ Object
- #drawShadow ⇒ Object
-
#initialize(model, color = nil) ⇒ View
constructor
A new instance of View.
- #makeObject ⇒ Object
- #makeShadow ⇒ Object
-
#shadowColorForHeight(height) ⇒ Object
Given the height of an object, return a shadow color.
Constructor Details
#initialize(model, color = nil) ⇒ View
Returns a new instance of View.
15 16 17 18 19 20 21 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 15 def initialize(model, color = nil) super() @model = model @color = color @object = nil @shadow = nil end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
13 14 15 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 13 def color @color end |
#model ⇒ Object
Returns the value of attribute model.
13 14 15 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 13 def model @model end |
#object ⇒ Object
Returns the value of attribute object.
13 14 15 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 13 def object @object end |
#shadow ⇒ Object
Returns the value of attribute shadow.
13 14 15 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 13 def shadow @shadow end |
Instance Method Details
#draw ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 39 def draw # We don't always have enough information to make the 3D objects # at initialize() time. makeObject() unless @object makeShadow() unless @shadow rot = Graphics.rotations(model.vector) PushMatrix() # Translate and rotate shadow. Rotation around y axis only. Translate(model.position.x, 0, model.position.z) Rotate(rot.y, 0, 1, 0) if rot.y.nonzero? # Draw shadow. drawShadow() unless @shadow.nil? # Translate and rotate object. Rotate object around x and z axes (y # axis already done for shadow). Translate(0, model.position.y, 0) Rotate(rot.x, 1, 0, 0) if rot.x.nonzero? Rotate(rot.z, 0, 0, 1) if rot.z.nonzero? # Draw object. drawObject() PopMatrix() end |
#drawObject ⇒ Object
31 32 33 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 31 def drawObject CallList(@object) end |
#drawShadow ⇒ Object
35 36 37 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 35 def drawShadow CallList(@shadow) if @shadow end |
#makeObject ⇒ Object
23 24 25 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 23 def makeObject raise "subclass should implement" end |
#makeShadow ⇒ Object
27 28 29 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 27 def makeShadow # Don't raise error; some models may not have a shadow end |
#shadowColorForHeight(height) ⇒ Object
Given the height of an object, return a shadow color. The shadow color gets lighter as heigt increases.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/View.rb', line 70 def shadowColorForHeight(height) wh = $PARAMS['world_height'] ratio = (height + wh / 2.0) / wh shadowColor = [] SHADOW_COLOR.each_with_index { | c0, i | min = c0 max = Canvas::GRASS_COLOR[i] if min > max tmp = min min = max max = tmp end shadowColor << min + ratio * (max - min) } return shadowColor end |