Class: Three::OrthographicCamera

Inherits:
Camera show all
Defined in:
lib/three/cameras/orthographic_camera.rb

Constant Summary

Constants inherited from Object3D

Three::Object3D::DEFAULT_MATRIX_AUTO_UPDATE, Three::Object3D::DEFAULT_MATRIX_WORLD_AUTO_UPDATE, Three::Object3D::DEFAULT_UP

Instance Attribute Summary collapse

Attributes inherited from Camera

#matrix_world_inverse, #projection_matrix, #projection_matrix_inverse

Attributes inherited from Object3D

#cast_shadow, #children, #id, #layers, #matrix, #matrix_auto_update, #matrix_world, #matrix_world_auto_update, #matrix_world_needs_update, #name, #parent, #position, #quaternion, #receive_shadow, #rotation, #scale, #type, #up, #user_data, #uuid, #visible

Instance Method Summary collapse

Methods inherited from Camera

#get_world_direction, #update_matrix_world, #update_world_matrix

Methods inherited from Object3D

#add, allocate_id, #clear, #dirty_dependency_changed, #get_object_by_id, #get_object_by_name, #get_object_by_property, #get_objects_by_property, #get_world_direction, #get_world_position, #get_world_quaternion, #get_world_scale, #mark_descendant_dirty!, #mark_dirty!, #remove, #remove_from_parent, #to_h, #to_json, #traverse, #traverse_ancestors, #traverse_visible, #update_matrix, #update_matrix_world, #update_world_matrix

Methods included from Dirty

#add_dirty_dependent, #dirty?, #dirty_dependents, #dirty_field?, #dirty_fields, #mark_clean!, #mark_dirty!, #remove_dirty_dependent

Methods inherited from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener?, #remove_event_listener

Constructor Details

#initialize(left = -1,, right = 1, top = 1, bottom = -1,, near: 0.1, far: 2000) ⇒ OrthographicCamera

Returns a new instance of OrthographicCamera.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/three/cameras/orthographic_camera.rb', line 10

def initialize(left = -1, right = 1, top = 1, bottom = -1, near: 0.1, far: 2000)
  super()
  @type = "OrthographicCamera"
  @left = left
  @right = right
  @top = top
  @bottom = bottom
  @near = near
  @far = far
  @zoom = 1
  @view = nil
  update_projection_matrix
end

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



7
8
9
# File 'lib/three/cameras/orthographic_camera.rb', line 7

def bottom
  @bottom
end

#farObject

Returns the value of attribute far.



7
8
9
# File 'lib/three/cameras/orthographic_camera.rb', line 7

def far
  @far
end

#leftObject

Returns the value of attribute left.



7
8
9
# File 'lib/three/cameras/orthographic_camera.rb', line 7

def left
  @left
end

#nearObject

Returns the value of attribute near.



7
8
9
# File 'lib/three/cameras/orthographic_camera.rb', line 7

def near
  @near
end

#rightObject

Returns the value of attribute right.



7
8
9
# File 'lib/three/cameras/orthographic_camera.rb', line 7

def right
  @right
end

#topObject

Returns the value of attribute top.



7
8
9
# File 'lib/three/cameras/orthographic_camera.rb', line 7

def top
  @top
end

#viewObject (readonly)

Returns the value of attribute view.



8
9
10
# File 'lib/three/cameras/orthographic_camera.rb', line 8

def view
  @view
end

#zoomObject

Returns the value of attribute zoom.



7
8
9
# File 'lib/three/cameras/orthographic_camera.rb', line 7

def zoom
  @zoom
end

Instance Method Details

#clear_view_offsetObject



74
75
76
77
78
79
# File 'lib/three/cameras/orthographic_camera.rb', line 74

def clear_view_offset
  @view[:enabled] = false if @view
  mark_dirty!(:camera)
  update_projection_matrix
  self
end

#set_view_offset(full_width, full_height, x, y, width, height) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/three/cameras/orthographic_camera.rb', line 59

def set_view_offset(full_width, full_height, x, y, width, height)
  @view = {
    enabled: true,
    full_width: full_width,
    full_height: full_height,
    offset_x: x,
    offset_y: y,
    width: width,
    height: height
  }
  mark_dirty!(:camera)
  update_projection_matrix
  self
end

#update_projection_matrixObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/three/cameras/orthographic_camera.rb', line 81

def update_projection_matrix
  dx = (@right - @left).to_f / (2 * @zoom)
  dy = (@top - @bottom).to_f / (2 * @zoom)
  cx = (@right + @left).to_f / 2
  cy = (@top + @bottom).to_f / 2

  left = cx - dx
  right = cx + dx
  top = cy + dy
  bottom = cy - dy

  if @view && @view[:enabled]
    scale_w = (@right - @left).to_f / @view[:full_width] / @zoom
    scale_h = (@top - @bottom).to_f / @view[:full_height] / @zoom
    left += scale_w * @view[:offset_x]
    right = left + scale_w * @view[:width]
    top -= scale_h * @view[:offset_y]
    bottom = top - scale_h * @view[:height]
  end

  @projection_matrix.make_orthographic(left, right, top, bottom, @near, @far)
  @projection_matrix_inverse.copy(@projection_matrix).invert
  mark_dirty!(:camera)
  self
end