Zylinder programmieren mit openGL



  • Hallo!
    Bin im moment dabei den Mantel des Zylinders zu programmieren. Mein Problem ist, dass sich die letzten beiden Flächen nicht treffen. Liegt eventuell daran, dass irgendwas mit dem Winkel nicht stimmt. Kann mir aber nicht erklären was da falsch sein sollte.

    Könnt ihr mir sagen woran es liegt?

    Vielen Dank schon mal!

    Grüße!

    void cylinder(){
    	const float radius = 1.0f;
    	float hoehe = 2.0f;
    //	const float PI = 4.0*atan2(1,1);
    
    	// clear buffers
     	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
     	// switch to modelview matrix
     	glMatrixMode(GL_MODELVIEW);
     	glLoadIdentity();
    
     	// viewing transformations
     	glTranslated(-PAN_X,-PAN_Y,-EYE_DISTANCE);
     	build_rotmatrix(TRANSFORM_MATRIX, CURRENT_QUATERNION);
     	glMultMatrixf(&TRANSFORM_MATRIX[0][0]);
    
    	glColor3f(1.0f,0.0f,0.0f);//rot
    
    	// unit box with vertex array and quad strip
    	static GLfloat geometry[] = {
    					(float)(radius*cos(0.0f)), (float)(radius*sin(0.0f)), hoehe,
    					(float)(radius*cos(0.0f)), (float)(radius*sin(0.0f)), hoehe+1,
    
    					(float)(radius*cos(45.0f)), (float)(radius*sin(45.0f)), hoehe,
    					(float)(radius*cos(45.0f)), (float)(radius*sin(45.0f)), hoehe+1,
    
    					(float)(radius*cos(90.0f)), (float)(radius*sin(90.0f)), hoehe,
    					(float)(radius*cos(90.0f)), (float)(radius*sin(90.0f)), hoehe+1,
    
    					(float)(radius*cos(135.0f)), (float)(radius*sin(135.0f)), hoehe,
    					(float)(radius*cos(135.0f)), (float)(radius*sin(135.0f)), hoehe+1,
    
    					(float)(radius*cos(180.0f)), (float)(radius*sin(180.0f)), hoehe,
    					(float)(radius*cos(180.0f)), (float)(radius*sin(180.0f)), hoehe+1,
    
    					(float)(radius*cos(225.0f)), (float)(radius*sin(225.0f)), hoehe,
    					(float)(radius*cos(225.0f)), (float)(radius*sin(225.0f)), hoehe+1,
    
    					(float)(radius*cos(270.0f)), (float)(radius*sin(270.0f)), hoehe,
    					(float)(radius*cos(270.0f)), (float)(radius*sin(270.0f)), hoehe+1,
    
    					(float)(radius*cos(315.0f)), (float)(radius*sin(315.0f)), hoehe,
    					(float)(radius*cos(315.0f)), (float)(radius*sin(315.0f)), hoehe+1,
    
    					(float)(radius*cos(360.0f)), (float)(radius*sin(360.0f)), hoehe,
    					(float)(radius*cos(360.0f)), (float)(radius*sin(360.0f)), hoehe+1
    	};//end geometry[]
    
    	static GLshort topology[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glVertexPointer(3,GL_FLOAT,0,geometry);
    	glDrawElements(GL_QUAD_STRIP,16,GL_UNSIGNED_SHORT,topology);
    	glDisableClientState(GL_VERTEX_ARRAY);
    
    	glutSwapBuffers();
    };
    


  • die funktionen sin und cos erwarten den winkel nicht in grad sondern in rad.



  • super! danke für den tipp!
    hab daran überhaupt nicht mehr gedacht!

    thx
    sven


Anmelden zum Antworten