Class: RAGE::Location
- Inherits:
-
Object
- Object
- RAGE::Location
- Defined in:
- lib/rage/location.rb
Overview
Location w/ coordinates in the 3D system. Various entities may be associated with Location to be drawn.
Instance Attribute Summary collapse
-
#mesh ⇒ Object
readonly
Mesh which to draw at location.
-
#text ⇒ Object
readonly
Text which to draw at location.
-
#x ⇒ Object
readonly
x, y, z coordinates of the location,.
-
#y ⇒ Object
readonly
x, y, z coordinates of the location,.
-
#z ⇒ Object
readonly
x, y, z coordinates of the location,.
Instance Method Summary collapse
-
#boundaries ⇒ Object
Return location boundaries.
-
#draw ⇒ Object
Invoked during draw cycle to draw location & entity associated w/ it.
-
#initialize(args = {}) ⇒ Location
constructor
Initialize Location with argument hash, which may include * :x location coordinate * :y location coordinate * :z location coordinate * :mesh resource to draw at location * :text resource to draw at location.
-
#update(args = {}) ⇒ Object
Update location w/ args, which may include * :x location coordinate * :y location coordinate * :z location coordinate.
Constructor Details
#initialize(args = {}) ⇒ Location
Initialize Location with argument hash, which may include
-
:x location coordinate
-
:y location coordinate
-
:z location coordinate
-
:mesh resource to draw at location
-
:text resource to draw at location
28 29 30 31 32 33 34 35 36 |
# File 'lib/rage/location.rb', line 28 def initialize(args = {}) @mesh = @text = nil @x = args.has_key?(:x) ? args[:x] : 0 @y = args.has_key?(:y) ? args[:y] : 0 @z = args.has_key?(:z) ? args[:z] : 0 @mesh = args[:mesh] @text = args[:text] end |
Instance Attribute Details
#mesh ⇒ Object (readonly)
Mesh which to draw at location
15 16 17 |
# File 'lib/rage/location.rb', line 15 def mesh @mesh end |
#text ⇒ Object (readonly)
Text which to draw at location
18 19 20 |
# File 'lib/rage/location.rb', line 18 def text @text end |
#x ⇒ Object (readonly)
x, y, z coordinates of the location,
12 13 14 |
# File 'lib/rage/location.rb', line 12 def x @x end |
#y ⇒ Object (readonly)
x, y, z coordinates of the location,
12 13 14 |
# File 'lib/rage/location.rb', line 12 def y @y end |
#z ⇒ Object (readonly)
x, y, z coordinates of the location,
12 13 14 |
# File 'lib/rage/location.rb', line 12 def z @z end |
Instance Method Details
#boundaries ⇒ Object
Return location boundaries. This is generated by determining maxima/minima local coordinates of entity associated w/ location and adding those to the location’s coordinates. Return value is an array of six values as follows
max_x, max_y, max_z, min_x, min_y, min_z
52 53 54 55 56 57 58 |
# File 'lib/rage/location.rb', line 52 def boundaries max_x = max_y = max_z = min_x = min_y = min_z = 0 unless mesh.nil? max_x, max_y, max_z, min_x, min_y, min_z = mesh.boundaries end return x + max_x, y + max_y, z + max_z, x + min_x, y + min_y, z + min_z end |
#draw ⇒ Object
Invoked during draw cycle to draw location & entity associated w/ it
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rage/location.rb', line 62 def draw Gl.glPushMatrix(); # translate coordinate system to location's coordinates Gl.glTranslatef(x, y, z) # draw mesh mesh.draw unless mesh.nil? # draw text text.draw unless text.nil? Gl.glPopMatrix(); end |
#update(args = {}) ⇒ Object
Update location w/ args, which may include
-
:x location coordinate
-
:y location coordinate
-
:z location coordinate
42 43 44 45 46 |
# File 'lib/rage/location.rb', line 42 def update(args = {}) @x = args[:x] if args.has_key?(:x) @y = args[:y] if args.has_key?(:y) @z = args[:z] if args.has_key?(:z) end |