Answer the question
In order to leave comments, you need to log in
Why doesn't gluLookAt change camera position?
Actually a question.
There is a simple program where 2 circles of different colors are drawn one after another, when you press the button, you need the cashier to change position and look at these circles from the other side.
For some reason, gluLookAt does not work, or I just screwed up somewhere :(
Please tell me what is the problem
/* gcc test.c -o test -lGL -lGLU -lglut -lXi -lXmu */
#include <stdlib.h>
#include <stdio.h>
/* подключаем библиотеку GLUT */
#include <GL/glut.h>
#include <math.h>
/* начальная ширина и высота окна */
GLint Width = 500, Height = 500;
int R = 1;
int LOOK = 0;
float eyeX = 0,eyeY = 0,eyeZ = 0, lookX = 0,lookY = 0,lookZ = 0, upX = 0,upY = 1,upZ = 0;
void changeLOOK() {
if (LOOK == 1) {
LOOK = 0;
eyeZ = -4.0;
}
else {
LOOK = 1;
eyeZ = 4.0;
}
}
void Circle()
{
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -2.0f);
glColor3ub(0,0,255);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(Width/2, Height/2);
for (int i = 0; i < 100; i++){
float angle = (float)i / 3.1415f * 100 * 2.0;
glVertex2f(Width/2-cos(angle)*100, Height/2-sin(angle)*100);
}
glEnd();
glLoadIdentity();
glTranslatef(5.0f, 5.0f ,2.0f);
glColor3ub(255,0,0);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(Width/2, Height/2);
for (int i = 0; i < 100; i++){
float angle = (float)i / 3.1415f * 100 * 2.0;
glVertex2f(Width/2-cos(angle)*100, Height/2-sin(angle)*100);
}
glEnd();
}
void Display(void)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Circle();
glLoadIdentity();
gluLookAt(eyeX, eyeY, eyeZ,
lookX, lookY, lookZ,
upX, upY, upZ);
glFinish();
}
/* Функция вызывается при изменении размеров окна */
void Reshape(GLint w, GLint h)
{
Width = w;
Height = h;
/* устанавливаем размеры области отображения */
glViewport(0, 0, w, h);
/* ортографическая проекция */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glFrustum(0, w, 0, h, 1, 200.0);
glOrtho(0, w, 0, h, -10, 10);
glMatrixMode(GL_MODELVIEW);
}
/* Функция обрабатывает сообщения от клавиатуры */
void Keyboard(unsigned char key, int x, int y)
{
#define ESCAPE '\033'
#define key_n 'n'
if( key == ESCAPE )
exit(0);
if (key == key_n)
{
printf("eyeX = %f eyeY = %f eyeZ = %f \n",eyeX, eyeY, eyeZ );
printf("lookX = %f lookY = %f lookZ = %f \n",lookX, lookY, lookZ );
printf("upX = %f upY = %f upZ = %f \n",upX, upY, upZ );
printf("-------------------------\n");
glMatrixMode(GL_MODELVIEW);
changeLOOK();
}
}
/* Главный цикл приложения */
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowPosition(700, 0);
glutInitWindowSize(Width, Height);
glutCreateWindow("red square");
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutKeyboardFunc(Keyboard);
glutMainLoop();
return 1;
}
Answer the question
In order to leave comments, you need to log in
Because stop learning the technologies of 1999!
Learn modern OpenGL, with a pipeline, normal batching, shaders and other goodies.
There is no point in what you teach, in modern versions it has already been removed from the standard and is not supported. You'll have to relearn later, unless, of course, you want to write games for NVidia MX440, I advise you to start learning at least OpenGL 3.3 as soon as possible, before it's too late.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question