mittsu 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +18 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +1158 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -1
- data/LICENSE.txt +1 -1
- data/README.md +173 -7
- data/circle.yml +20 -0
- data/install-glfw-3.1.2.sh +14 -0
- data/lib/mittsu.rb +0 -2
- data/lib/mittsu/extras/image_utils.rb +59 -55
- data/lib/mittsu/renderers/glfw_window.rb +17 -2
- data/lib/mittsu/renderers/opengl_renderer.rb +1 -1
- data/lib/mittsu/renderers/shaders/shader_lib.rb +4 -4
- data/lib/mittsu/version.rb +1 -1
- data/mittsu.gemspec +11 -5
- metadata +53 -71
- data/.travis.yml +0 -3
- data/examples/01_-_Default1noCulling.png +0 -0
- data/examples/01_scene_example.rb +0 -14
- data/examples/02_box_mesh_example.rb +0 -30
- data/examples/02_sphere_mesh_example.rb +0 -30
- data/examples/03_complex_object_example.rb +0 -52
- data/examples/04_ambient_light_example.rb +0 -33
- data/examples/04_dir_light_example.rb +0 -36
- data/examples/04_hemi_light_example.rb +0 -30
- data/examples/04_point_light_example.rb +0 -50
- data/examples/04_spot_light_example.rb +0 -44
- data/examples/05_earth_example.rb +0 -42
- data/examples/05_earth_moon_example.rb +0 -46
- data/examples/05_texture_example.rb +0 -32
- data/examples/06_cube_texture_example.rb +0 -36
- data/examples/06_skybox_example.rb +0 -60
- data/examples/07_earth_normal_example.rb +0 -36
- data/examples/08_shadow_example.rb +0 -87
- data/examples/09_line_example.rb +0 -52
- data/examples/10_obj_loader_example.rb +0 -68
- data/examples/11_character_input_example.rb +0 -18
- data/examples/11_continuous_keyboard_input_example.rb +0 -35
- data/examples/11_keyboard_input_example.rb +0 -43
- data/examples/12_mouse_click_example.rb +0 -38
- data/examples/12_mouse_motion_example.rb +0 -35
- data/examples/12_mouse_scroll_example.rb +0 -36
- data/examples/12_orbit_zoom_example.rb +0 -68
- data/examples/13_joystick_example.rb +0 -80
- 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 +0 -2
- data/examples/male-02-1noCulling.png +0 -0
- data/examples/male02.mtl +0 -54
- data/examples/male02.obj +0 -13888
- data/examples/moon.png +0 -0
- data/examples/orig_02_-_Defaul1noCulling.png +0 -0
- data/examples/texture.png +0 -0
@@ -1,87 +0,0 @@
|
|
1
|
-
require_relative './example_helper'
|
2
|
-
|
3
|
-
SCREEN_WIDTH = 800
|
4
|
-
SCREEN_HEIGHT = 600
|
5
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
6
|
-
|
7
|
-
scene = Mittsu::Scene.new
|
8
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
9
|
-
|
10
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '08 Shadow Example'
|
11
|
-
renderer.shadow_map_enabled = true
|
12
|
-
renderer.shadow_map_type = Mittsu::PCFSoftShadowMap
|
13
|
-
|
14
|
-
floor = Mittsu::Mesh.new(
|
15
|
-
Mittsu::BoxGeometry.new(100.0, 1.0, 100.0),
|
16
|
-
Mittsu::MeshPhongMaterial.new(color: 0x00ff00)
|
17
|
-
)
|
18
|
-
floor.position.y = -1.0
|
19
|
-
floor.receive_shadow = true
|
20
|
-
scene.add(floor)
|
21
|
-
|
22
|
-
NB = 15
|
23
|
-
NR = 5
|
24
|
-
balls = NB.times.map do |index|
|
25
|
-
NR.times.map do |r|
|
26
|
-
ring = (3 + r)
|
27
|
-
i = r * 0.1 + (index.to_f / NB.to_f) * Math::PI * 2
|
28
|
-
Mittsu::Mesh.new(
|
29
|
-
Mittsu::SphereGeometry.new(0.5, 16, 16),
|
30
|
-
Mittsu::MeshLambertMaterial.new(color: r.even? ? 0x00ffff : 0xff00ff)
|
31
|
-
).tap do |b|
|
32
|
-
b.cast_shadow = true
|
33
|
-
b.receive_shadow = true
|
34
|
-
b.position.z = Math.cos(i) * ring
|
35
|
-
b.position.x = Math.sin(i) * ring
|
36
|
-
scene.add(b)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end.flatten
|
40
|
-
|
41
|
-
ball = Mittsu::Mesh.new(
|
42
|
-
Mittsu::SphereGeometry.new(1.0, 32, 32),
|
43
|
-
Mittsu::MeshLambertMaterial.new(color: 0xffffff)
|
44
|
-
)
|
45
|
-
ball.cast_shadow = true
|
46
|
-
ball.receive_shadow = true
|
47
|
-
scene.add(ball)
|
48
|
-
|
49
|
-
light = Mittsu::SpotLight.new(0xffffff, 1.0)
|
50
|
-
light.position.set(20.0, 30.0, 0.0)
|
51
|
-
|
52
|
-
light.cast_shadow = true
|
53
|
-
light.shadow_darkness = 0.5
|
54
|
-
|
55
|
-
light.shadow_map_width = 1024
|
56
|
-
light.shadow_map_height = 1024
|
57
|
-
|
58
|
-
light.shadow_camera_near = 1.0
|
59
|
-
light.shadow_camera_far = 100.0
|
60
|
-
light.shadow_camera_fov = 60.0
|
61
|
-
|
62
|
-
light.shadow_camera_visible = true
|
63
|
-
scene.add(light)
|
64
|
-
|
65
|
-
camera.position.z = 10.0
|
66
|
-
camera.position.y = 10.0
|
67
|
-
camera.look_at(floor.position)
|
68
|
-
|
69
|
-
renderer.window.on_resize do |width, height|
|
70
|
-
renderer.set_viewport(0, 0, width, height)
|
71
|
-
camera.aspect = width.to_f / height.to_f
|
72
|
-
camera.update_projection_matrix
|
73
|
-
end
|
74
|
-
|
75
|
-
x = 0
|
76
|
-
renderer.window.run do
|
77
|
-
# break if x > 0
|
78
|
-
x += 1
|
79
|
-
light.position.x = Math::sin(x * 0.01) * 20.0
|
80
|
-
light.position.z = Math::cos(x * 0.01) * 20.0
|
81
|
-
|
82
|
-
balls.each_with_index do |b, i|
|
83
|
-
b.position.y = (1.0 + Math::sin(x * 0.05 + i)) * 2.0
|
84
|
-
end
|
85
|
-
|
86
|
-
renderer.render(scene, camera)
|
87
|
-
end
|
data/examples/09_line_example.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require_relative './example_helper'
|
2
|
-
|
3
|
-
SCREEN_WIDTH = 800
|
4
|
-
SCREEN_HEIGHT = 600
|
5
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
6
|
-
|
7
|
-
scene = Mittsu::Scene.new
|
8
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
9
|
-
|
10
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '09 Line Example'
|
11
|
-
|
12
|
-
ball = Mittsu::Mesh.new(
|
13
|
-
Mittsu::SphereGeometry.new(0.1),
|
14
|
-
Mittsu::MeshBasicMaterial.new(color: 0xff00ff)
|
15
|
-
)
|
16
|
-
scene.add(ball)
|
17
|
-
|
18
|
-
material = Mittsu::LineBasicMaterial.new(color: 0xff00ff)
|
19
|
-
|
20
|
-
geometry = Mittsu::Geometry.new()
|
21
|
-
NP = 10000
|
22
|
-
MD = 10.0
|
23
|
-
NR = 200
|
24
|
-
NP.times do |i|
|
25
|
-
d = (i.to_f / NP) * MD
|
26
|
-
r = (i.to_f / NP) * Math::PI * NR
|
27
|
-
x = Math.sin(r) * d
|
28
|
-
y = Math.cos(r) * d
|
29
|
-
geometry.vertices.push(Mittsu::Vector3.new(x, y, 0.0))
|
30
|
-
end
|
31
|
-
|
32
|
-
line = Mittsu::Line.new(geometry, material)
|
33
|
-
scene.add(line)
|
34
|
-
|
35
|
-
camera.position.z = 5.0
|
36
|
-
camera.position.y = 0.0
|
37
|
-
camera.look_at(line.position)
|
38
|
-
|
39
|
-
renderer.window.on_resize do |width, height|
|
40
|
-
renderer.set_viewport(0, 0, width, height)
|
41
|
-
camera.aspect = width.to_f / height.to_f
|
42
|
-
camera.update_projection_matrix
|
43
|
-
end
|
44
|
-
|
45
|
-
x = 0
|
46
|
-
renderer.window.run do
|
47
|
-
# break if x > 0
|
48
|
-
x += 1
|
49
|
-
line.rotation.z = x * 0.1
|
50
|
-
|
51
|
-
renderer.render(scene, camera)
|
52
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require_relative './example_helper'
|
2
|
-
|
3
|
-
SCREEN_WIDTH = 800
|
4
|
-
SCREEN_HEIGHT = 600
|
5
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
6
|
-
|
7
|
-
scene = Mittsu::Scene.new
|
8
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
9
|
-
|
10
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '10 OBJ Loader Example'
|
11
|
-
renderer.shadow_map_enabled = true
|
12
|
-
renderer.shadow_map_type = Mittsu::PCFSoftShadowMap
|
13
|
-
|
14
|
-
loader = Mittsu::OBJMTLLoader.new
|
15
|
-
|
16
|
-
object = loader.load('male02.obj', 'male02.mtl')
|
17
|
-
|
18
|
-
object.receive_shadow = true
|
19
|
-
object.cast_shadow = true
|
20
|
-
|
21
|
-
object.traverse do |child|
|
22
|
-
child.receive_shadow = true
|
23
|
-
child.cast_shadow = true
|
24
|
-
end
|
25
|
-
|
26
|
-
scene.add(object)
|
27
|
-
|
28
|
-
scene.print_tree
|
29
|
-
|
30
|
-
floor = Mittsu::Mesh.new(
|
31
|
-
Mittsu::BoxGeometry.new(1000.0, 1.0, 1000.0),
|
32
|
-
Mittsu::MeshPhongMaterial.new(color: 0xffffff)
|
33
|
-
)
|
34
|
-
floor.position.y = -1.0
|
35
|
-
floor.receive_shadow = true
|
36
|
-
scene.add(floor)
|
37
|
-
|
38
|
-
scene.add Mittsu::AmbientLight.new(0xffffff)
|
39
|
-
|
40
|
-
light = Mittsu::SpotLight.new(0xffffff, 1.0)
|
41
|
-
light.position.set(300.0, 200.0, 0.0)
|
42
|
-
|
43
|
-
light.cast_shadow = true
|
44
|
-
light.shadow_darkness = 0.5
|
45
|
-
|
46
|
-
light.shadow_map_width = 1024
|
47
|
-
light.shadow_map_height = 1024
|
48
|
-
|
49
|
-
light.shadow_camera_near = 1.0
|
50
|
-
light.shadow_camera_far = 2000.0
|
51
|
-
light.shadow_camera_fov = 60.0
|
52
|
-
|
53
|
-
light.shadow_camera_visible = false
|
54
|
-
scene.add(light)
|
55
|
-
|
56
|
-
camera.position.z = 200.0
|
57
|
-
camera.position.y = 100.0
|
58
|
-
|
59
|
-
renderer.window.on_resize do |width, height|
|
60
|
-
renderer.set_viewport(0, 0, width, height)
|
61
|
-
camera.aspect = width.to_f / height.to_f
|
62
|
-
camera.update_projection_matrix
|
63
|
-
end
|
64
|
-
|
65
|
-
renderer.window.run do
|
66
|
-
object.rotation.y += 0.1
|
67
|
-
renderer.render(scene, camera)
|
68
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative './example_helper'
|
2
|
-
|
3
|
-
SCREEN_WIDTH = 800
|
4
|
-
SCREEN_HEIGHT = 600
|
5
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
6
|
-
|
7
|
-
scene = Mittsu::Scene.new
|
8
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
9
|
-
|
10
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '11 Character Input Example'
|
11
|
-
|
12
|
-
renderer.window.on_character_input do |char|
|
13
|
-
print char
|
14
|
-
end
|
15
|
-
|
16
|
-
renderer.window.run do
|
17
|
-
renderer.render(scene, camera)
|
18
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require_relative './example_helper'
|
2
|
-
|
3
|
-
SCREEN_WIDTH = 800
|
4
|
-
SCREEN_HEIGHT = 600
|
5
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
6
|
-
|
7
|
-
scene = Mittsu::Scene.new
|
8
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
9
|
-
|
10
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '11 Continous Keyboard Example'
|
11
|
-
|
12
|
-
geometry = Mittsu::BoxGeometry.new(1.0, 1.0, 1.0)
|
13
|
-
material = Mittsu::MeshBasicMaterial.new(color: 0x00ff00)
|
14
|
-
cube = Mittsu::Mesh.new(geometry, material)
|
15
|
-
scene.add(cube)
|
16
|
-
|
17
|
-
camera.position.z = 5.0
|
18
|
-
|
19
|
-
renderer.window.on_resize do |width, height|
|
20
|
-
renderer.set_viewport(0, 0, width, height)
|
21
|
-
camera.aspect = width.to_f / height.to_f
|
22
|
-
camera.update_projection_matrix
|
23
|
-
end
|
24
|
-
|
25
|
-
renderer.window.run do
|
26
|
-
cube.rotation.x += 0.1
|
27
|
-
cube.rotation.y += 0.1
|
28
|
-
|
29
|
-
cube.position.y += 0.1 if renderer.window.key_down?(GLFW_KEY_UP)
|
30
|
-
cube.position.y -= 0.1 if renderer.window.key_down?(GLFW_KEY_DOWN)
|
31
|
-
cube.position.x -= 0.1 if renderer.window.key_down?(GLFW_KEY_LEFT)
|
32
|
-
cube.position.x += 0.1 if renderer.window.key_down?(GLFW_KEY_RIGHT)
|
33
|
-
|
34
|
-
renderer.render(scene, camera)
|
35
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require_relative './example_helper'
|
2
|
-
|
3
|
-
SCREEN_WIDTH = 800
|
4
|
-
SCREEN_HEIGHT = 600
|
5
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
6
|
-
|
7
|
-
scene = Mittsu::Scene.new
|
8
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
9
|
-
|
10
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '11 Keyboard Input Example'
|
11
|
-
|
12
|
-
geometry = Mittsu::BoxGeometry.new(1.0, 1.0, 1.0)
|
13
|
-
material = Mittsu::MeshBasicMaterial.new(color: 0x00ff00)
|
14
|
-
cube = Mittsu::Mesh.new(geometry, material)
|
15
|
-
scene.add(cube)
|
16
|
-
|
17
|
-
camera.position.z = 5.0
|
18
|
-
|
19
|
-
renderer.window.on_resize do |width, height|
|
20
|
-
renderer.set_viewport(0, 0, width, height)
|
21
|
-
camera.aspect = width.to_f / height.to_f
|
22
|
-
camera.update_projection_matrix
|
23
|
-
end
|
24
|
-
|
25
|
-
renderer.window.on_key_typed do |key|
|
26
|
-
case key
|
27
|
-
when GLFW_KEY_UP
|
28
|
-
cube.position.y += 0.5
|
29
|
-
when GLFW_KEY_DOWN
|
30
|
-
cube.position.y -= 0.5
|
31
|
-
when GLFW_KEY_LEFT
|
32
|
-
cube.position.x -= 0.5
|
33
|
-
when GLFW_KEY_RIGHT
|
34
|
-
cube.position.x += 0.5
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
renderer.window.run do
|
39
|
-
cube.rotation.x += 0.1
|
40
|
-
cube.rotation.y += 0.1
|
41
|
-
|
42
|
-
renderer.render(scene, camera)
|
43
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require_relative './example_helper'
|
2
|
-
|
3
|
-
SCREEN_WIDTH = 800
|
4
|
-
SCREEN_HEIGHT = 600
|
5
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
6
|
-
|
7
|
-
scene = Mittsu::Scene.new
|
8
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
9
|
-
|
10
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '12 Mouse Click Example'
|
11
|
-
|
12
|
-
camera.position.z = 5.0
|
13
|
-
|
14
|
-
cubes = []
|
15
|
-
renderer.window.on_mouse_button_pressed do |button, position|
|
16
|
-
geometry = Mittsu::BoxGeometry.new(1.0, 1.0, 1.0)
|
17
|
-
material = Mittsu::MeshBasicMaterial.new(color: 0x00ff00)
|
18
|
-
cube = Mittsu::Mesh.new(geometry, material)
|
19
|
-
cube.position.x = ((position.x/SCREEN_WIDTH)*2.0-1.0) * 5.0
|
20
|
-
cube.position.y = ((position.y/SCREEN_HEIGHT)*-2.0+1.0) * 5.0
|
21
|
-
scene.add(cube)
|
22
|
-
cubes << cube
|
23
|
-
end
|
24
|
-
|
25
|
-
renderer.window.on_resize do |width, height|
|
26
|
-
renderer.set_viewport(0, 0, width, height)
|
27
|
-
camera.aspect = width.to_f / height.to_f
|
28
|
-
camera.update_projection_matrix
|
29
|
-
end
|
30
|
-
|
31
|
-
renderer.window.run do
|
32
|
-
cubes.each do |cube|
|
33
|
-
cube.rotation.x += 0.1
|
34
|
-
cube.rotation.y += 0.1
|
35
|
-
end
|
36
|
-
|
37
|
-
renderer.render(scene, camera)
|
38
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require_relative './example_helper'
|
2
|
-
|
3
|
-
SCREEN_WIDTH = 800
|
4
|
-
SCREEN_HEIGHT = 600
|
5
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
6
|
-
|
7
|
-
scene = Mittsu::Scene.new
|
8
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
9
|
-
|
10
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '12 Mouse Motion Example'
|
11
|
-
|
12
|
-
geometry = Mittsu::BoxGeometry.new(1.0, 1.0, 1.0)
|
13
|
-
material = Mittsu::MeshBasicMaterial.new(color: 0x00ff00)
|
14
|
-
cube = Mittsu::Mesh.new(geometry, material)
|
15
|
-
scene.add(cube)
|
16
|
-
|
17
|
-
camera.position.z = 5.0
|
18
|
-
|
19
|
-
renderer.window.on_mouse_move do |position|
|
20
|
-
cube.position.x = ((position.x/SCREEN_WIDTH)*2.0-1.0) * 5.0
|
21
|
-
cube.position.y = ((position.y/SCREEN_HEIGHT)*-2.0+1.0) * 5.0
|
22
|
-
end
|
23
|
-
|
24
|
-
renderer.window.on_resize do |width, height|
|
25
|
-
renderer.set_viewport(0, 0, width, height)
|
26
|
-
camera.aspect = width.to_f / height.to_f
|
27
|
-
camera.update_projection_matrix
|
28
|
-
end
|
29
|
-
|
30
|
-
renderer.window.run do
|
31
|
-
cube.rotation.x += 0.1
|
32
|
-
cube.rotation.y += 0.1
|
33
|
-
|
34
|
-
renderer.render(scene, camera)
|
35
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require_relative './example_helper'
|
2
|
-
|
3
|
-
SCREEN_WIDTH = 800
|
4
|
-
SCREEN_HEIGHT = 600
|
5
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
6
|
-
|
7
|
-
scene = Mittsu::Scene.new
|
8
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
9
|
-
|
10
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '12 Mouse Scroll Example'
|
11
|
-
|
12
|
-
geometry = Mittsu::BoxGeometry.new(1.0, 1.0, 1.0)
|
13
|
-
material = Mittsu::MeshBasicMaterial.new(color: 0x00ff00)
|
14
|
-
cube = Mittsu::Mesh.new(geometry, material)
|
15
|
-
scene.add(cube)
|
16
|
-
|
17
|
-
camera.position.z = 5.0
|
18
|
-
|
19
|
-
renderer.window.on_scroll do |offset|
|
20
|
-
scroll_factor = (1.5 ** (offset.y * 0.1))
|
21
|
-
camera.zoom *= scroll_factor
|
22
|
-
camera.update_projection_matrix
|
23
|
-
end
|
24
|
-
|
25
|
-
renderer.window.on_resize do |width, height|
|
26
|
-
renderer.set_viewport(0, 0, width, height)
|
27
|
-
camera.aspect = width.to_f / height.to_f
|
28
|
-
camera.update_projection_matrix
|
29
|
-
end
|
30
|
-
|
31
|
-
renderer.window.run do
|
32
|
-
cube.rotation.x += 0.1
|
33
|
-
cube.rotation.y += 0.1
|
34
|
-
|
35
|
-
renderer.render(scene, camera)
|
36
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require_relative './example_helper'
|
2
|
-
|
3
|
-
SCREEN_WIDTH = 800
|
4
|
-
SCREEN_HEIGHT = 600
|
5
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
6
|
-
|
7
|
-
scene = Mittsu::Scene.new
|
8
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
9
|
-
|
10
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '12 Orbit/Zoom Example'
|
11
|
-
|
12
|
-
axis_object = Mittsu::Object3D.new
|
13
|
-
axis_object.add(Mittsu::Mesh.new(
|
14
|
-
Mittsu::BoxGeometry.new(1.0, 1.0, 1.0),
|
15
|
-
Mittsu::MeshBasicMaterial.new(color: 0xffffff)))
|
16
|
-
axis_object.add(Mittsu::Mesh.new(
|
17
|
-
Mittsu::BoxGeometry.new(10.0, 0.1, 0.1),
|
18
|
-
Mittsu::MeshBasicMaterial.new(color: 0xff0000)))
|
19
|
-
axis_object.add(Mittsu::Mesh.new(
|
20
|
-
Mittsu::BoxGeometry.new(0.1, 10.0, 0.1),
|
21
|
-
Mittsu::MeshBasicMaterial.new(color: 0x00ff00)))
|
22
|
-
axis_object.add(Mittsu::Mesh.new(
|
23
|
-
Mittsu::BoxGeometry.new(0.1, 0.1, 10.0),
|
24
|
-
Mittsu::MeshBasicMaterial.new(color: 0x0000ff)))
|
25
|
-
scene.add(axis_object)
|
26
|
-
|
27
|
-
camera_container = Mittsu::Object3D.new
|
28
|
-
camera_container.add(camera)
|
29
|
-
camera.position.z = 5.0
|
30
|
-
scene.add(camera_container)
|
31
|
-
|
32
|
-
renderer.window.on_scroll do |offset|
|
33
|
-
scroll_factor = (1.5 ** (offset.y * 0.1))
|
34
|
-
camera.zoom *= scroll_factor
|
35
|
-
camera.update_projection_matrix
|
36
|
-
end
|
37
|
-
|
38
|
-
X_AXIS = Mittsu::Vector3.new(1.0, 0.0, 0.0)
|
39
|
-
Y_AXIS = Mittsu::Vector3.new(0.0, 1.0, 0.0)
|
40
|
-
|
41
|
-
mouse_delta = Mittsu::Vector2.new
|
42
|
-
last_mouse_position = Mittsu::Vector2.new
|
43
|
-
|
44
|
-
renderer.window.on_mouse_button_pressed do |button, position|
|
45
|
-
if button == GLFW_MOUSE_BUTTON_LEFT
|
46
|
-
last_mouse_position.copy(position)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
renderer.window.on_mouse_move do |position|
|
51
|
-
if renderer.window.mouse_button_down?(GLFW_MOUSE_BUTTON_LEFT)
|
52
|
-
mouse_delta.copy(last_mouse_position).sub(position)
|
53
|
-
last_mouse_position.copy(position)
|
54
|
-
|
55
|
-
camera_container.rotate_on_axis(Y_AXIS, mouse_delta.x * 0.01)
|
56
|
-
camera_container.rotate_on_axis(X_AXIS, mouse_delta.y * 0.01)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
renderer.window.on_resize do |width, height|
|
61
|
-
renderer.set_viewport(0, 0, width, height)
|
62
|
-
camera.aspect = width.to_f / height.to_f
|
63
|
-
camera.update_projection_matrix
|
64
|
-
end
|
65
|
-
|
66
|
-
renderer.window.run do
|
67
|
-
renderer.render(scene, camera)
|
68
|
-
end
|