C++ GLUT通过单击、拖动和平移缩放到光标

C++ GLUT通过单击、拖动和平移缩放到光标,c++,opengl,2d,C++,Opengl,2d,我正试图使这个功能像谷歌地图或 如何使用鼠标位置如缩放中心 如何通过移动光标拖动图像?要使用按钮==0&&state==GLUT\u DOWN执行此操作 非常感谢您的帮助 #include <stdlib.h> #include <string.h> #include <stdio.h> #include <math.h> #include "glut.h" #define windowSize 900.0 double zoomFactor =

我正试图使这个功能像谷歌地图或

如何使用鼠标位置如缩放中心

如何通过移动光标拖动图像?要使用按钮==0&&state==GLUT\u DOWN执行此操作

非常感谢您的帮助

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "glut.h"

#define windowSize 900.0
double zoomFactor = 1;
int mouseX=0, mouseY=0;
void reshape (int w, int h)
{
}
void mouse(int button, int state, int x, int y) {
if (button == 0)
{
   if (state == GLUT_UP) return;
   zoomFactor -= 0.05; 
}
else if (button == 2) {
    if (state == GLUT_UP) return;
    zoomFactor += 0.05;
}
else return;
glutPostRedisplay();
}
void motion(int ax, int ay) {
mouseX = ax;
mouseY = ay;
}

Void display(){
glClear(GL_COLOR_BUFFER_BIT);
glViewport (0.0, 0.0, glutGet(GLUT_INIT_WINDOW_WIDTH), glutGet(GLUT_INIT_WINDOW_HEIGHT));
 glMatrixMode (GL_PROJECTION);
 glLoadIdentity ();
 gluOrtho2D (-glutGet(GLUT_INIT_WINDOW_WIDTH)*zoomFactor, glutGet(GLUT_INIT_WINDOW_WIDTH)*zoomFactor,\
 -glutGet(GLUT_INIT_WINDOW_HEIGHT)*zoomFactor, glutGet(GLUT_INIT_WINDOW_HEIGHT)*zoomFactor);

glBegin(GL_LINES); 
glVertex2f ((0),(0)); 
glVertex2f ((100),(0));
 glEnd();
glBegin(GL_LINES); 
glVertex2f ((100),(0)); 
glVertex2f ((100),(100));
 glEnd();
glFlush();
}

int main(int argc,char** argv) {
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(windowSize, windowSize);
glutInitWindowPosition(500,0);
glutCreateWindow("test");
glClearColor(0, 0.1,0.8,0.90);    
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 200, 200,0);   
glutDisplayFunc( display );
glutPassiveMotionFunc(motion);    
glutMouseFunc(mouse);
glutMainLoop(;   
return(0);
}
#包括
#包括
#包括
#包括
#包括“glut.h”
#定义WindowsSize 900.0
双变焦因子=1;
int mouseX=0,mouseY=0;
空洞重塑(整数w,整数h)
{
}
无效鼠标(int按钮、int状态、int x、int y){
如果(按钮==0)
{
if(state==GLUT_UP)返回;
动物因子-=0.05;
}
否则如果(按钮==2){
if(state==GLUT_UP)返回;
动物因子+=0.05;
}
否则返回;
再发现();
}
无效运动(int ax,int ay){
mouseX=ax;
mouseY=ay;
}
无效显示(){
glClear(GLU颜色缓冲位);
glViewport(0.0,0.0,glutGet(GLUT_初始_窗口宽度),glutGet(GLUT_初始_窗口高度));
glMatrixMode(GL_投影);
glLoadIdentity();
gluOrtho2D(-glutGet(GLUT初始窗口宽度)*缩放因子,glutGet(GLUT初始窗口宽度)*缩放因子\
-glutGet(GLUT_初始_窗口高度)*缩放因子,glutGet(GLUT_初始_窗口高度)*缩放因子;
glBegin(GL_行);
glVertex2f((0),(0));
glVertex2f((100),(0));
格伦德();
glBegin(GL_行);
glVertex2f((100),(0));
glVertex2f((100),(100));
格伦德();
glFlush();
}
int main(int argc,字符**argv){
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
GLUTINITWindowsSize(WindowsSize,WindowsSize);
位置(500,0);
测试窗口(“测试”);
glClearColor(0,0.1,0.8,0.90);
glMatrixMode(GL_投影);
glLoadIdentity();
gluOrtho2D(0,200200,0);
glutDisplayFunc(显示器);
情绪功能(运动);
glutMouseFunc(小鼠);
glutMainLoop(;
返回(0);
}