【发布时间】:2023-04-02 07:09:01
【问题描述】:
我厌倦了在 VC++ 中使用 glutMouseWheelFunc 实现简单的放大/缩小。我能够实现放大/缩小,但这样做时,轴(GLlines)在缩放超过一定水平后往往会消失。
我正在使用glutMouseWheelFunc 来增加/减少glTranslatef 中的z 轴值。
我已将glTranslatef 的“z”定义为相机距离:
float cDist= 30.0f; // camera distance
然后在glTranslatef中作为,
glTranslatef(0.0f, 0.0f, -cDist);
在下面的显示功能中。
void display(void) {
glClearColor(0.0, 0.0, 0.0, 1.0); //clear the screen to black
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//clear the color buffer and the depth buffer
enable();
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -cDist);
glRotatef(xrot, 1.0, 0.0, 0.0);
---------------
glBegin(GL_LINES);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-500, 0, 0);
glVertex3f(500, 0, 0);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0, -500, 0);
glVertex3f(0, 500, 0);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0, 0, -500);
glVertex3f(0, 0, 500);
glTranslated(-xpos, 0.0f, -zpos); //translate the screento the position of our camera
glColor3f(1.0f, 1.0f, 1.0f);
glutSwapBuffers();
}
之后,我将wheelfunc定义为,
void mouseWheel(int button, int dir, int x, int y)
{
if (dir > 0)
{
cDist = cDist++;
}
else
{
cDist= cDist--;
}
return;
}
并用glutMouseWheelFunc(mouseWheel);在主函数中调用它
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("Window");
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
glutMotionFunc(mouseMovement);
glutMouseWheelFunc(mouseWheel);---- here
-----
---
glutMainLoop();
return 0;
}
这种放大方法合适吗?如果没有,还有什么替代方法?另外,如何将轴(我绘制的线)定义为屏幕的全部范围?
【问题讨论】:
-
你的近端和远端是什么?
标签: c++ opengl visual-c++ glut freeglut