Class: GlimR::Camera
- Inherits:
-
Transform
- Object
- SceneObject
- Transform
- GlimR::Camera
- Defined in:
- lib/glimr/renderer/camera.rb
Overview
Camera is a special Transform that applies to both the OpenGL projection matrix and modelview matrix.
Instance Attribute Summary collapse
-
#far ⇒ Object
Returns the value of attribute far.
-
#fov ⇒ Object
Returns the value of attribute fov.
-
#near ⇒ Object
Returns the value of attribute near.
-
#perspective ⇒ Object
Returns the value of attribute perspective.
Attributes inherited from Transform
#collapsed_matrix, #matrix, #position, #rotation, #scale
Attributes inherited from SceneObject
#children, #drawables, #mtime, #parent, #viewport
Attributes included from EventListener
#event_listeners, #listener_count
Instance Method Summary collapse
- #absolute_transform ⇒ Object
-
#apply ⇒ Object
Sets up the camera projection to the projection matrix.
- #default_config ⇒ Object
-
#gl_transform ⇒ Object
Uses GLU.LookAt to position the camera.
-
#initialize(*a, &b) ⇒ Camera
constructor
A new instance of Camera.
Methods inherited from Transform
#===, #angle, #angle=, #clone, #collapse!, #inspect, #pop_state, #push_state, #replace!, rotate, rotate_aa, rotate_quat, scale, #touch!, #translate, translate, #x, #x=, #y, #y=, #z, #z=
Methods inherited from SceneObject
#<<, #absolute_geometry, #absolute_material, #absolute_shader, #absolute_texture, #absolute_transform_for_drawing, #add_drawables, #attach, #clone, #detach, #detach_self, #inspect, #pop_state, #push_state, #remove_drawables, #render, #replace_node, #root, #touch!, #visible
Methods included from EventListener
#add_event_listener, #decrement_listener_count, #dispatch_event, #event_root, #increment_listener_count, #method_missing, #multicast_event, #process_event, #remove_event_listener
Constructor Details
#initialize(*a, &b) ⇒ Camera
Returns a new instance of Camera.
25 26 27 28 |
# File 'lib/glimr/renderer/camera.rb', line 25 def initialize(*a, &b) super @changed = true end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class GlimR::EventListener
Instance Attribute Details
#far ⇒ Object
Returns the value of attribute far.
11 12 13 |
# File 'lib/glimr/renderer/camera.rb', line 11 def far @far end |
#fov ⇒ Object
Returns the value of attribute fov.
11 12 13 |
# File 'lib/glimr/renderer/camera.rb', line 11 def fov @fov end |
#near ⇒ Object
Returns the value of attribute near.
11 12 13 |
# File 'lib/glimr/renderer/camera.rb', line 11 def near @near end |
#perspective ⇒ Object
Returns the value of attribute perspective.
11 12 13 |
# File 'lib/glimr/renderer/camera.rb', line 11 def perspective @perspective end |
Instance Method Details
#absolute_transform ⇒ Object
55 56 57 58 |
# File 'lib/glimr/renderer/camera.rb', line 55 def absolute_transform collapse! unless @collapsed_matrix @collapsed_matrix end |
#apply ⇒ Object
Sets up the camera projection to the projection matrix
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/glimr/renderer/camera.rb', line 31 def apply MatrixMode(PROJECTION) LoadIdentity() if perspective top = Math.tan(fov*Math::PI/360) * near bottom = -top left = .aspect * bottom right = .aspect * top Frustum(left,right, bottom,top, near,far) else Ortho(.x,.width, .y,.height, near,far) Scale(1,-1,1) Translate(0,-.height,0) end MatrixMode(MODELVIEW) LoadIdentity() super end |
#default_config ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/glimr/renderer/camera.rb', line 13 def default_config super.merge( :position => [0,0,5000], :looking_at => [0,0,0], :up => [0,1,0], :near => 1, :far => 10000, :fov => 60, :perspective => false ) end |
#gl_transform ⇒ Object
Uses GLU.LookAt to position the camera.
51 52 53 |
# File 'lib/glimr/renderer/camera.rb', line 51 def gl_transform GLU.LookAt(*position+looking_at+up) end |