Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: one questions (Important)

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    7

    one questions (Important)

    hello all
    I have lots of questions In OpenGl (i can not speak English very well )
    .

    .
    1_ i want to create a camera Similar 3Ds max or maya or blender but i can not create very well . this is my code
    There are different things in the code
    please help me ............ this code is very bad
    Code :
    #include <freeglut.h>
    float _EYEX = 0.0f ;
    float _EYEY = 0.0f ;
    float _EYEZ = 1 ;
    float _CENTERX = 0.0f ;
    float _CENTERY = 0.0f ;
    float _CENTERZ = -100.0f ;
     
    float _UPX = 0.0f ;
    float _UPY = 1.0f;
    float _UPZ = 0.0f ;
     
     
    void keyboard(unsigned char key , int x , int y )
    {
    	switch (key)
    	{
    	case 'q' :
    		_EYEX += 0.05 ;
    		break ;
    	case 'w' :
    		_EYEX -= 0.05 ;
    		break ;
     
     
    	case 'a' :
    		_EYEY += 0.05 ;
    		break ;
    	case 's' :
            _EYEY -= 0.05 ;
    		break ;
     
    	case 'z' :
    		_EYEZ += 0.05 ;
    		break ;
    	case 'x' :
            _EYEZ -= 0.05 ;
    		break ;
     
    		/////////////
    	case 'e' :
    		_CENTERX += 10 ;
    		break ;
    	case 'r' :
            _CENTERX -= 10 ;
    		break ;
     
    	case 'd' :
    		_CENTERY += 10 ;
    		break ;
    	case 'f' :
            _CENTERY -= 10 ;
    		break ;
     
    	case 'c' :
    		_CENTERZ += 10 ;
    		break ;
    	case 'v' :
            _CENTERZ -= 10 ;
    		break ;
    		////////////
    	case 't' :
    		_UPX += 0.1 ;
    		break ;
    	case 'y' :
            _UPX -= 0.1 ;
    		break ;
    	case 'g' :
    		_UPY += 0.1 ;
    		break ;
    	case 'h' :
            _UPY -= 0.1 ;
    		break ;
    	case 'b' :
    		_UPZ += 0.1 ;
    		break ;
    	case 'n' :
            _UPZ -= 0.1 ;
    		break ;
    	}
    }
    float ZOOM_WIDTH = 1280 ;
    float ZOOM_HEIGHT = 960 ;
     
    void display()
    {
    	glClear(GL_COLOR_BUFFER_BIT);
    	glClearColor(0.3,0.3,0.3,1);
    	///////////////////////////////////////////////////////////////////////////
    	glColor3f(0,0,0);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity(); 
        glViewport(0,0,ZOOM_WIDTH ,ZOOM_HEIGHT);
    	gluPerspective(45, ZOOM_WIDTH/ZOOM_HEIGHT, 0.1f, -100.0f);
        gluLookAt(_EYEX, _EYEY, _EYEZ, _CENTERX, _CENTERY, _CENTERZ, _UPX, _UPY, _UPZ);
     
     
     
    	glLineWidth(1);
     
    	for (float xxx = -3 ; xxx <= 3 ; xxx += 0.1 )
    	{
    		glBegin(GL_LINES);
    		glVertex2f(xxx , -3 );
    		glVertex2f(xxx , +3 );
    		glEnd();
    	}
    	for (float yyy = -3 ; yyy <= 3 ; yyy += 0.1 )
    	{
    		glBegin(GL_LINES);
    		glVertex2f(-3 , yyy );
    		glVertex2f(+3 , yyy );
    		glEnd();
    	}
    	glLineWidth(3);
    	glBegin(GL_LINES);
    	glVertex2f(-3 , 0 );
    	glVertex2f(+3 , 0);
    	glVertex2f(0 , +3 );
    	glVertex2f(0 , -3);
    	glEnd();
    	glDisable(GL_LIGHT0);
    	glDisable(GL_LIGHTING);
    	glPushMatrix();
    	glColor3f(0,0,1);
    	glRotatef(90,0,1,0);
    	glutSolidCylinder(0.002,0.2,10,10);
    	glTranslatef(0,0,0.2);
    	glutSolidCone(0.01,0.02,10,10);
    	glPopMatrix();
     
    	glPushMatrix();
    	glColor3f(0,1,0);
    	glRotatef(90,1,0,0);
    	glutSolidCylinder(0.002,0.2,10,10);
    	glTranslatef(0,0,0.2);
    	glutSolidCone(0.01,0.02,10,10);
    	glPopMatrix();
     
        glPushMatrix();
    	glColor3f(1,0,0);
    	glutSolidCylinder(0.002,0.2,10,10);
    	glTranslatef(0,0,0.2);
    	glutSolidCone(0.01,0.02,10,10);
    	glPopMatrix();
    	//////////////////////////////////////////
    	glEnable(GL_LIGHTING);
    	glEnable(GL_LIGHT0);
    	GLfloat lightPos[] = { 2.0, 4.0, -3.0, 1.0 };
        glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
    	glPushMatrix();
    	glRotatef(90,1,0,0);
    	glutSolidTeapot(0.05);
    	glPopMatrix();
    	/////////////////////////////////////////////////////////////////////////////
    	glutPostRedisplay();
    	glutSwapBuffers();
    	glFlush();
    }
     
     
    int main (int argc , char ** argv)
    {
    	glutInit(&argc,argv);
    	glutInitDisplayMode(GLUT_DOUBLE);
    	glutInitWindowSize(ZOOM_WIDTH,ZOOM_HEIGHT);
        glutCreateWindow("orache");
    	glutDisplayFunc(display);
    	glutKeyboardFunc(keyboard);
    	glutMainLoop();
     
     
    }

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    7
    please help me

  3. #3
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    454
    http://www.opengl.org/archives/resou...al/viewing.htm

    Code :
    glViewport(0,0,ZOOM_WIDTH ,ZOOM_HEIGHT);
     
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45, ZOOM_WIDTH/ZOOM_HEIGHT, 0.1f, -100.0f);
     
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(_EYEX, _EYEY, _EYEZ, _CENTERX, _CENTERY, _CENTERZ, _UPX, _UPY, _UPZ);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •