opengl-cube 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/opengl-cube.rb +22 -10
- data/test/test_opengl-cube.rb +8 -4
- metadata +1 -1
data/lib/opengl-cube.rb
CHANGED
@@ -6,13 +6,15 @@ class OpenGLCube
|
|
6
6
|
include Glut
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
|
9
|
+
@mouse_left_button_down = false
|
10
|
+
@mouse_right_button_down = false
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
@mouse_pos_x = 0
|
13
|
+
@mouse_pos_y = 0
|
13
14
|
|
14
15
|
@cube_angle_x = 0
|
15
16
|
@cube_angle_y = 0
|
17
|
+
@cube_angle_z = 0
|
16
18
|
|
17
19
|
# Initliaze our GLUT code
|
18
20
|
glutInit
|
@@ -80,6 +82,7 @@ class OpenGLCube
|
|
80
82
|
# Rotate the cube on the X, Y and Z axis
|
81
83
|
glRotatef @cube_angle_y, 0.0, 1.0, 0.0
|
82
84
|
glRotatef @cube_angle_x, 1.0, 0.0, 0.0
|
85
|
+
glRotatef @cube_angle_z, 0.0, 0.0, 1.0
|
83
86
|
|
84
87
|
# Set it to a blue color one time only
|
85
88
|
glBegin GL_QUADS do
|
@@ -161,25 +164,34 @@ class OpenGLCube
|
|
161
164
|
@cube_angle_y = @mouse_pos_y - y
|
162
165
|
@mouse_pos_x = x
|
163
166
|
@mouse_pos_y = y
|
167
|
+
@mouse_left_button_down = false
|
164
168
|
end
|
165
169
|
when GLUT_RIGHT_BUTTON
|
166
170
|
case state
|
167
|
-
when GLUT_DOWN
|
168
|
-
|
171
|
+
when GLUT_DOWN
|
172
|
+
@mouse_pos_x = x
|
173
|
+
@mouse_pos_y = y
|
174
|
+
@mouse_right_button_down = true
|
175
|
+
when GLUT_UP
|
176
|
+
@cube_angle_z = @mouse_pos_x - x
|
177
|
+
@mouse_right_button_down = false
|
169
178
|
end
|
170
179
|
end
|
171
180
|
glutPostRedisplay
|
172
181
|
end
|
173
182
|
|
174
183
|
def motion x, y
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
184
|
+
if @mouse_left_button_down
|
185
|
+
@cube_angle_y = @mouse_pos_x - x
|
186
|
+
@cube_angle_x = @mouse_pos_y - y
|
187
|
+
elsif @mouse_right_button_down
|
188
|
+
@cube_angle_z = @mouse_pos_x - x
|
189
|
+
end
|
179
190
|
end
|
180
191
|
|
181
192
|
def passive_motion x, y
|
182
193
|
end
|
183
194
|
end
|
184
195
|
|
185
|
-
OpenGLCube.new if $0 == __FILE__
|
196
|
+
OpenGLCube.new if $0 == __FILE__
|
197
|
+
|
data/test/test_opengl-cube.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'rubygems'
|
2
|
+
require 'opengl/test_case'
|
3
|
+
require 'gl'
|
4
|
+
require 'glut'
|
5
|
+
include Gl
|
6
|
+
include Glut
|
3
7
|
|
4
|
-
class OpenGLCubeTest <
|
8
|
+
class OpenGLCubeTest < OpenGL::TestCase
|
5
9
|
def setup
|
6
10
|
end
|
7
11
|
|
8
12
|
def teardown
|
9
13
|
end
|
10
|
-
end
|
14
|
+
end
|