perhpe’s i don’t need to create it but i change the code
instead of mouse i use glSpecialFunc and there now only problem of Problem of Axis and one’s rotation
Main.cpp:
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include “Shapes.h”
#define WinWidth 640
#define WinHeight 480
/*This Time
A plane with objects lied on it
i try to move around the world of plane(glRectf is right choice for it instead of those of 4 vertex’s)
*/
//where
GLfloat x = 0.0f,y = 2.0f,z = 0.0f;
//what
GLfloat Cx,Cy,Cz;
GLfloat alpha = 0.0f,beta = 0.0f,gama = 90.0f;
GLfloat col[4] = {0.70f,0.70f,0.70f,0.70f};
// not much but for measureable distance
void fog(GLfloat Density,GLfloat *col)
{
glFogf( GL_FOG_DENSITY, Density );
glFogfv( GL_FOG_COLOR, col );
glFogf( GL_FOG_START, -10.0f );
glFogf( GL_FOG_END, 100.0f );
glFogf( GL_FOG_MODE, GL_EXP );
}
void CameraMan()
{
///gluLookAt(x,y,z,Cx,Cy,Cz,0.0f,1.0f,0.0f);Cx <->x , Cy <-> y Cz <->z
//for circle there must radius let it 0.5f
Cx = sin(alpha);
Cy = sin(beta);
Cz = sin(gama);
if(beta > 180.0f)beta = 180.0f;
else if(beta < -180.0f)beta = -180.0f;
gluLookAt(x,y,z,Cx+x,Cy+y,Cz+z,0.0f,1.0f,0.0f);
}
void ReSce()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glEnable(GL_DEPTH_TEST);
fog(1.0f ,col);
glEnable(GL_FOG);
CameraMan();
glMatrixMode(GL_PROJECTION);
glTranslatef(0.0f,0.0f,-1.0f);
glLoadIdentity();
glPushMatrix();
glColor3f(0.0f,1.0f,0.0f);
glTranslatef(0.0f,-1.0f,0.0f);
glRotatef(90.0f,1.0f,0.0f,0.0f);
glRectf(2.0f,2.0f,-2.0f,-2.0f);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glutSwapBuffers();
}
void WinSize(int w,int h)
{
GLfloat As = (GLfloat)w/(GLfloat)h;
glMatrixMode(GL_PROJECTION);
gluPerspective(90.0f,As,-1.0f,500.0f);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);
}
void Idle()
{glLoadIdentity();
glutPostRedisplay();
}
void keyb(unsigned char k , int x, int y)
{
switch(k)
{
case 27:
case ‘q’:
exit(0);
break;
case ‘w’:
z+=0.2f;
break;
case ‘a’:
::x-=0.2f;
break;
case ‘s’:
z-=0.2f;
break;
case ‘d’:
::x+=0.2f;
break;
}
}
void Special(int k,int x,int y)
{switch(k)
{
case GLUT_KEY_LEFT:
gama+=0.1;
break;
case GLUT_KEY_RIGHT:
gama-=0.1;
break;
case GLUT_KEY_UP:
beta+=0.1;
break;
case GLUT_KEY_DOWN:
beta-=0.1;
break;
}
}
int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutInitWindowSize(WinWidth,WinHeight);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(“Win”);
glEnable(GL_FOG);
glutDisplayFunc(ReSce);
glutReshapeFunc(WinSize);
glutKeyboardFunc(keyb);
glutSpecialFunc(Special);
glutIdleFunc(Idle);
glutMainLoop();
}
#ifdef LINUX_USER
LIB = -I/usr/lib
INC = -I/usr/include
SRC = main.cpp
COMP = gcc
LINK = -lglut -lGL
1st:
$(COMP) -o Cam2 $(SRC) $(INC) $(LIB) $(LINK)
#endif
only problem of gama/alpha rotation
and axis motion(z,x)
help me about this(z,x,gama/alpha/beta)