i have a problem where whenever u move the camera all the object on screen disappear here is my code
class camera
{
public:
GLfloat eye[3];
GLfloat up[3];
GLfloat side[3];
GLfloat look[3];
GLfloat matrix[3][3];
GLfloat vertMatrix[3];
GLfloat tmpMatrix[3];
camera()
{ // Camera Position
eye[0] = 0.0f; eye[1] = 0.0f; eye[2] = 0.0f;
up[0] = 0.0f; up[1] = 1.0f; up[2] = 0.0f;
side[0] = 1.0f; side[1] = 0.0f; side[2] = 0.0f;
look[0] = 0.0f; look[1] = 0.0f; look[2] = -1.0f;
matrix = {
{side[0] - eye[0], up[0] - eye[0], look[0] - eye[0]},
{side[1] - eye[1], up[1] - eye[1], look[1] - eye[1]},
{side[2] - eye[2], up[2] - eye[2], look[2] - eye[2]}};
};
void updatePosi()
{
glLoadIdentity();// Update the camera
gluLookAt( eye[0], eye[1], eye[2], look[0], look[1], look[2], up[0] - eye[0], up[1] - eye[1], up[2] - eye[2]);
}
void translatePosi(GLfloat x1, GLfloat y1, GLfloat z1)
{
matrix = {
{side[0] - eye[0], up[0] - eye[0], look[0] - eye[0]},
{side[1] - eye[1], up[1] - eye[1], look[1] - eye[1]},
{side[2] - eye[2], up[2] - eye[2], look[2] - eye[2]}
};
vertMatrix = { x1, y1, -z1};
tmpMatrix = {matrix[0][0] * vertMatrix[0] + matrix[0][1]* vertMatrix[0] + matrix[0][2]* vertMatrix[0],
matrix[1][0] * vertMatrix[1] + matrix[1][1]* vertMatrix[1] + matrix[1][2]* vertMatrix[1],
matrix[2][0] * vertMatrix[2] + matrix[2][1]* vertMatrix[2] + matrix[2][2]* vertMatrix[2]};
eye[0] += tmpMatrix[0]; eye[1] += tmpMatrix[1]; eye[2] += tmpMatrix[2];
up[0] += tmpMatrix[0]; up[1] += tmpMatrix[1]; up[2] += tmpMatrix[2];
side[0] += tmpMatrix[0]; side[1] += tmpMatrix[1]; side[2] += tmpMatrix[2];
look[0] += tmpMatrix[0]; look[1] += tmpMatrix[1]; look[2] += tmpMatrix[2];
}
};
void display()
{
glClearColor( 0.0, 0.0f, 0.0, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
keymanage();
glLoadIdentity();
cam.updatePosi();
enable();
glutSolidCube(0.25f);
glutSwapBuffers();
}
int main(int argc, char **args)
{
glutInit(&argc, args);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("opengl mycode");
init();
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyDown);
glutKeyboardUpFunc(keyUp);
glutMainLoop();
return 0;
}
i 'm am very new to opengl so any help would be appreciated.