bug : L'utilisation du grab de la souris générait des évènements qui faisaient pivoter la caméra avant la première frame.
This commit is contained in:
parent
2a816ef4f1
commit
e035eac1c8
|
@ -38,7 +38,7 @@ class Vertexf {
|
||||||
static Vertexf fromSpherical(float r, float xAngle, float yAngle);
|
static Vertexf fromSpherical(float r, float xAngle, float yAngle);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend std::ostream& operator<<(std::ostream& os, const Vertex& v);
|
friend std::ostream& operator<<(std::ostream& os, const Vertexf& v);
|
||||||
friend Vertexf operator+(const Vertexf& u, const Vertexf& v);
|
friend Vertexf operator+(const Vertexf& u, const Vertexf& v);
|
||||||
friend Vertexf operator-(const Vertexf& u, const Vertexf& v);
|
friend Vertexf operator-(const Vertexf& u, const Vertexf& v);
|
||||||
friend Vertexf operator-(const Vertexf& v);
|
friend Vertexf operator-(const Vertexf& v);
|
||||||
|
|
69
view.cpp
69
view.cpp
|
@ -1,6 +1,6 @@
|
||||||
#include "all_includes.hh"
|
#include "all_includes.hh"
|
||||||
|
|
||||||
View::View(Chose* root) : root(root), camera(Camera(Vertexf(127,0,128),180,-20,40,0.6)) {
|
View::View(Chose* root) : root(root), camera(Camera(Vertexf(420,468,151),230,108,40,0.6)) {
|
||||||
initWindow();
|
initWindow();
|
||||||
mainLoop();
|
mainLoop();
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ void View::renderScene(int lastTime, int currentTime) {
|
||||||
camera.setCamera();
|
camera.setCamera();
|
||||||
|
|
||||||
setLight();
|
setLight();
|
||||||
displayAxes();
|
//displayAxes();
|
||||||
root->display();
|
root->display();
|
||||||
|
|
||||||
glFlush();
|
glFlush();
|
||||||
|
@ -97,6 +97,7 @@ void View::mainLoop() {
|
||||||
SDL_EnableKeyRepeat(40,40);
|
SDL_EnableKeyRepeat(40,40);
|
||||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
while ( SDL_PollEvent(&event) ); // empty queue.
|
||||||
|
|
||||||
int lastTime = SDL_GetTicks() - 30;
|
int lastTime = SDL_GetTicks() - 30;
|
||||||
int currentTime = 0;
|
int currentTime = 0;
|
||||||
|
@ -112,60 +113,35 @@ void View::mainLoop() {
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
camera.keyboard(event.key);
|
camera.keyboard(event.key);
|
||||||
/*switch(event.key.keysym.sym) {
|
|
||||||
case SDLK_DOWN:
|
|
||||||
cameraCenter = cameraCenter - Vertex::fromSpherical(moveDist, yAngle, xAngle);
|
|
||||||
break;
|
break;
|
||||||
case SDLK_UP:
|
|
||||||
cameraCenter = cameraCenter + Vertex::fromSpherical(moveDist, yAngle, xAngle);
|
|
||||||
break;
|
|
||||||
case SDLK_PAGEUP:
|
|
||||||
cameraCenter = cameraCenter - Vertex::fromSpherical(moveDist, yAngle + 90, xAngle);
|
|
||||||
break;
|
|
||||||
case SDLK_PAGEDOWN:
|
|
||||||
cameraCenter = cameraCenter + Vertex::fromSpherical(moveDist, yAngle + 90, xAngle);
|
|
||||||
break;
|
|
||||||
case SDLK_LEFT:
|
|
||||||
cameraCenter = cameraCenter - Vertex::fromSpherical(moveDist, 90, xAngle - 90);
|
|
||||||
break;
|
|
||||||
case SDLK_RIGHT:
|
|
||||||
cameraCenter = cameraCenter + Vertex::fromSpherical(moveDist, 90, xAngle - 90);
|
|
||||||
break;
|
|
||||||
case SDLK_ESCAPE:
|
|
||||||
continuer = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (SDL_GetKeyName(event.key.keysym.sym)[0] == 'q')
|
|
||||||
continuer = 0;
|
|
||||||
if (SDL_GetKeyName(event.key.keysym.sym)[0] == 'p') { // _Print _Position
|
|
||||||
std::cout << "Camera = " << cameraCenter << " xAngle = " << xAngle << " yAngle = " << yAngle << std::endl;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}*/
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
camera.mouseMotion(event.motion);
|
camera.mouseMotion(event.motion);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderScene(lastTime,currentTime);
|
renderScene(lastTime,currentTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera::Camera(Vertexf pos, float xA, float yA, int moveSensitivity, float mouseSensitivity) {
|
Camera::Camera(Vertexf pos, float xA, float yA, int moveSensitivity, float mouseSensitivity)
|
||||||
cameraCenter = pos;
|
: cameraCenter(pos),
|
||||||
xAngle = xA;
|
cameraSight(cameraCenter + Vertexf::fromSpherical(100,yA,xA)),
|
||||||
yAngle = yA;
|
xAngle(xA),
|
||||||
cameraSight = cameraCenter + Vertexf::fromSpherical(100,yA,xA);
|
yAngle(yA),
|
||||||
moveDist = moveSensitivity;
|
moveDist(moveSensitivity),
|
||||||
this->mouseSensitivity = mouseSensitivity;
|
mouseSensitivity(mouseSensitivity),
|
||||||
|
up(false), down(false), left(false), right(false),
|
||||||
|
pageUp(false), pageDown(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& Camera::print(std::ostream& os) const {
|
||||||
|
return os << "Camera = " << cameraCenter << " xAngle = "
|
||||||
|
<< xAngle << " yAngle = " << yAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::setCamera() {
|
void Camera::setCamera() {
|
||||||
|
@ -206,6 +182,15 @@ void Camera::keyboard(const SDL_KeyboardEvent &eventKey) {
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
|
switch(SDL_GetKeyName(eventKey.keysym.sym)[0]) {
|
||||||
|
case 'q':
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
case 'p': // _Print _Position
|
||||||
|
std::cout << *this << std::endl;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
view.hh
2
view.hh
|
@ -30,6 +30,8 @@ class Camera {
|
||||||
void mouseMotion(const SDL_MouseMotionEvent &event);
|
void mouseMotion(const SDL_MouseMotionEvent &event);
|
||||||
void keyboard(const SDL_KeyboardEvent &event);
|
void keyboard(const SDL_KeyboardEvent &event);
|
||||||
void animation(int elapsedTime);
|
void animation(int elapsedTime);
|
||||||
|
std::ostream& print(std::ostream& os) const;
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const Camera& c) { return c.print(os); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user