Hi , I am trying to use gluLookAt() function for run time animation for that I take coordinates from a text file and pass those coordinates to gluLookAt(). But somehow my is not working. I have recently started working on OpenGL and GLUT .
When I run my code it gives a transparent window in the beginning and then shows the cube. I want to move the camera to give effect as if object is moving. I am posting my code …
Can anybody help me?
Thank you
Rohit
#include <math.h>
#include <GL/glut.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include <windows.h>
using namespace std;
float angle=0.0,deltaAngle = 0.0,ratio;
float x=0.0f,y=1.75f,z=5.0f;
float lx=0.0f,ly=0.0f,lz=-1.0f;
GLint snowman_display_list;
int deltaMove = 0;
float a = 0.0f;
int b = 0;
void changeSize(int w, int h)
{
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;
ratio = 1.0f * w / h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the clipping volume
gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void renderScene(void)
{
FILE *file;
float numbers[3];
float rx,ry,rz;
int i;
file = fopen(“C:\Users\RoBa\Desktop\ est.txt”, “r”);
while(feof(file)== NULL)
{ //b = 0;
fscanf(file, "%f %f %f ", &numbers[b],&numbers[b+1], &numbers[b+2]);
rx = (numbers[b])/10;
ry = (numbers[b+1])/10;
rz = (numbers[b+2])/10;
cout<<rx<<endl;
cout<<ry<<endl;
cout<<rz<<endl;
glLoadIdentity();
gluLookAt(0.0f , 0.0f , -(10.0*rz) , 0.0f,0.0f,0.f,0.0f,1.0f,0.0f);
glFlush();
}
fclose(file);
cout<<rx<<endl;
cout<<ry<<endl;
cout<<rz<<endl;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutWireCube(2.0f);
glutPostRedisplay();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(640,360);
glutCreateWindow(“My animation”);
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutMainLoop();
return(0);
}