Zoom per Mausrad? OpenGL



  • Hallo zusammen!

    Ich suche nach einer Möglichkeit, die Objekte die ich bis jetzt habe, per Mausrad zu zoomen. (Mit Tasten wäre es mir möglich)
    Aber finde keine Funktion in GL.h, GLU.h und in der GLUT.h wo man auf das Mausrad zugreifen kann.

    Wie kann ich das einfach hinbekommen?
    Hier wär mal mein Code:

    #include <glut.h>
    #include <gl/glu.h>
    #include <gl/gl.h>
    
    //using namespace std;
    
    GLfloat diffuseLight[] = {0.5f, 0.5f, 0.5f, 1.0f};
    GLfloat LightPos[] = {50.0f, 50.0f, 20.0f, 1.0f};
    GLfloat xRot = 0.0f;
    GLfloat yRot = 0.0f;
    GLfloat zoom = -100.0f;
    
    void RenderScene(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    	glPushMatrix();
    	glColor3f(1.0f, 1.0f, 1.0f);
    	glTranslatef(0.0f, 0.0f, zoom);
    	glRotatef(xRot, 1.0f, 0.0f, 0.0f);
    	glRotatef(yRot, 0.0f, 1.0f, 0.0f);
    	//glutSolidSphere(25, 50, 50);
    	glutWireSphere(25, 50, 50);
    	glPopMatrix();
    
    	glutSwapBuffers();
    
    }
    
    void SetupRC(void)
    {
    	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    
    	glShadeModel(GL_SMOOTH);
    	glEnable(GL_DEPTH_TEST);
    	//glEnable(GL_LIGHTING);
    
    	glEnable(GL_LIGHT0);
    	glLightfv(GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE, diffuseLight);
    	glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
    	glEnable(GL_LIGHTING);
    
    	glEnable(GL_CULL_FACE);
    	glFrontFace(GL_CCW);	
    	glCullFace(GL_BACK);
    
    	glEnable(GL_COLOR_MATERIAL);
    }
    
    void ChangeSize(int w, int h)
    {
    	if (h == 0)
    		h = 1;
    
    	// Set up the projection matrix
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glViewport(0, 0, w, h);
    	gluPerspective(55.0, (double)w / h, 1.0, 1000.0);
    
    	// Set up the modelview matrix
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    
    }
    
    void OnSpecialKey(int key, int x, int y)
    {
    	switch(key)
    	{
    		case GLUT_KEY_UP:
    			xRot += 5.0f;
    			break;
    
    		case GLUT_KEY_DOWN:
    			xRot -= 5.0f;
    			break;
    
    		case GLUT_KEY_LEFT:
    			yRot -= 5.0f;
    			break;
    
    		case GLUT_KEY_RIGHT:
    			yRot += 5.0f;
    			break;
    
    		default:
    			break;
    	}
    
    	RenderScene();
    }
    
    void main(int argc, char** argv)
    {
    	// Initialize Glut
    	glutInit(&argc, argv);
    
    	// Initialize a Glut window
    	//glutInitWindowPosition(50, 50);
    	glutInitWindowSize(800, 600);
    	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    	glutCreateWindow("OpenGl Haupt");
    
    	// Setup the Glut callback functions
    	//glutIdleFunc(OnIdle);
    	glutReshapeFunc(ChangeSize);
    	glutDisplayFunc(RenderScene);
    	//glutKeyboardFunc(OnKey);
    	glutSpecialFunc(OnSpecialKey);
    	//glutMouseFunc(OnMouse);
    	//glutMotionFunc(OnActiveMouse);
    	//glutPassiveMotionFunc(OnPassiveMouse);
    
    	// Hide the mouse cursor
    	//glutSetCursor(GLUT_CURSOR_NONE);
    
    	// Be sure to call DestroyScene when we exit
    	//atexit(DestroyScene);
    
    	// Initialize the scene specific details (ie: load models, textures, etc...)
    	SetupRC();
    
    	//glutWarpPointer(200, 200);
    	//gltInitFrame(&g_CameraFrame);
    	//glutIgnoreKeyRepeat(0);
    
    	// Let's begin
    	glutMainLoop();
    
    }
    

    Is noch nix besonderes, aber ich versuche eine "Haupt"-Datei hinzukriegen, wo alles drin ist was ich so brauche um nicht immer alles neu zu schreiben.

    LG WedlWedl



  • Schau mal hier.



  • Gehe ich richtig in der Annahme, dass mit (OpenGL) SPACEBALL das Mausrad gemeint ist?
    Sorry für so eine Noob-Frage. 🙄

    Noch ne Frage: Wie war das bei Euch, habt ihr Euch am Anfang "alle" *.h-dateien angeguckt, oder einfach drauflosgetippt und geschaut was bei raus kommt?

    LG WedlWedl


Anmelden zum Antworten