mittsu 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/examples/01_-_Default1noCulling.png +0 -0
- data/examples/01_scene_example.rb +14 -0
- data/examples/02_box_mesh_example.rb +30 -0
- data/examples/02_sphere_mesh_example.rb +30 -0
- data/examples/03_complex_object_example.rb +52 -0
- data/examples/04_ambient_light_example.rb +33 -0
- data/examples/04_dir_light_example.rb +36 -0
- data/examples/04_hemi_light_example.rb +30 -0
- data/examples/04_point_light_example.rb +50 -0
- data/examples/04_spot_light_example.rb +44 -0
- data/examples/05_earth_example.rb +42 -0
- data/examples/05_earth_moon_example.rb +46 -0
- data/examples/05_texture_example.rb +32 -0
- data/examples/06_cube_texture_example.rb +36 -0
- data/examples/06_skybox_example.rb +60 -0
- data/examples/07_earth_normal_example.rb +36 -0
- data/examples/08_shadow_example.rb +87 -0
- data/examples/09_line_example.rb +52 -0
- data/examples/10_obj_loader_example.rb +68 -0
- data/examples/11_character_input_example.rb +18 -0
- data/examples/11_continuous_keyboard_input_example.rb +35 -0
- data/examples/11_keyboard_input_example.rb +43 -0
- data/examples/12_mouse_click_example.rb +38 -0
- data/examples/12_mouse_motion_example.rb +35 -0
- data/examples/12_mouse_scroll_example.rb +36 -0
- data/examples/12_orbit_zoom_example.rb +68 -0
- data/examples/13_joystick_example.rb +80 -0
- data/examples/cubemap/tron_bk.png +0 -0
- data/examples/cubemap/tron_dn.png +0 -0
- data/examples/cubemap/tron_ft.png +0 -0
- data/examples/cubemap/tron_lf.png +0 -0
- data/examples/cubemap/tron_rt.png +0 -0
- data/examples/cubemap/tron_up.png +0 -0
- data/examples/earth.png +0 -0
- data/examples/earth_normal.png +0 -0
- data/examples/example_helper.rb +2 -0
- data/examples/male-02-1noCulling.png +0 -0
- data/examples/male02.mtl +54 -0
- data/examples/male02.obj +13888 -0
- data/examples/moon.png +0 -0
- data/examples/orig_02_-_Defaul1noCulling.png +0 -0
- data/examples/texture.png +0 -0
- data/lib/mittsu.rb +15 -0
- data/lib/mittsu/cameras.rb +4 -0
- data/lib/mittsu/cameras/camera.rb +34 -0
- data/lib/mittsu/cameras/cube_camera.rb +74 -0
- data/lib/mittsu/cameras/orthographic_camera.rb +53 -0
- data/lib/mittsu/cameras/perspective_camera.rb +115 -0
- data/lib/mittsu/constants.rb +160 -0
- data/lib/mittsu/core.rb +10 -0
- data/lib/mittsu/core/buffer_attribute.rb +87 -0
- data/lib/mittsu/core/buffer_geometry.rb +694 -0
- data/lib/mittsu/core/clock.rb +44 -0
- data/lib/mittsu/core/dynamic_buffer_attribute.rb +16 -0
- data/lib/mittsu/core/event_dispatcher.rb +39 -0
- data/lib/mittsu/core/face3.rb +30 -0
- data/lib/mittsu/core/geometry.rb +596 -0
- data/lib/mittsu/core/hash_array.rb +36 -0
- data/lib/mittsu/core/hash_object.rb +19 -0
- data/lib/mittsu/core/object_3d.rb +421 -0
- data/lib/mittsu/core/raycaster.rb +78 -0
- data/lib/mittsu/extras.rb +3 -0
- data/lib/mittsu/extras/geometries.rb +2 -0
- data/lib/mittsu/extras/geometries/box_geometry.rb +108 -0
- data/lib/mittsu/extras/geometries/sphere_geometry.rb +88 -0
- data/lib/mittsu/extras/helpers.rb +1 -0
- data/lib/mittsu/extras/helpers/camera_helper.rb +155 -0
- data/lib/mittsu/extras/image.rb +3 -0
- data/lib/mittsu/extras/image_utils.rb +80 -0
- data/lib/mittsu/lights.rb +7 -0
- data/lib/mittsu/lights/ambient_light.rb +16 -0
- data/lib/mittsu/lights/area_light.rb +24 -0
- data/lib/mittsu/lights/directional_light.rb +131 -0
- data/lib/mittsu/lights/hemisphere_light.rb +29 -0
- data/lib/mittsu/lights/light.rb +21 -0
- data/lib/mittsu/lights/point_light.rb +27 -0
- data/lib/mittsu/lights/spot_light.rb +104 -0
- data/lib/mittsu/loaders.rb +7 -0
- data/lib/mittsu/loaders/cache.rb +53 -0
- data/lib/mittsu/loaders/file_loader.rb +22 -0
- data/lib/mittsu/loaders/image_loader.rb +32 -0
- data/lib/mittsu/loaders/loader.rb +212 -0
- data/lib/mittsu/loaders/loading_manager.rb +17 -0
- data/lib/mittsu/loaders/mtl_loader.rb +242 -0
- data/lib/mittsu/loaders/obj_mtl_loader.rb +225 -0
- data/lib/mittsu/materials.rb +7 -0
- data/lib/mittsu/materials/line_basic_material.rb +39 -0
- data/lib/mittsu/materials/material.rb +156 -0
- data/lib/mittsu/materials/mesh_basic_material.rb +122 -0
- data/lib/mittsu/materials/mesh_face_material.rb +30 -0
- data/lib/mittsu/materials/mesh_lambert_material.rb +126 -0
- data/lib/mittsu/materials/mesh_phong_material.rb +152 -0
- data/lib/mittsu/materials/shader_material.rb +108 -0
- data/lib/mittsu/math.rb +105 -0
- data/lib/mittsu/math/box2.rb +135 -0
- data/lib/mittsu/math/box3.rb +194 -0
- data/lib/mittsu/math/color.rb +252 -0
- data/lib/mittsu/math/color_keywords.rb +151 -0
- data/lib/mittsu/math/euler.rb +182 -0
- data/lib/mittsu/math/frustum.rb +106 -0
- data/lib/mittsu/math/line3.rb +76 -0
- data/lib/mittsu/math/matrix3.rb +163 -0
- data/lib/mittsu/math/matrix4.rb +581 -0
- data/lib/mittsu/math/plane.rb +128 -0
- data/lib/mittsu/math/quaternion.rb +309 -0
- data/lib/mittsu/math/ray.rb +292 -0
- data/lib/mittsu/math/sphere.rb +91 -0
- data/lib/mittsu/math/spline.rb +128 -0
- data/lib/mittsu/math/triangle.rb +121 -0
- data/lib/mittsu/math/vector2.rb +238 -0
- data/lib/mittsu/math/vector3.rb +491 -0
- data/lib/mittsu/math/vector4.rb +414 -0
- data/lib/mittsu/objects.rb +3 -0
- data/lib/mittsu/objects/group.rb +8 -0
- data/lib/mittsu/objects/line.rb +143 -0
- data/lib/mittsu/objects/mesh.rb +243 -0
- data/lib/mittsu/renderers.rb +1 -0
- data/lib/mittsu/renderers/glfw_window.rb +216 -0
- data/lib/mittsu/renderers/opengl/opengl_debug.rb +38 -0
- data/lib/mittsu/renderers/opengl/opengl_program.rb +402 -0
- data/lib/mittsu/renderers/opengl/opengl_shader.rb +58 -0
- data/lib/mittsu/renderers/opengl/opengl_state.rb +207 -0
- data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +416 -0
- data/lib/mittsu/renderers/opengl_render_target.rb +87 -0
- data/lib/mittsu/renderers/opengl_renderer.rb +3376 -0
- data/lib/mittsu/renderers/shaders/shader_chunk.rb +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +40 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +60 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +15 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +21 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +62 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +21 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +7 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +17 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +26 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +15 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +43 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +196 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +243 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +58 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +2 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +11 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +15 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +9 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +11 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +13 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +20 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +27 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +217 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +19 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +9 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +8 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +47 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +20 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +20 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +17 -0
- data/lib/mittsu/renderers/shaders/shader_lib.rb +420 -0
- data/lib/mittsu/renderers/shaders/uniforms_lib.rb +107 -0
- data/lib/mittsu/renderers/shaders/uniforms_utils.rb +31 -0
- data/lib/mittsu/scenes.rb +1 -0
- data/lib/mittsu/scenes/scene.rb +27 -0
- data/lib/mittsu/textures.rb +5 -0
- data/lib/mittsu/textures/compressed_texture.rb +30 -0
- data/lib/mittsu/textures/cube_texture.rb +19 -0
- data/lib/mittsu/textures/data_texture.rb +17 -0
- data/lib/mittsu/textures/texture.rb +92 -0
- data/lib/mittsu/textures/video_texture.rb +17 -0
- data/lib/mittsu/version.rb +4 -0
- data/mittsu.gemspec +31 -0
- metadata +357 -0
data/examples/moon.png
ADDED
Binary file
|
Binary file
|
Binary file
|
data/lib/mittsu.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "pry"
|
2
|
+
|
3
|
+
require "mittsu/version"
|
4
|
+
require "mittsu/math"
|
5
|
+
require "mittsu/core"
|
6
|
+
require "mittsu/cameras"
|
7
|
+
require "mittsu/extras"
|
8
|
+
require "mittsu/lights"
|
9
|
+
require "mittsu/loaders"
|
10
|
+
require "mittsu/materials"
|
11
|
+
require "mittsu/objects"
|
12
|
+
require "mittsu/renderers"
|
13
|
+
require "mittsu/scenes"
|
14
|
+
require "mittsu/textures"
|
15
|
+
require "mittsu/constants"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'mittsu'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
class Camera < Object3D
|
5
|
+
attr_accessor :projection_matrix, :matrix_world_inverse
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
|
10
|
+
@type = 'Camera'
|
11
|
+
@matrix_world_inverse = Matrix4.new
|
12
|
+
@projection_matrix = Matrix4.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_world_direction(target = Vector3.new)
|
16
|
+
@_quaternion ||= Quaternion.new
|
17
|
+
self.get_world_quaternion(@_quaternion)
|
18
|
+
target.set(0.0, 0.0, -1.0).qpply_quaternion(@_quaternion)
|
19
|
+
end
|
20
|
+
|
21
|
+
def look_at(vector)
|
22
|
+
@_m1 ||= Matrix4.new
|
23
|
+
@_m1.look_at(@position, vector, @up)
|
24
|
+
@quaternion.set_from_rotation_matrix(@_m1)
|
25
|
+
end
|
26
|
+
|
27
|
+
def clone(camera = Camera.new)
|
28
|
+
super
|
29
|
+
camera.matrix_world_inverse.copy(@matrix_world_inverse)
|
30
|
+
camera.projection_matrix.copy(@projection_matrix)
|
31
|
+
camera
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'mittsu'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
class CubeCamera < Object3D
|
5
|
+
attr_accessor :render_target
|
6
|
+
|
7
|
+
def initialize(near, far, cube_resolution)
|
8
|
+
super()
|
9
|
+
|
10
|
+
@type = 'CubeCamera'
|
11
|
+
|
12
|
+
fov = 90.0
|
13
|
+
aspect = 1.0
|
14
|
+
|
15
|
+
@camera_px = Mittsu::PerspectiveCamera.new(fov, aspect, near, far)
|
16
|
+
@camera_px.up.set(0.0, -1.0, 0.0)
|
17
|
+
@camera_px.look_at(Mittsu::Vector3.new(1.0, 0.0, 0.0))
|
18
|
+
self.add(@camera_px)
|
19
|
+
|
20
|
+
@camera_nx = Mittsu::PerspectiveCamera.new(fov, aspect, near, far)
|
21
|
+
@camera_nx.up.set(0.0, -1.0, 0.0)
|
22
|
+
@camera_nx.look_at(Mittsu::Vector3.new(-1.0, 0.0, 0.0))
|
23
|
+
self.add(@camera_nx)
|
24
|
+
|
25
|
+
@camera_py = Mittsu::PerspectiveCamera.new(fov, aspect, near, far)
|
26
|
+
@camera_py.up.set(0.0, 0.0, 1.0)
|
27
|
+
@camera_py.look_at(Mittsu::Vector3.new(0.0, 1.0, 0.0))
|
28
|
+
self.add(@camera_py)
|
29
|
+
|
30
|
+
@camera_ny = Mittsu::PerspectiveCamera.new(fov, aspect, near, far)
|
31
|
+
@camera_ny.up.set(0.0, 0.0, 1.0)
|
32
|
+
@camera_ny.look_at(Mittsu::Vector3.new(0.0, -1.0, 0.0))
|
33
|
+
self.add(@camera_ny)
|
34
|
+
|
35
|
+
@camera_pz = Mittsu::PerspectiveCamera.new(fov, aspect, near, far)
|
36
|
+
@camera_pz.up.set(0.0, -1.0, 0.0)
|
37
|
+
@camera_pz.look_at(Mittsu::Vector3.new(0.0, 0.0, 1.0))
|
38
|
+
self.add(@camera_pz)
|
39
|
+
|
40
|
+
@camera_nz = Mittsu::PerspectiveCamera.new(fov, aspect, near, far)
|
41
|
+
@camera_nz.up.set(0.0, -1.0, 0.0)
|
42
|
+
@camera_nz.look_at(Mittsu::Vector3.new(0.0, 0.0, -1.0))
|
43
|
+
self.add(@camera_nz)
|
44
|
+
|
45
|
+
@render_target = Mittsu::OpenGLRenderTargetCube(cube_resolution, cube_resolution, format: Mittsu::RGBFormat, mag_filter: Mittsu::LinearFilter, min_filter: Mittsu::LinearFilter)
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_cube_map(renderer, scene)
|
49
|
+
generate_mipmaps = render_target.generate_mipmaps
|
50
|
+
|
51
|
+
render_target.generate_mipmaps = false
|
52
|
+
|
53
|
+
render_target.active_cube_face = 0
|
54
|
+
renderer.render(scene, @camera_px, render_target)
|
55
|
+
|
56
|
+
render_target.active_cube_face = 1
|
57
|
+
renderer.render(scene, @camera_nx, render_target)
|
58
|
+
|
59
|
+
render_target.active_cube_face = 2
|
60
|
+
renderer.render(scene, @camera_py, render_target)
|
61
|
+
|
62
|
+
render_target.active_cube_face = 3
|
63
|
+
renderer.render(scene, @camera_ny, render_target)
|
64
|
+
|
65
|
+
render_target.active_cube_face = 4
|
66
|
+
renderer.render(scene, @camera_pz, render_target)
|
67
|
+
|
68
|
+
render_target.generate_mipmaps = generate_mipmaps
|
69
|
+
|
70
|
+
render_target.active_cube_face = 5
|
71
|
+
renderer.render(scene, @camera_nz, render_target)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'mittsu'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
class OrthographicCamera < Camera
|
5
|
+
attr_accessor :zoom, :left, :right, :top, :bottom, :near, :far
|
6
|
+
|
7
|
+
def initialize(left, right, top, bottom, near = 0.1, far = 2000.0)
|
8
|
+
super()
|
9
|
+
|
10
|
+
@type = 'OrthographicCamera'
|
11
|
+
|
12
|
+
@zoom = 1.0
|
13
|
+
|
14
|
+
@left = left.to_f
|
15
|
+
@right = right.to_f
|
16
|
+
@top = top.to_f
|
17
|
+
@bottom = bottom.to_f
|
18
|
+
|
19
|
+
@near = near.to_f
|
20
|
+
@far = far.to_f
|
21
|
+
|
22
|
+
update_projection_matrix
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_projection_matrix
|
26
|
+
dx = (right - left) / (2.0 * zoom)
|
27
|
+
dy = (top - bottom) / (2.0 * zoom)
|
28
|
+
cx = (right - left) / 2.0
|
29
|
+
cy = (top - bottom) / 2.0
|
30
|
+
|
31
|
+
projection_matrix.make_orthographic(cx - dx, cx + dx, cy + dy, cy - dy, near, far)
|
32
|
+
end
|
33
|
+
|
34
|
+
def clone
|
35
|
+
camera = Mittsu::OrthographicCamera.new
|
36
|
+
super(camera)
|
37
|
+
|
38
|
+
camera.zoom = zoom
|
39
|
+
|
40
|
+
camera.left = left
|
41
|
+
camera.right = right
|
42
|
+
camera.top = top
|
43
|
+
camera.bottom = bottom
|
44
|
+
|
45
|
+
camera.near = near
|
46
|
+
camera.far = far
|
47
|
+
|
48
|
+
camera.projection_matrix.copy()
|
49
|
+
|
50
|
+
camera
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'mittsu'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
class PerspectiveCamera < Camera
|
5
|
+
attr_accessor :zoom, :fov, :aspect, :near, :far
|
6
|
+
|
7
|
+
def initialize(fov = 50.0, aspect = 1.0, near = 0.1, far = 2000.0)
|
8
|
+
super()
|
9
|
+
|
10
|
+
@type = 'PerspectiveCamera'
|
11
|
+
|
12
|
+
@zoom = 1.0
|
13
|
+
|
14
|
+
@fov = fov.to_f
|
15
|
+
@aspect = aspect.to_f
|
16
|
+
@near = near.to_f
|
17
|
+
@far = far.to_f
|
18
|
+
|
19
|
+
update_projection_matrix
|
20
|
+
end
|
21
|
+
|
22
|
+
# Uses Focal Length (in mm) to estimate and set FOV
|
23
|
+
# 35mm (fullframe) camera is used if frame size is not specified;
|
24
|
+
# Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
|
25
|
+
def set_lens(focal_length, frame_height = 24.0)
|
26
|
+
@fov = 2.0 * Math.rad_to_deg(Math.atan(frame_height / (focal_length * 2.0)))
|
27
|
+
update_projection_matrix
|
28
|
+
end
|
29
|
+
|
30
|
+
# Sets an offset in a larger frustum. This is useful for multi-window or
|
31
|
+
# multi-monitor/multi-machine setups.
|
32
|
+
#
|
33
|
+
# For example, if you have 3x2 monitors and each monitor is 1920x1080 and
|
34
|
+
# the monitors are in grid like this
|
35
|
+
#
|
36
|
+
# +---+---+---+
|
37
|
+
# | A | B | C |
|
38
|
+
# +---+---+---+
|
39
|
+
# | D | E | F |
|
40
|
+
# +---+---+---+
|
41
|
+
#
|
42
|
+
# then for each monitor you would call it like this
|
43
|
+
#
|
44
|
+
# var w = 1920;
|
45
|
+
# var h = 1080;
|
46
|
+
# var fullWidth = w * 3;
|
47
|
+
# var fullHeight = h * 2;
|
48
|
+
#
|
49
|
+
# --A--
|
50
|
+
# camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
|
51
|
+
# --B--
|
52
|
+
# camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
|
53
|
+
# --C--
|
54
|
+
# camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
|
55
|
+
# --D--
|
56
|
+
# camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
|
57
|
+
# --E--
|
58
|
+
# camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
|
59
|
+
# --F--
|
60
|
+
# camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
|
61
|
+
#
|
62
|
+
# Note there is no reason monitors have to be the same size or in a grid.
|
63
|
+
|
64
|
+
def set_view_offset(full_width, full_height, x, y, width, height)
|
65
|
+
@full_width = full_width
|
66
|
+
@full_height = full_height
|
67
|
+
@x = x
|
68
|
+
@y = y
|
69
|
+
@width = width
|
70
|
+
@height = height
|
71
|
+
|
72
|
+
update_projection_matrix
|
73
|
+
end
|
74
|
+
|
75
|
+
def update_projection_matrix
|
76
|
+
new_fov = Math.rad_to_deg(2.0 * Math.atan(Math.tan(Math.deg_to_rad(@fov) * 0.5) / @zoom))
|
77
|
+
|
78
|
+
if @full_width
|
79
|
+
aspect = @full_width / @full_height
|
80
|
+
top = Math.tan(Math.deg_to_rad(new_fov * 0.5)) * @near
|
81
|
+
bottom = -top
|
82
|
+
left = aspect * bottom
|
83
|
+
right = aspect * top
|
84
|
+
width = (right - left).abs
|
85
|
+
height = (top - bottom).abs
|
86
|
+
|
87
|
+
projection_matrix.make_frustum(
|
88
|
+
left + @x * width / @full_width,
|
89
|
+
left + (@x + @width) * width / @full_width,
|
90
|
+
top - (@y + @height) * height / @full_height,
|
91
|
+
top - @y * height / @full_height,
|
92
|
+
@near,
|
93
|
+
@far
|
94
|
+
)
|
95
|
+
else
|
96
|
+
projection_matrix.make_perspective(new_fov, @aspect, @near, @far)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def clone
|
101
|
+
camera = Mittsu::PerspectiveCamera.new
|
102
|
+
super(camera)
|
103
|
+
|
104
|
+
camera.zoom = zoom
|
105
|
+
camera.fov = fov
|
106
|
+
camera.aspect = aspect
|
107
|
+
camera.near = near
|
108
|
+
camera.far = far
|
109
|
+
|
110
|
+
camera.projection_matrix.copy(projection_matrix)
|
111
|
+
|
112
|
+
camera
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
module Mittsu
|
2
|
+
MOUSE_LEFT = 0
|
3
|
+
MOUSE_MIDDLE = 1
|
4
|
+
MOUSE_RIGHT = 2
|
5
|
+
|
6
|
+
# GL STATE CONSTANTS
|
7
|
+
|
8
|
+
CullFaceNone = 0
|
9
|
+
CullFaceBack = 1
|
10
|
+
CullFaceFront = 2
|
11
|
+
CullFaceFrontBack = 3
|
12
|
+
|
13
|
+
FrontFaceDirectionCW = 0
|
14
|
+
FrontFaceDirectionCCW = 1
|
15
|
+
|
16
|
+
# SHADOWING TYPES
|
17
|
+
|
18
|
+
BasicShadowMap = 0
|
19
|
+
PCFShadowMap = 1
|
20
|
+
PCFSoftShadowMap = 2
|
21
|
+
|
22
|
+
# MATERIAL CONSTANTS
|
23
|
+
|
24
|
+
# side
|
25
|
+
|
26
|
+
FrontSide = 0
|
27
|
+
BackSide = 1
|
28
|
+
DoubleSide = 2
|
29
|
+
|
30
|
+
# shading
|
31
|
+
|
32
|
+
NoShading = false
|
33
|
+
FlatShading = 1
|
34
|
+
SmoothShading = 2
|
35
|
+
|
36
|
+
# colors
|
37
|
+
|
38
|
+
NoColors = false
|
39
|
+
FaceColors = 1
|
40
|
+
VertexColors = 2
|
41
|
+
|
42
|
+
# blending modes
|
43
|
+
|
44
|
+
NoBlending = false
|
45
|
+
NormalBlending = 1
|
46
|
+
AdditiveBlending = 2
|
47
|
+
SubtractiveBlending = 3
|
48
|
+
MultiplyBlending = 4
|
49
|
+
CustomBlending = 5
|
50
|
+
|
51
|
+
# custom blending equations
|
52
|
+
# (numbers start from 100 not to clash with other
|
53
|
+
# mappings to OpenGL constants defined in texture.rb)
|
54
|
+
|
55
|
+
AddEquation = 100
|
56
|
+
SubtractEquation = 101
|
57
|
+
ReverseSubtractEquation = 102
|
58
|
+
MinEquation = 103
|
59
|
+
MaxEquation = 104
|
60
|
+
|
61
|
+
# custom blending destination factors
|
62
|
+
ZeroFactor = 200
|
63
|
+
OneFactor = 201
|
64
|
+
SrcColorFactor = 202
|
65
|
+
OneMinusSrcColorFactor = 203
|
66
|
+
SrcAlphaFactor = 204
|
67
|
+
OneMinusSrcAlphaFactor = 205
|
68
|
+
DstAlphaFactor = 206
|
69
|
+
OneMinusDstAlphaFactor = 207
|
70
|
+
|
71
|
+
# custom blending source factors
|
72
|
+
|
73
|
+
#ZeroFactor = 200
|
74
|
+
#OneFactor = 201
|
75
|
+
#SrcAlphaFactor = 204
|
76
|
+
#OneMinusSrcAlphaFactor = 205
|
77
|
+
#DstAlphaFactor = 206
|
78
|
+
#OneMinusDstAlphaFactor = 207
|
79
|
+
DstColorFactor = 208
|
80
|
+
OneMinusDstColorFactor = 209
|
81
|
+
SrcAlphaSaturateFactor = 210
|
82
|
+
|
83
|
+
# TEXTURE CONSTANTS
|
84
|
+
|
85
|
+
MultiplyOperation = 0
|
86
|
+
MixOperation = 1
|
87
|
+
AddOperation = 2
|
88
|
+
|
89
|
+
# Mapping modes
|
90
|
+
|
91
|
+
UVMapping = 300
|
92
|
+
|
93
|
+
CubeReflectionMapping = 301
|
94
|
+
CubeRefractionMapping = 302
|
95
|
+
|
96
|
+
EquirectangularReflectionMapping = 303
|
97
|
+
EquirectangularRefractionMapping = 304
|
98
|
+
|
99
|
+
SphericalReflectionMapping = 305
|
100
|
+
|
101
|
+
# Wrapping modes
|
102
|
+
|
103
|
+
RepeatWrapping = 1000
|
104
|
+
ClampToEdgeWrapping = 1001
|
105
|
+
MirroredRepeatWrapping = 1002
|
106
|
+
|
107
|
+
# Filters
|
108
|
+
|
109
|
+
NearestFilter = 1003
|
110
|
+
NearestMipMapNearestFilter = 1004
|
111
|
+
NearestMipMapLinearFilter = 1005
|
112
|
+
LinearFilter = 1006
|
113
|
+
LinearMipMapNearestFilter = 1007
|
114
|
+
LinearMipMapLinearFilter = 1008
|
115
|
+
|
116
|
+
# Data types
|
117
|
+
|
118
|
+
UnsignedByteType = 1009
|
119
|
+
ByteType = 1010
|
120
|
+
ShortType = 1011
|
121
|
+
UnsignedShortType = 1012
|
122
|
+
IntType = 1013
|
123
|
+
UnsignedIntType = 1014
|
124
|
+
FloatType = 1015
|
125
|
+
HalfFloatType = 1025
|
126
|
+
|
127
|
+
# Pixel types
|
128
|
+
|
129
|
+
#UnsignedByteType = 1009
|
130
|
+
UnsignedShort4444Type = 1016
|
131
|
+
UnsignedShort5551Type = 1017
|
132
|
+
UnsignedShort565Type = 1018
|
133
|
+
|
134
|
+
# Pixel formats
|
135
|
+
|
136
|
+
AlphaFormat = 1019
|
137
|
+
RGBFormat = 1020
|
138
|
+
RGBAFormat = 1021
|
139
|
+
LuminanceFormat = 1022
|
140
|
+
LuminanceAlphaFormat = 1023
|
141
|
+
# RGBEFormat handled as RGBAFormat in shaders
|
142
|
+
RGBEFormat = RGBAFormat #1024
|
143
|
+
|
144
|
+
# DDS / ST3C Compressed texture formats
|
145
|
+
|
146
|
+
RGB_S3TC_DXT1_Format = 2001
|
147
|
+
RGBA_S3TC_DXT1_Format = 2002
|
148
|
+
RGBA_S3TC_DXT3_Format = 2003
|
149
|
+
RGBA_S3TC_DXT5_Format = 2004
|
150
|
+
|
151
|
+
# PVRTC compressed texture formats
|
152
|
+
|
153
|
+
RGB_PVRTC_4BPPV1_Format = 2100
|
154
|
+
RGB_PVRTC_2BPPV1_Format = 2101
|
155
|
+
RGBA_PVRTC_4BPPV1_Format = 2102
|
156
|
+
RGBA_PVRTC_2BPPV1_Format = 2103
|
157
|
+
|
158
|
+
LineStrip = 0
|
159
|
+
LinePieces = 1
|
160
|
+
end
|