tlsn2
November 26th, 2006, 08:10 AM
Hey all,
I am trying to do a very simple task in openGL and glut.
I've built a viewer that allows me to control the camera movement in my 3D generated world. I want to add this simple feature, I want to be able to press the 's' key and let my camera to get back to its origin point. I want to actually see the movement and not just to "jump" to the origin point.
For some reason I cant make this happen, no matter what I do I cant make the screen render after every iteration. Can someone please take a short look and tell me what am I doing wrong:
//in main
glutKeyboardFunc ( myKeysFunc );
//Keys events func
void myKeysFunc( unsigned char key, int x, int y )
{
if (key=='q')
{
cout << endl << "GoodBye..." << endl;
exit(0);
}
....
if(key == 's')
{
goToPosition(2.3, 5, 3, 0, -1, 0);
}
glutPostRedisplay();
printf("Xcoor = %f, Ycoor = %f, Zcoor = %f, lookX = %f, lookY = %f, lookZ = %f, upX = %f, upY = %f, upZ = %f\n", Xcoor,Ycoor,Zcoor,lookX,lookY,lookZ, Xup, Yup, Zup);
}
//Camera movement func
void goToPosition(float newX, float newY, float newZ,
float newLookX, float newLookY, float newLookZ)
{
int xDistance1 = newX - Xcoor;
int yDistance1 = newY - Ycoor;
int zDistance1 = newZ - Zcoor;
int xDistance2 = newLookX - lookX;
int yDistance2 = newLookY - lookY;
int zDistance2 = newLookZ - lookZ;
cout << endl << endl;
for (int i = 0; i < FRAMES; ++i)
{
Xcoor += (float)xDistance1/FRAMES;
Ycoor += (float)yDistance1/FRAMES;
Zcoor += (float)zDistance1/FRAMES;
lookX += (float)xDistance2/FRAMES;
lookY += (float)yDistance2/FRAMES;
lookZ += (float)zDistance2/FRAMES;
cout << "Xcoor: " << Xcoor << " ";
glutSwapBuffers();
glutPostRedisplay();
sleep(100);
}
cout << endl << endl;
}
I am trying to do a very simple task in openGL and glut.
I've built a viewer that allows me to control the camera movement in my 3D generated world. I want to add this simple feature, I want to be able to press the 's' key and let my camera to get back to its origin point. I want to actually see the movement and not just to "jump" to the origin point.
For some reason I cant make this happen, no matter what I do I cant make the screen render after every iteration. Can someone please take a short look and tell me what am I doing wrong:
//in main
glutKeyboardFunc ( myKeysFunc );
//Keys events func
void myKeysFunc( unsigned char key, int x, int y )
{
if (key=='q')
{
cout << endl << "GoodBye..." << endl;
exit(0);
}
....
if(key == 's')
{
goToPosition(2.3, 5, 3, 0, -1, 0);
}
glutPostRedisplay();
printf("Xcoor = %f, Ycoor = %f, Zcoor = %f, lookX = %f, lookY = %f, lookZ = %f, upX = %f, upY = %f, upZ = %f\n", Xcoor,Ycoor,Zcoor,lookX,lookY,lookZ, Xup, Yup, Zup);
}
//Camera movement func
void goToPosition(float newX, float newY, float newZ,
float newLookX, float newLookY, float newLookZ)
{
int xDistance1 = newX - Xcoor;
int yDistance1 = newY - Ycoor;
int zDistance1 = newZ - Zcoor;
int xDistance2 = newLookX - lookX;
int yDistance2 = newLookY - lookY;
int zDistance2 = newLookZ - lookZ;
cout << endl << endl;
for (int i = 0; i < FRAMES; ++i)
{
Xcoor += (float)xDistance1/FRAMES;
Ycoor += (float)yDistance1/FRAMES;
Zcoor += (float)zDistance1/FRAMES;
lookX += (float)xDistance2/FRAMES;
lookY += (float)yDistance2/FRAMES;
lookZ += (float)zDistance2/FRAMES;
cout << "Xcoor: " << Xcoor << " ";
glutSwapBuffers();
glutPostRedisplay();
sleep(100);
}
cout << endl << endl;
}