disp3D 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +73 -1
- data/VERSION +1 -1
- data/disp3D.gemspec +97 -0
- data/example/stl_viewer/app_model.rb +8 -0
- data/example/stl_viewer/document.rb +15 -0
- data/example/stl_viewer/document_ctrl.rb +62 -0
- data/example/stl_viewer/gl_ctrl.rb +15 -0
- data/example/stl_viewer/main.rb +120 -0
- data/example/stl_viewer/mesh_info.rb +12 -0
- data/example/stl_viewer/stl_viewer.rb +9 -0
- data/lib/camera.rb +49 -35
- data/lib/disp3D.rb +19 -3
- data/lib/dsl.rb +18 -0
- data/lib/gl_view.rb +80 -0
- data/lib/glut_window.rb +60 -0
- data/lib/light.rb +49 -0
- data/lib/manipulator.rb +92 -21
- data/lib/node.rb +15 -9
- data/lib/node_arrows.rb +68 -0
- data/lib/node_collection.rb +14 -3
- data/lib/node_leaf.rb +80 -0
- data/lib/node_lines.rb +4 -7
- data/lib/node_points.rb +9 -11
- data/lib/node_polylines.rb +34 -0
- data/lib/node_tea_pod.rb +9 -2
- data/lib/node_text.rb +17 -0
- data/lib/node_tris.rb +24 -0
- data/lib/picked_result.rb +15 -0
- data/lib/picker.rb +56 -0
- data/lib/qt_widget_gl.rb +80 -0
- data/lib/scene_graph.rb +5 -0
- data/lib/stl.rb +92 -0
- data/lib/util.rb +18 -0
- data/test/test_data/binary_test.stl +0 -0
- data/test/test_data/cube-ascii.stl +86 -0
- data/test/test_dsl.rb +8 -0
- data/test/test_glut_window.rb +113 -0
- data/test/test_qtgl.rb +26 -0
- data/test/test_stl.rb +12 -0
- data/test/test_tea_pod.rb +13 -2
- metadata +41 -19
- data/lib/helloworld.rb +0 -112
- data/lib/view.rb +0 -47
- data/test/test_line.rb +0 -8
- data/test/test_lines.rb +0 -17
- data/test/test_point.rb +0 -25
- data/test/test_points.rb +0 -27
data/lib/helloworld.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "opengl"
|
3
|
-
require "glut"
|
4
|
-
|
5
|
-
class Teapot
|
6
|
-
LIGHT_POSITION = [0.25, 1.0, 0.25, 0.0]
|
7
|
-
LIGHT_DIFFUSE = [1.0, 1.0, 1.0]
|
8
|
-
LIGHT_AMBIENT = [0.25, 0.25, 0.25]
|
9
|
-
LIGHT_SPECULAR = [1.0, 1.0, 1.0]
|
10
|
-
|
11
|
-
MAT_DIFFUSE = [1.0, 0.0, 0.0]
|
12
|
-
MAT_AMBIENT = [0.25, 0.25, 0.25]
|
13
|
-
MAT_SPECULAR = [1.0, 1.0, 1.0]
|
14
|
-
MAT_SHININESS = [32.0]
|
15
|
-
|
16
|
-
def reshape(w,h)
|
17
|
-
GL.Viewport(0,0,w,h)
|
18
|
-
|
19
|
-
GL.MatrixMode(GL::GL_PROJECTION)
|
20
|
-
GL.LoadIdentity()
|
21
|
-
GLU.Perspective(45.0, w.to_f()/h.to_f(), 0.1, 100.0)
|
22
|
-
# GL.Ortho(-1,1,-1,1,2,4)
|
23
|
-
end
|
24
|
-
|
25
|
-
def display()
|
26
|
-
GL.MatrixMode(GL::GL_MODELVIEW)
|
27
|
-
GL.LoadIdentity()
|
28
|
-
GLU.LookAt(0.5, 1.5, 2.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
|
29
|
-
|
30
|
-
GL.Lightfv(GL::GL_LIGHT0, GL::GL_POSITION, LIGHT_POSITION)
|
31
|
-
GL.Lightfv(GL::GL_LIGHT0, GL::GL_DIFFUSE, LIGHT_DIFFUSE)
|
32
|
-
GL.Lightfv(GL::GL_LIGHT0, GL::GL_AMBIENT, LIGHT_AMBIENT)
|
33
|
-
GL.Lightfv(GL::GL_LIGHT0, GL::GL_SPECULAR, LIGHT_SPECULAR)
|
34
|
-
|
35
|
-
GL.Materialfv(GL::GL_FRONT, GL::GL_DIFFUSE, MAT_DIFFUSE)
|
36
|
-
GL.Materialfv(GL::GL_FRONT, GL::GL_AMBIENT, MAT_AMBIENT)
|
37
|
-
GL.Materialfv(GL::GL_FRONT, GL::GL_SPECULAR, MAT_SPECULAR)
|
38
|
-
GL.Materialfv(GL::GL_FRONT, GL::GL_SHININESS, MAT_SHININESS)
|
39
|
-
|
40
|
-
GL.ClearColor(0.0, 0.0, 0.0, 1.0)
|
41
|
-
GL.Clear(GL::GL_COLOR_BUFFER_BIT | GL::GL_DEPTH_BUFFER_BIT)
|
42
|
-
|
43
|
-
GL.Rotate(@rotX, 1, 0, 0)
|
44
|
-
GL.Rotate(@rotY, 0, 1, 0)
|
45
|
-
GLUT.SolidTeapot(0.5)
|
46
|
-
|
47
|
-
GLUT.SwapBuffers()
|
48
|
-
end
|
49
|
-
|
50
|
-
def mouse(button,state,x,y)
|
51
|
-
if button == GLUT::GLUT_LEFT_BUTTON && state == GLUT::GLUT_DOWN then
|
52
|
-
@start_x = x
|
53
|
-
@start_y = y
|
54
|
-
@drag_flg = true
|
55
|
-
elsif state == GLUT::GLUT_UP then
|
56
|
-
@drag_flg = false
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def motion(x,y)
|
61
|
-
if @drag_flg then
|
62
|
-
dx = x - @start_x
|
63
|
-
dy = y - @start_y
|
64
|
-
|
65
|
-
@rotY += dx
|
66
|
-
@rotY = @rotY % 360
|
67
|
-
|
68
|
-
@rotX += dy
|
69
|
-
@rotX = @rotX % 360
|
70
|
-
end
|
71
|
-
@start_x = x
|
72
|
-
@start_y = y
|
73
|
-
GLUT.PostRedisplay()
|
74
|
-
end
|
75
|
-
|
76
|
-
def initialize()
|
77
|
-
@start_x = 0
|
78
|
-
@start_y = 0
|
79
|
-
@rotY = 0
|
80
|
-
@rotX = 0
|
81
|
-
@drag_flg = false
|
82
|
-
GLUT.InitWindowPosition(100, 100)
|
83
|
-
GLUT.InitWindowSize(300,300)
|
84
|
-
GLUT.Init
|
85
|
-
GLUT.InitDisplayMode(GLUT::GLUT_DOUBLE | GLUT::GLUT_RGB | GLUT::GLUT_DEPTH)
|
86
|
-
GLUT.CreateWindow("Ruby de OpenGL")
|
87
|
-
|
88
|
-
GL.Enable(GL::GL_DEPTH_TEST)
|
89
|
-
GL.Enable(GL::GL_LIGHTING)
|
90
|
-
GL.Enable(GL::GL_LIGHT0)
|
91
|
-
|
92
|
-
GL.FrontFace(GL::GL_CW)
|
93
|
-
GL.Enable(GL::GL_AUTO_NORMAL)
|
94
|
-
GL.Enable(GL::GL_NORMALIZE)
|
95
|
-
GL.Enable(GL::GL_DEPTH_TEST)
|
96
|
-
GL.DepthFunc(GL::GL_LESS)
|
97
|
-
|
98
|
-
GL.ShadeModel(GL::SMOOTH)
|
99
|
-
|
100
|
-
GLUT.ReshapeFunc(method(:reshape).to_proc())
|
101
|
-
GLUT.DisplayFunc(method(:display).to_proc())
|
102
|
-
GLUT.MouseFunc(method(:mouse).to_proc())
|
103
|
-
GLUT.MotionFunc(method(:motion).to_proc())
|
104
|
-
end
|
105
|
-
|
106
|
-
def start()
|
107
|
-
GLUT.MainLoop()
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
Teapot.new().start()
|
112
|
-
|
data/lib/view.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'disp3D'
|
2
|
-
|
3
|
-
module Disp3D
|
4
|
-
class View
|
5
|
-
attr_accessor :world_scene_graph
|
6
|
-
attr_accessor :camera
|
7
|
-
|
8
|
-
attr_accessor :bk_color
|
9
|
-
|
10
|
-
def display()
|
11
|
-
GL.ClearColor(@bk_color[0],@bk_color[1],@bk_color[2],@bk_color[3])
|
12
|
-
|
13
|
-
@camera.display() if(@camera)
|
14
|
-
@world_scene_graph.display() if(@world_scene_graph)
|
15
|
-
GLUT.SwapBuffers()
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(x,y,width,height)
|
19
|
-
GLUT.InitWindowPosition(x, y)
|
20
|
-
GLUT.InitWindowSize(width, height)
|
21
|
-
GLUT.Init
|
22
|
-
GLUT.InitDisplayMode(GLUT::GLUT_DOUBLE | GLUT::GLUT_RGB | GLUT::GLUT_DEPTH)
|
23
|
-
GLUT.CreateWindow("Disp3D view test")
|
24
|
-
|
25
|
-
GL.Enable(GL::GL_DEPTH_TEST)
|
26
|
-
|
27
|
-
GL.FrontFace(GL::GL_CW)
|
28
|
-
GL.Enable(GL::GL_AUTO_NORMAL)
|
29
|
-
GL.Enable(GL::GL_NORMALIZE)
|
30
|
-
GL.Enable(GL::GL_DEPTH_TEST)
|
31
|
-
GL.DepthFunc(GL::GL_LESS)
|
32
|
-
GL.ShadeModel(GL::SMOOTH)
|
33
|
-
|
34
|
-
GLUT.DisplayFunc(method(:display).to_proc())
|
35
|
-
|
36
|
-
@camera = Camera.new()
|
37
|
-
@manipulator = Manipulator.new(@camera)
|
38
|
-
@world_scene_graph = SceneGraph.new()
|
39
|
-
|
40
|
-
@bk_color = [0.5,0.5,0.5,0]
|
41
|
-
end
|
42
|
-
|
43
|
-
def start
|
44
|
-
GLUT.MainLoop()
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/test/test_line.rb
DELETED
data/test/test_lines.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
include GMath3D
|
5
|
-
|
6
|
-
main_view = Disp3D::View.new(100,100,200,200)
|
7
|
-
|
8
|
-
nodes = []
|
9
|
-
|
10
|
-
geoms = [FiniteLine.new(),
|
11
|
-
FiniteLine.new(Vector3.new(), Vector3.new(Math::sqrt(2)/2, Math::sqrt(2)/2, 0)),
|
12
|
-
FiniteLine.new(Vector3.new(), Vector3.new(0,1,0))]
|
13
|
-
nodes.push( Disp3D::NodeLines.new(geoms) )
|
14
|
-
|
15
|
-
main_view.world_scene_graph.add(nodes)
|
16
|
-
|
17
|
-
main_view.start
|
data/test/test_point.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
main_view = Disp3D::View.new(100,100,200,200)
|
5
|
-
|
6
|
-
geom1 = GMath3D::Vector3.new(-1,0,0)
|
7
|
-
node1 = Disp3D::NodePoints.new(geom1)
|
8
|
-
node1.color = [1,1,1]
|
9
|
-
main_view.world_scene_graph.add(node1)
|
10
|
-
|
11
|
-
geom2 = GMath3D::Vector3.new(0,0,0)
|
12
|
-
node2 = Disp3D::NodePoints.new(geom2)
|
13
|
-
node2.color = [0,1,1]
|
14
|
-
node2.size = 6
|
15
|
-
main_view.world_scene_graph.add(node2)
|
16
|
-
|
17
|
-
geom3 = GMath3D::Vector3.new(1,0,0)
|
18
|
-
node3 = Disp3D::NodePoints.new(geom3)
|
19
|
-
node3.color = [1,0,0]
|
20
|
-
node3.size = 9
|
21
|
-
main_view.world_scene_graph.add(node3)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
main_view.start
|
data/test/test_points.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
main_view = Disp3D::View.new(100,100,200,200)
|
5
|
-
|
6
|
-
nodes = []
|
7
|
-
|
8
|
-
geom1 = [GMath3D::Vector3.new(-1,0,0),
|
9
|
-
GMath3D::Vector3.new( 0,0,0),
|
10
|
-
GMath3D::Vector3.new( 1,0,0)]
|
11
|
-
nodes.push( Disp3D::NodePoints.new(geom1) )
|
12
|
-
|
13
|
-
geom2 = GMath3D::Vector3.new(1,0,0)
|
14
|
-
node1 = Disp3D::NodePoints.new(geom2)
|
15
|
-
node2 = Disp3D::NodePoints.new(geom2)
|
16
|
-
node3 = Disp3D::NodePoints.new(geom2)
|
17
|
-
|
18
|
-
node1.translate = [ 0,0.5,0]
|
19
|
-
node2.translate = [-1,0.5,0]
|
20
|
-
node3.translate = [-2,0.5,0]
|
21
|
-
nodes.push( node1 )
|
22
|
-
nodes.push( node2 )
|
23
|
-
nodes.push( node3 )
|
24
|
-
|
25
|
-
main_view.world_scene_graph.add(nodes)
|
26
|
-
|
27
|
-
main_view.start
|