Class: Mittsu::CameraHelper

Inherits:
Line show all
Defined in:
lib/mittsu/extras/helpers/camera_helper.rb

Constant Summary

Constants inherited from Object3D

Object3D::DefaultUp

Instance Attribute Summary collapse

Attributes inherited from Line

#mode, #morph_target_base, #type

Attributes inherited from Object3D

#active, #cast_shadow, #children, #frustum_culled, #id, #initted, #matrix_world, #matrix_world_needs_update, #model_view_matrix, #morph_target_influences, #name, #parent, #position, #quaternion, #receive_shadow, #render_order, #renderer, #rotation, #rotation_auto_update, #scale, #type, #up, #user_data, #uuid, #visible

Instance Method Summary collapse

Methods inherited from Line

#add_opengl_object, #clone, #init_geometry, #raycast, #render_buffer, #update

Methods inherited from Object3D

#active?, #add, #add_opengl_object, #apply_matrix, #buffer_material, #clone, #deinit, #get_object_by_id, #get_object_by_name, #get_object_by_property, #get_world_direction, #get_world_position, #get_world_quaternion, #get_world_rotation, #get_world_scale, #init, #init_geometry, #load_uniforms_matrices, #local_to_world, #look_at, #print_tree, #project, #raycast, #remove, #rotate_on_axis, #rotate_x, #rotate_y, #rotate_z, #set_rotation_from_axis_angle, #set_rotation_from_euler, #set_rotation_from_matrix, #set_rotation_from_quaternion, #setup_matrices, #to_json, #to_s, #translate_on_axis, #translate_x, #translate_y, #translate_z, #traverse, #traverse_ancestors, #traverse_visible, #update_matrix, #update_matrix_world, #world_to_local

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Constructor Details

#initialize(camera) ⇒ CameraHelper

Returns a new instance of CameraHelper.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mittsu/extras/helpers/camera_helper.rb', line 7

def initialize(camera)
  @_vector = Vector3.new
  @_camera = Camera.new

  @geometry = Geometry.new
  @material = LineBasicMaterial.new(color: 0xffffff, vertex_colors: FaceColors)

  @point_map = {}

  # colors

  hex_frustrum = 0xffaa00
  hex_cone = 0xff0000
  hex_up = 0x00aaff
  hex_target = 0xffffff
  hex_cross = 0x333333

  # near

  add_line(:n1, :n2, hex_frustrum)
  add_line(:n2, :n4, hex_frustrum)
  add_line(:n4, :n3, hex_frustrum)
  add_line(:n3, :n1, hex_frustrum)

  # far

  add_line(:f1, :f2, hex_frustrum)
  add_line(:f2, :f4, hex_frustrum)
  add_line(:f4, :f3, hex_frustrum)
  add_line(:f3, :f1, hex_frustrum)

  # sides

  add_line(:n1, :f1, hex_frustrum)
  add_line(:n2, :f2, hex_frustrum)
  add_line(:n3, :f3, hex_frustrum)
  add_line(:n4, :f4, hex_frustrum)

  # cone

  add_line(:p, :n1, hex_cone)
  add_line(:p, :n2, hex_cone)
  add_line(:p, :n3, hex_cone)
  add_line(:p, :n4, hex_cone)

  # up

  add_line(:u1, :u2, hex_up)
  add_line(:u2, :u3, hex_up)
  add_line(:u3, :u1, hex_up)

  # target

  add_line(:c, :t, hex_target)
  add_line(:p, :c, hex_cross)

  # cross

  add_line(:cn1, :cn2, hex_cross)
  add_line(:cn3, :cn4, hex_cross)

  add_line(:cf1, :cf2, hex_cross)
  add_line(:cf3, :cf4, hex_cross)

  super(@geometry, @material, LinePieces)

  @camera = camera

  @matrix = camera.matrix_world
  @matrix_auto_update = false

  update_points
end

Instance Attribute Details

#cameraObject

Returns the value of attribute camera.



5
6
7
# File 'lib/mittsu/extras/helpers/camera_helper.rb', line 5

def camera
  @camera
end

#geometryObject

Returns the value of attribute geometry.



5
6
7
# File 'lib/mittsu/extras/helpers/camera_helper.rb', line 5

def geometry
  @geometry
end

#materialObject

Returns the value of attribute material.



5
6
7
# File 'lib/mittsu/extras/helpers/camera_helper.rb', line 5

def material
  @material
end

#matrixObject

Returns the value of attribute matrix.



5
6
7
# File 'lib/mittsu/extras/helpers/camera_helper.rb', line 5

def matrix
  @matrix
end

#matrix_auto_updateObject

Returns the value of attribute matrix_auto_update.



5
6
7
# File 'lib/mittsu/extras/helpers/camera_helper.rb', line 5

def matrix_auto_update
  @matrix_auto_update
end

#point_mapObject

Returns the value of attribute point_map.



5
6
7
# File 'lib/mittsu/extras/helpers/camera_helper.rb', line 5

def point_map
  @point_map
end

Instance Method Details

#update_pointsObject



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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/mittsu/extras/helpers/camera_helper.rb', line 81

def update_points
  w = 1.0
  h = 1.0

  # we need just camera projection matrix
  # world matrix must be identity

  @_camera.projection_matrix.copy(@camera.projection_matrix)

  # center / target

  set_point(:c, 0.0, 0.0, -1.0)
  set_point(:t, 0.0, 0.0, 1.0)

  # near

  set_point(:n1, -w, -h, -1.0)
  set_point(:n2,  w, -h, -1.0)
  set_point(:n3, -w,  h, -1.0)
  set_point(:n4,  w,  h, -1.0)

  # far

  set_point(:f1, -w, -h, 1.0)
  set_point(:f2,  w, -h, 1.0)
  set_point(:f3, -w,  h, 1.0)
  set_point(:f4,  w,  h, 1.0)

  # up

  set_point(:u1,  w * 0.7, h * 1.1, -1.0)
  set_point(:u2, -w * 0.7, h * 1.1, -1.0)
  set_point(:u3,      0.0, h * 2.0, -1.0)

  # cross

  set_point(:cf1,  -w, 0.0, 1.0)
  set_point(:cf2,   w, 0.0, 1.0)
  set_point(:cf3, 0.0,  -h, 1.0)
  set_point(:cf4, 0.0,   h, 1.0)

  set_point(:cn1,  -w, 0.0, -1.0)
  set_point(:cn2,   w, 0.0, -1.0)
  set_point(:cn3, 0.0,  -h, -1.0)
  set_point(:cn4, 0.0,   h, -1.0)

  @geometry.vertices_need_update = true
end