Class: Stagecraft::Cameras::Perspective
- Defined in:
- lib/stagecraft/cameras/perspective_camera.rb
Instance Attribute Summary collapse
-
#aspect ⇒ Object
Returns the value of attribute aspect.
-
#far ⇒ Object
Returns the value of attribute far.
-
#fov ⇒ Object
Returns the value of attribute fov.
-
#near ⇒ Object
Returns the value of attribute near.
Attributes inherited from Node
#cast_shadow, #children, #name, #parent, #position, #receive_shadow, #render_order, #rotation, #scale, #visible, #world_version
Instance Method Summary collapse
-
#initialize(fov: 50.0, aspect: 1.0, near: 0.1, far: 2_000.0) ⇒ Perspective
constructor
A new instance of Perspective.
- #projection_matrix ⇒ Object
Methods inherited from Camera
#view_matrix, #view_projection_matrix
Methods inherited from Node
#add, #find, #local_matrix, #look_at, #remove, #transform_dirty!, #traverse, #world_matrix, #world_matrix_with_version, #world_position
Constructor Details
#initialize(fov: 50.0, aspect: 1.0, near: 0.1, far: 2_000.0) ⇒ Perspective
Returns a new instance of Perspective.
8 9 10 11 12 13 14 15 16 |
# File 'lib/stagecraft/cameras/perspective_camera.rb', line 8 def initialize(fov: 50.0, aspect: 1.0, near: 0.1, far: 2_000.0, **) super(**) @projection_revision = 0 @cached_projection_revision = -1 self.fov = fov self.aspect = aspect self.near = near self.far = far end |
Instance Attribute Details
#aspect ⇒ Object
Returns the value of attribute aspect.
6 7 8 |
# File 'lib/stagecraft/cameras/perspective_camera.rb', line 6 def aspect @aspect end |
#far ⇒ Object
Returns the value of attribute far.
6 7 8 |
# File 'lib/stagecraft/cameras/perspective_camera.rb', line 6 def far @far end |
#fov ⇒ Object
Returns the value of attribute fov.
6 7 8 |
# File 'lib/stagecraft/cameras/perspective_camera.rb', line 6 def fov @fov end |
#near ⇒ Object
Returns the value of attribute near.
6 7 8 |
# File 'lib/stagecraft/cameras/perspective_camera.rb', line 6 def near @near end |
Instance Method Details
#projection_matrix ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/stagecraft/cameras/perspective_camera.rb', line 36 def projection_matrix return @projection_matrix if @cached_projection_revision == @projection_revision radians = fov * Math::PI / 180.0 f = 1.0 / Math.tan(radians / 2.0) @projection_matrix = Larb::Mat4.new([ f / aspect, 0.0, 0.0, 0.0, 0.0, f, 0.0, 0.0, 0.0, 0.0, far / (near - far), -1.0, 0.0, 0.0, (near * far) / (near - far), 0.0 ]) @cached_projection_revision = @projection_revision @projection_matrix end |