Made mouse control camera. (Stupid init of camera...)

This commit is contained in:
Fabian Klemp 2014-11-14 18:33:42 +01:00
parent 93363d1391
commit 04234b1f1c
4 changed files with 16 additions and 6 deletions

View File

@ -20,6 +20,10 @@ GLFWwindow* Graphics::getWindow() {
return window;
}
glm::uvec2 Graphics::getWindowSize() {
return windowSize;
}
void Graphics::setGLFWHintsForOpenGLVersion( unsigned int _version )
{
#ifdef __APPLE__
@ -159,8 +163,8 @@ glm::mat4 Graphics::buildFrustum( float phiInDegree, float _near, float _far, fl
glm::mat4 Graphics::buildViewMatrix(Level* level) {
glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, level->getCamera().getDistance(), 0.0f);
// rotate vector
glm::mat4 rotationMatrix = glm::rotate<float>(level->getCamera().getRotation()[0], glm::vec3(1.0f, 0.0f, 0.0f)) *
glm::rotate<float>(level->getCamera().getRotation()[1], glm::vec3(0.0f, 1.0f, 0.0f)) * glm::rotate<float>(level->getCamera().getRotation()[2], glm::vec3(0.0f, 0.0f, 1.0f));
glm::mat4 rotationMatrix =
glm::rotate<float>(level->getCamera().getRotation()[1], glm::vec3(0.0f, 1.0f, 0.0f)) *glm::rotate<float>(level->getCamera().getRotation()[0], glm::vec3(1.0f, 0.0f, 0.0f));
cameraVector = rotationMatrix * cameraVector;
//construct lookAt (cameraPosition = cameraCenter + cameraVector
return glm::lookAt(level->getCameraCenter()->getPosition() + glm::vec3(cameraVector), level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));

View File

@ -41,9 +41,10 @@ void Level::render() {
this->terrain.render();
}
void Level::update(float runTime) {
void Level::update(float runTime, glm::vec2 mouseDelta) {
// rotate bunny
cameraCenter->setRotation(glm::vec3(0.0f, 1.0472f * runTime, 0.0f));
//cameraCenter->setRotation(glm::vec3(0.0f, 1.0472f * runTime, 0.0f));
camera.updateRotation(mouseDelta/50.0f);
}
glm::vec3 Level::getAmbientLight() {

View File

@ -15,7 +15,7 @@ class Level {
Level();
~Level();
void load(ACGL::OpenGL::SharedShaderProgram shader); // Shader is necessary for correct texture assigning
void update(float runTime);
void update(float runTime, glm::vec2 mouseDelta);
void render();
glm::vec3 getAmbientLight();
std::vector<Light> getLights();

View File

@ -126,7 +126,12 @@ int main( int argc, char *argv[] )
frameCount = 0;
}
app.getLevel()->update(now - startTimeInSeconds);
double xpos, ypos;
glfwGetCursorPos(app.getGraphics()->getWindow(), &xpos, &ypos);
glfwSetCursorPos(app.getGraphics()->getWindow(), app.getGraphics()->getWindowSize().x/2, app.getGraphics()->getWindowSize().y/2);
app.getLevel()->update(now - startTimeInSeconds, glm::vec2((float)ypos-app.getGraphics()->getWindowSize().y/2,
(float)xpos-app.getGraphics()->getWindowSize().x/2));
app.getGraphics()->render(app.getLevel(), app.getShader());
openGLCriticalError();