-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnlt_3dlabor.rb
98 lines (93 loc) · 2.14 KB
/
nlt_3dlabor.rb
1
2
3
4
5
6
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding: utf-8 -*-
f = File.open(ARGV[0], mode="rb")
points = []
while not f.eof
# Die Daten weisen auf int16 als Datentyp hin.
z = f.read(2).unpack("s")[0]
break if z == nil
fixpt = z / (2**15).to_f
points.push(fixpt)
end
points.shift
puts "added #{points.size} points"
f.close
require 'opengl'
require 'glu'
require 'glut'
$preshift = 0
$postshift = 0
$inshift = 0
$intershift = 0
$corners = 3
$variant = GL::POINTS
display = Proc.new {
p = points.clone
$preshift.times do p.shift end
$postshift.times do p.pop; end
GL.ClearColor(0.0, 0.0, 0.0, 1.0)
GL.Clear(GL::COLOR_BUFFER_BIT)
GL.Begin($variant)
i = 0
while p.size > 0
GL.Color3f(1.0, p.size/points.size.to_f, 0.0)
x = p.shift
y = p.shift
z = 0#p.shift
break if z==nil
GL.Vertex3f(x, y, z)
$inshift.times do p.shift end
i+= 1
if (i % $corners == 0)
GL.End
$intershift.times do p.shift end
GL.Begin($variant)
end
end
GL.End
GLUT.SwapBuffers
}
reshape = Proc.new{|width, height|
GL.Viewport(0, 0, width, height)
GL.MatrixMode(GL::PROJECTION)
GL.LoadIdentity
GLU.Perspective(90.0, 4/3.0, -2, 0)
GL.MatrixMode(GL::MODELVIEW)
GL.LoadIdentity
GLU.LookAt(0, 0, -1.5, 0, 0, 0, 0, -1, 0)
$width = width
$height= height
}
motion = Proc.new{|x,y|
GL.MatrixMode(GL::MODELVIEW)
GL.LoadIdentity
GLU.LookAt((2.0*x)/$width-1.0, (2.0*y)/$height-1.0, -1.5,
0, 0, 0,
0, -1, 0)
GLUT.PostRedisplay
}
keyboard = Proc.new{|c|
case (c)
when 'q' then exit
when 'y' then $corners -= 1
when 'u' then $corners += 1
when ',' then $preshift -= 1
when 'o' then $preshift += 1
when '.' then $inshift -= 1
when 'e' then $inshift += 1
when 'p' then $intershift -= 1
when 'i' then $intershift += 1
when 'd' then puts "c=#{$corners}, pre=#{$preshift}, in=#{$inshift}, inter=#{$intershift}"
end
GLUT.PostRedisplay
}
GLUT.Init
GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGB)
GLUT.InitWindowSize(320, 240)
GLUT.CreateWindow("glut")
GLUT.DisplayFunc(display)
GLUT.KeyboardFunc(keyboard)
GLUT.MotionFunc(motion)
GLUT.ReshapeFunc(reshape)
GL.PointSize(3)
GL.Enable(GL::BLEND)
GLUT.MainLoop