Potrebno mi je pomjeranje kamere po svim osama (x, y, z).
Koristio sam funkciju gluLookAt i realizovao pomjeranje cajnika po z osi te rotaciju kamere.
Na isti nacin (promjenom parametara gluLookAt funkcije pomocu tastature) sam pokusao realizovati pomjeranje po x i y osama, ali iz nekog razloga pritiskom na tipke koje bi trebale kontrolisati pomjeranje po tim osama ne dobijam nikakav odziv. U isto vrijeme, pomjeranje po z radi kako treba.
Kod koji sam do sad napisao je dat u nastavku.
Code:
#include <windows.h>
#include <GL/glut.h>
#include <math.h>
void display();
float angle;
float angle3 = 0.0;
float lx = 0.0, lz = -1.0, ly = 0.0;
float x = 0.0, z = 1.0, y = 1.0;
float fraction = 0.1;
void kbd(unsigned char key, int x, int y) {
switch(key) {
case 27:
exit(0);
break;
case 'a':
case 'A':
angle += 0.1;
if(angle > 360)
angle -= 360;
break;
case 'd':
case 'D':
angle -= 0.1;
if(angle < 0)
angle += 360;
break;
case 'f':
case 'F':
angle3 -= 0.1;
lx = sin(angle3);
lz = -cos(angle3);
break;
case 'h':
case 'H':
angle3 += 0.1;
lx = sin(angle3);
lz = -cos(angle3);
break;
case 'g':
case 'G':
//x += lx * fraction;
z += fraction;
break;
case 't':
case 'T':
//x -= lx * fraction;
z -= fraction;
break;
case 'j':
case 'J':
x -= fraction;
break;
case 'l':
case 'L':
x += fraction;
break;
case 'i':
case 'I':
y += fraction;
break;
case 'k':
case 'K':
y -= fraction;
break;
}
glutPostRedisplay();
}
int main(int argc, char** argv){
glutInit(&argc,argv);
glutInitWindowSize(1000, 800);
glutCreateWindow("Cajnik");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display() {
glClear (GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 15.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -2.0);
glRotatef(angle, 0.0, 0.0, 1.0);
gluLookAt(x, y, z,
x + lx, y, z + lz,
0.0, 1.0, 0.0);
glutWireTeapot(1.0);
glutKeyboardFunc(kbd);
glFlush();
}
#include <windows.h>
#include <GL/glut.h>
#include <math.h>
void display();
float angle;
float angle3 = 0.0;
float lx = 0.0, lz = -1.0, ly = 0.0;
float x = 0.0, z = 1.0, y = 1.0;
float fraction = 0.1;
void kbd(unsigned char key, int x, int y) {
switch(key) {
case 27:
exit(0);
break;
case 'a':
case 'A':
angle += 0.1;
if(angle > 360)
angle -= 360;
break;
case 'd':
case 'D':
angle -= 0.1;
if(angle < 0)
angle += 360;
break;
case 'f':
case 'F':
angle3 -= 0.1;
lx = sin(angle3);
lz = -cos(angle3);
break;
case 'h':
case 'H':
angle3 += 0.1;
lx = sin(angle3);
lz = -cos(angle3);
break;
case 'g':
case 'G':
//x += lx * fraction;
z += fraction;
break;
case 't':
case 'T':
//x -= lx * fraction;
z -= fraction;
break;
case 'j':
case 'J':
x -= fraction;
break;
case 'l':
case 'L':
x += fraction;
break;
case 'i':
case 'I':
y += fraction;
break;
case 'k':
case 'K':
y -= fraction;
break;
}
glutPostRedisplay();
}
int main(int argc, char** argv){
glutInit(&argc,argv);
glutInitWindowSize(1000, 800);
glutCreateWindow("Cajnik");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display() {
glClear (GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 15.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -2.0);
glRotatef(angle, 0.0, 0.0, 1.0);
gluLookAt(x, y, z,
x + lx, y, z + lz,
0.0, 1.0, 0.0);
glutWireTeapot(1.0);
glutKeyboardFunc(kbd);
glFlush();
}
Izvinjavam se unaprijed ako je bila slicna tema, ja je nisam pronasao.
Unaprijed hvala svima na pomoci.