Début d'implémentation de la flycam.
This commit is contained in:
parent
0d467384f3
commit
82491c509d
13
vertex.cpp
13
vertex.cpp
|
@ -1,4 +1,4 @@
|
|||
#include "vertex.hh"
|
||||
#include "all_includes.hh"
|
||||
|
||||
Vertex::Vertex() {}
|
||||
|
||||
|
@ -13,7 +13,7 @@ Vertex operator+(const Vertex& u, const Vertex& v) {
|
|||
}
|
||||
|
||||
Vertex operator-(const Vertex& u, const Vertex& v) {
|
||||
return Vertex(u.x + v.x, u.y + v.y, u.z + v.z);
|
||||
return Vertex(u.x - v.x, u.y - v.y, u.z - v.z);
|
||||
}
|
||||
|
||||
Vertex operator-(const Vertex& v) {
|
||||
|
@ -27,3 +27,12 @@ Vertex operator*(const Vertex& v, const int n) {
|
|||
Vertex operator/(const Vertex& v, const int n) {
|
||||
return Vertex(v.x / n, v.y / n, v.z / n);
|
||||
}
|
||||
|
||||
Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) {
|
||||
// http://electron9.phys.utk.edu/vectors/3dcoordinates.htm
|
||||
return Vertex(
|
||||
r * std::sin(xAngle / 180 * 3.14159) * std::cos(yAngle / 180 * 3.14159),
|
||||
r * std::sin(xAngle / 180 * 3.14159) * std::sin(yAngle / 180 * 3.14159),
|
||||
r * std::cos(xAngle / 180 * 3.14159)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _VERTEX_HH_
|
||||
#define _VERTEX_HH_
|
||||
|
||||
#include <iostream>
|
||||
#include "all_includes.hh"
|
||||
|
||||
class Vertex {
|
||||
public:
|
||||
|
@ -11,6 +11,7 @@ public:
|
|||
public:
|
||||
Vertex();
|
||||
Vertex(int x, int y, int z);
|
||||
static Vertex fromSpherical(float r, float xAngle, float yAngle);
|
||||
public:
|
||||
friend std::ostream& operator<<(std::ostream& os, const Vertex& v);
|
||||
friend Vertex operator+(const Vertex& u, const Vertex& v);
|
||||
|
|
32
view.cpp
32
view.cpp
|
@ -1,6 +1,6 @@
|
|||
#include "all_includes.hh"
|
||||
|
||||
View::View(Chose* root) : root(root), cameraDist(300), xSight(0), ySight(0), zSight(0), xAngle(0), yAngle(0), moveDist(10) {
|
||||
View::View(Chose* root) : root(root), cameraCenter(500,500,10), cameraDist(300), xSight(0), ySight(0), zSight(0), xAngle(0), yAngle(0), moveDist(10) {
|
||||
initWindow();
|
||||
mainLoop();
|
||||
}
|
||||
|
@ -59,6 +59,21 @@ void View::displayAxes() {
|
|||
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
||||
glVertex3f(0.0f, 0.0f, -2500.0f); // ending point of the line
|
||||
glEnd( );
|
||||
|
||||
Vertex dest = Vertex::fromSpherical(100, xAngle, yAngle);
|
||||
glBegin(GL_LINES);
|
||||
glColor3ub(255,0,255);
|
||||
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
||||
glVertex3d(dest.x, dest.y, dest.z); // ending point of the line
|
||||
glEnd( );
|
||||
|
||||
dest = cameraCenter - dest;
|
||||
glBegin(GL_LINES);
|
||||
glColor3ub(255,255,0);
|
||||
glVertex3d(cameraCenter.x, cameraCenter.y, cameraCenter.z); // origin of the line
|
||||
glVertex3d(dest.x, dest.y, dest.z); // ending point of the line
|
||||
glEnd( );
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
@ -71,9 +86,10 @@ void View::renderScene() {
|
|||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
|
||||
|
||||
//gluLookAt(0,0,cameraDist, 0, 0, 0,0,1,0);
|
||||
glTranslated(-xSight,-ySight,-(zSight+cameraDist));
|
||||
// glTranslated(-xSight,-ySight,-(zSight+cameraDist));
|
||||
glRotatef(-yAngle,1,0,0);
|
||||
glRotatef(-xAngle,0,0,1);
|
||||
glTranslated(-cameraCenter.x, -cameraCenter.y, -cameraCenter.z);
|
||||
|
||||
displayAxes();
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
@ -84,7 +100,6 @@ void View::renderScene() {
|
|||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
void View::mainLoop() {
|
||||
short continuer = 1;
|
||||
SDL_Event event;
|
||||
|
@ -98,18 +113,11 @@ void View::mainLoop() {
|
|||
case SDL_KEYDOWN:
|
||||
switch(event.key.keysym.sym) {
|
||||
case SDLK_DOWN:
|
||||
ySight -= moveDist;
|
||||
cameraCenter = cameraCenter + Vertex::fromSpherical(10, xAngle, yAngle);
|
||||
break;
|
||||
case SDLK_UP:
|
||||
ySight += moveDist;
|
||||
cameraCenter = cameraCenter - Vertex::fromSpherical(10, xAngle, yAngle);
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
xSight -= moveDist;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
xSight += moveDist;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user