Correction du déplacement de la caméra.
This commit is contained in:
parent
82491c509d
commit
4e0853e54f
26
view.cpp
26
view.cpp
|
@ -1,10 +1,14 @@
|
||||||
#include "all_includes.hh"
|
#include "all_includes.hh"
|
||||||
|
|
||||||
View::View(Chose* root) : root(root), cameraCenter(500,500,10), cameraDist(300), xSight(0), ySight(0), zSight(0), xAngle(0), yAngle(0), moveDist(10) {
|
View::View(Chose* root) : root(root), cameraCenter(500,-500,100), cameraDist(300), xSight(0), ySight(0), zSight(0), xAngle(0), yAngle(0), moveDist(10) {
|
||||||
|
xSight = cameraCenter.x + 20;
|
||||||
|
ySight = cameraCenter.y;
|
||||||
|
zSight = cameraCenter.z;
|
||||||
initWindow();
|
initWindow();
|
||||||
mainLoop();
|
mainLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void View::initWindow() {
|
void View::initWindow() {
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
SDL_WM_SetCaption("Sortie terrain OpenGL",NULL);
|
SDL_WM_SetCaption("Sortie terrain OpenGL",NULL);
|
||||||
|
@ -42,6 +46,8 @@ void View::initWindow() {
|
||||||
void View::displayAxes() {
|
void View::displayAxes() {
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glEnable(GL_LINE_SMOOTH);
|
||||||
|
glLineWidth(2);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glColor3ub(255,0,0);
|
glColor3ub(255,0,0);
|
||||||
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
||||||
|
@ -57,7 +63,7 @@ void View::displayAxes() {
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glColor3ub(0,0,255);
|
glColor3ub(0,0,255);
|
||||||
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
||||||
glVertex3f(0.0f, 0.0f, -2500.0f); // ending point of the line
|
glVertex3f(0.0f, 0.0f, 2500.0f); // ending point of the line
|
||||||
glEnd( );
|
glEnd( );
|
||||||
|
|
||||||
Vertex dest = Vertex::fromSpherical(100, xAngle, yAngle);
|
Vertex dest = Vertex::fromSpherical(100, xAngle, yAngle);
|
||||||
|
@ -85,11 +91,9 @@ void View::renderScene() {
|
||||||
//glClearColor(1,1,1,1); // pour un fond blanc
|
//glClearColor(1,1,1,1); // pour un fond blanc
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
|
||||||
|
|
||||||
//gluLookAt(0,0,cameraDist, 0, 0, 0,0,1,0);
|
Vertex sight;
|
||||||
// glTranslated(-xSight,-ySight,-(zSight+cameraDist));
|
sight = cameraCenter + Vertex::fromSpherical(100, yAngle, xAngle);
|
||||||
glRotatef(-yAngle,1,0,0);
|
gluLookAt(cameraCenter.x,cameraCenter.y,cameraCenter.z, sight.x, sight.y, sight.z,0,0,1);
|
||||||
glRotatef(-xAngle,0,0,1);
|
|
||||||
glTranslated(-cameraCenter.x, -cameraCenter.y, -cameraCenter.z);
|
|
||||||
|
|
||||||
displayAxes();
|
displayAxes();
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
|
@ -113,10 +117,10 @@ void View::mainLoop() {
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
switch(event.key.keysym.sym) {
|
switch(event.key.keysym.sym) {
|
||||||
case SDLK_DOWN:
|
case SDLK_DOWN:
|
||||||
cameraCenter = cameraCenter + Vertex::fromSpherical(10, xAngle, yAngle);
|
cameraCenter = cameraCenter + Vertex::fromSpherical(100, yAngle, xAngle);
|
||||||
break;
|
break;
|
||||||
case SDLK_UP:
|
case SDLK_UP:
|
||||||
cameraCenter = cameraCenter - Vertex::fromSpherical(10, xAngle, yAngle);
|
cameraCenter = cameraCenter - Vertex::fromSpherical(100, yAngle, xAngle);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -124,8 +128,8 @@ void View::mainLoop() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
xAngle = ((event.motion.x-windowWidth/2)*340/(windowWidth));
|
xAngle = (event.motion.x - (windowWidth/2))*340/windowWidth;
|
||||||
yAngle = (event.motion.y-windowHeight/2)*340/(windowHeight);
|
yAngle = (event.motion.y - (windowHeight/2))*340/windowHeight;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user