【发布时间】:2012-02-07 20:29:59
【问题描述】:
我正在使用 OpenGL 绑定在 Perl 中编写一个程序,当通过读取 GLUT_WINDOW_HEIGHT 和 GLUT_WINDOW_WIDTH 变量调用 glutReshapeFunc(\&changeSize); 时,我已经克服了第一个障碍,但我不知道如何获取调用glutSpecialFunc(\&processSpecialKeys); 时传递的键的值。
阅读 API 我找不到 GLUT_SPECIAL_KEY 变量或类似的东西。
sub changeSize
{
my $w = glutGet(GLUT_WINDOW_WIDTH);
my $h = glutGet(GLUT_WINDOW_HEIGHT);
if($w eq 0){
$w = 1;
}
my $ratio = ($w / $h);
# Use the Projection Matrix
glMatrixMode(GL_PROJECTION);
#// Reset Matrix
glLoadIdentity();
#// Set the viewport to be the entire window
glViewport(0, 0, $w, $h);
#// Set the correct perspective.
gluPerspective(45,$ratio,1,1000);
#// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
gluLookAt( $x, 1.0, $z,
$x+$lx,1.0,$z+$lz,
0.0,1.0,0.0);
}
sub processSpecialKeys
{
$fraction = 0.1;
$key = $_[0]; #my first shot was that the key value was stored at $_[0]
#the mouse_x was at $_[1] and $_[2] had mouse_y
if ($key eq GLUT_KEY_LEFT)
{
$angle -= 0.01;
$lx = sin($angle);
$lz = -cos($angle);
}
}
【问题讨论】: