PDA

View Full Version : Setting a camera



Cypray
03-24-2004, 04:08 AM
I need to use the perspective camera to show an entire seen and also have it pan around the seen to that the object on the seen can be viewed from different angles. The objects will be in 3D.

Does any one knows how I can do this and the codes I need to do it?

Nychold
03-24-2004, 05:28 AM
Use gluLookAt(cameraX, cameraY, cameraZ, lookX, lookY, lookZ, upX, upY, upZ) where the vector <cameraX, cameraY, cameraZ> is the position of your camera, <lookX, lookY, lookZ> is the direction the camera is aiming and <upX, upY, upZ> is the "up" vector (since you can tilt the camera on its side).

Cypray
03-24-2004, 06:00 AM
Thanks for your help. I am having problems establishing those vectors for the objects that I am drawing.
Here is the code that I have. How do I get the valuse that will work with this?

#include <windows.h>
#include <gl/Gl.h>
#include <gl/Glu.h>
#include <gl/glut.h>
#include <math.h>
#include <iostream.h>
#include <fstream.h>

void displayWire(void)
{

/* glMatrixMode(GL_PROJECTION); // set the view Volume
glLoadIdentity();
glOrtho(-2.0*64/48.0, 2.0*64/48.0, -2.0, 2.0, 0.1, 100);
glMatrixMode(GL_MODELVIEW); // place and aim the camera
glLoadIdentity();
gluLookAt(2.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

*/

glClear(GL_COLOR_BUFFER_BIT);




glBegin(GL_LINE_STRIP); //draw the next polyline

glVertex2i(200, 300);
glVertex2i(150, 315);
glVertex2i(220, 335);
glVertex2i(200, 300);
glVertex2i(190, 370);
glVertex2i(220, 335);
glVertex2i(150, 315);
glVertex2i(190, 370);



glEnd();

glFlush();

glBegin(GL_LINE_STRIP); //draw the next polyline

glVertex2i(400, 300);
glVertex2i(400, 350);
glVertex2i(450, 350);
glVertex2i(450, 300);
glVertex2i(400, 300);
glVertex2i(400, 350);
glVertex2i(425, 375);
glVertex2i(475, 375);
glVertex2i(450, 350);
glVertex2i(450, 300);
glVertex2i(475, 325);
glVertex2i(475, 375);



glEnd();

glFlush();

glBegin(GL_LINE_STRIP); //draw the next polyline

glVertex2i(400, 130);
glVertex2i(300, 30);
glVertex2i(200, 130);
glVertex2i(300, 230);
glVertex2i(400, 130);
glVertex2i(280, 100);
glVertex2i(300, 230);
glVertex2i(200, 130);
glVertex2i(280, 100);
glVertex2i(300, 30);



glEnd();

glFlush();

}

int main()
{

char* argv[1];
char dummyString[8];
argv[0] = dummyString;
int argc= 1;

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 100);
glutCreateWindow("Letter window");
glMatrixMode(GL_PROJECTION);

glClearColor(1.0,1.0,1.0,0.0);
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glViewport(0, 0, 640, 480);


glutDisplayFunc(displayWire);
glutMainLoop();

return 0;

}