Verwirrung mit gluPerspective und gluLookAt

blacksh33p

Grünschnabel
Hallo,

Ich sitz hier nun seit 3 Stunden und werd verrückt. Ich versuche für den Anfang nur
eine Quadrat dar zu stellen (wird später mehr, deswegen direkt perspective).
Egal was ich tue, er mal das Rote Quadrat immer bildschirmfüllend. Zur hilfe habe
ich mir eine kleine Steuerung für glulookat gebastelt, jedoch ohne damit weiter zu kommen.
Ich vermute, dass ich irgenwas mit den clippingebenen oder mit den matrizen nich richtig habe. wäre sehr dankbar für jede hilfe.

Code:
#include <iostream>      
#include <math.h>
#include <GL/freeglut.h>
#include "R.h"

int width=1024;
int height = 768;

GLfloat x = 0.0f;
GLfloat y = 0.0f;
GLfloat z = 3.0f;


void Init()	
{
// Hier finden jene Aktionen statt, die zum Programmstart einmalig 
// durchgeführt werden müssen
	 glClearColor ( 1.0f, 1.0f, 1.0f, 1.0f );	// Hintergrundfarbe definieren
	 glEnable(GL_DEPTH_TEST);
	 glClearDepth(1.0);

}

void RenderScene(void)
{
// Hier befindet sich der Code der in jedem frame ausgefuehrt werden muss
   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Puffer loeschen
   glLoadIdentity ();
   glMatrixMode(GL_PROJECTION); // Matrix für Transf. Frustum->viewport
	glLoadIdentity();
	gluPerspective(0.50f,width/height,0.1f,100.0f);
	
	glMatrixMode(GL_MODELVIEW); // Modellierungs/Viewing-Matrix
	glLoadIdentity();
    gluLookAt(x, y, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
	
	
	GLfloat w = 0.5f;

	glBegin(GL_POLYGON);

  
	glColor3f(0.5f,0.0f,0.0f);
	glVertex3f(-w,-w,0.0f);
	glVertex3f(w,-w,0.0f);
	glVertex3f(w,w,0.0f);
	glVertex3f(-w,w,0.0f);


	glEnd();

	

  
  glutSwapBuffers(); 
  glFlush ();
  
   

}

void Reshape(int width,int height)
{
// Hier finden die Reaktionen auf eine Veränderung der Größe des 
// Graphikfensters statt
	glViewport(0,0,width,height);

}

void Animate (int value ) {
   // Hier werden Berechnungen durchgeführt, die zu einer Animation der Szene 
   // erforderlich sind; läuft im Hintergrund und wird alle 10 msec aufgerufen. 
	/*
   static float richtung =1.0, virthoehe;
   virthoehe = virthoehe + 0.005*richtung; 
   if ( virthoehe >= -extent &&  virthoehe <= extent) hoehe = virthoehe;
   if ( virthoehe <= -0.5*extent)	richtung = +1.0;
   if ( virthoehe >=  1.0*extent)  hoehe = extent;
   if ( virthoehe >=  1.5*extent)	richtung = -1.0;

   glutPostRedisplay(); */





   glutTimerFunc(10,Animate,++value);           
}
void KeyPress(unsigned char key, int a, int b)
{

	if(key=='e')
		exit(0);
		
	
}

void KeyPressSpecial(int key, int a, int b)
{
	if(key == GLUT_KEY_UP)
	{
		std::cout<<"Z from:"<<z<<" to ";
		z -=0.5f;
		std::cout<<z<<std::endl;
	}
	if(key == GLUT_KEY_DOWN)
	{
		std::cout<<"Z from:"<<z<<" to ";
		z +=0.5f;
		std::cout<<z<<std::endl;
	}


	if(key == GLUT_KEY_LEFT)
	{
		std::cout<<"X from:"<<x<<" to ";
		x -=0.5f;
		std::cout<<x<<std::endl;
	}
	if(key == GLUT_KEY_RIGHT)
	{
		std::cout<<"X from:"<<x<<" to ";
		x +=0.5f;
		std::cout<<x<<std::endl;
	}

	if(key == GLUT_KEY_PAGE_DOWN)
	{
		std::cout<<"Y from:"<<y<<" to ";
		y -=0.5f;
		std::cout<<y<<std::endl;
	}
	if(key == GLUT_KEY_PAGE_UP)
	{
		std::cout<<"y from:"<<y<<" to ";
		y +=0.5f;
		std::cout<<y<<std::endl;
	}




}


int main(int argc, char **argv)
{
   glutInit ( &argc, argv );
   glutInitDisplayMode ( GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH );
   glutInitWindowSize ( 1024,768 );
   glutCreateWindow ("Olypia Buchstabe R");
   glutDisplayFunc ( RenderScene );
   glutKeyboardFunc(KeyPress);
   glutSpecialFunc(KeyPressSpecial);
   glutReshapeFunc ( Reshape );
   // TimerCallback registrieren; wird nach 10 msec aufgerufen mit Parameter 0  
  // glutTimerFunc(10,Animate,0);
   Init();
   glutMainLoop ();
   return 0;
}
 
Zurück