PDA

View Full Version : one questions (Important)



orache
06-16-2013, 10:43 AM
hello all
I have lots of questions In OpenGl (i can not speak English very well :D )
.

.
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 :D
please help me ............ this code is very bad

#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();


}

orache
06-17-2013, 01:02 AM
please help me

Dan Bartlett
06-17-2013, 02:07 AM
http://www.opengl.org/archives/resources/faq/technical/viewing.htm


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);