Merge branch 'master' of github.com:Faerbit/swp

This commit is contained in:
Steffen Fündgens 2014-11-17 11:25:49 +01:00
commit 51359d065f
10 changed files with 2106 additions and 22 deletions

2069
Geometry/Sphere.obj Normal file

File diff suppressed because it is too large Load Diff

BIN
Geometry/stoneTexture.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@ -42,3 +42,15 @@ void Camera::updateRotation(glm::vec2 rotation) {
this-> rotation += rotation; this-> rotation += rotation;
} }
} }
void Camera:: updateDistance(float distance) {
if (this->distance + distance <= 1.0f) {
this->distance = 1.0f;
}
else if (this->distance + distance >= 30.0f) {
this->distance = 30.f;
}
else {
this->distance += distance;
}
}

View File

@ -10,6 +10,7 @@ class Camera {
~Camera(); ~Camera();
float getDistance(); float getDistance();
void setDistance(float distance); void setDistance(float distance);
void updateDistance(float distance); //adds to current distance
glm::vec2 getRotation(); glm::vec2 getRotation();
void setRotation(glm::vec2 rotation); void setRotation(glm::vec2 rotation);
void updateRotation(glm::vec2 rotation); //adds to current rotation void updateRotation(glm::vec2 rotation); //adds to current rotation

View File

@ -68,7 +68,7 @@ bool Graphics::createWindow()
glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, true ); glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, true );
// define whether the window can get resized: // define whether the window can get resized:
glfwWindowHint(GLFW_RESIZABLE, false); glfwWindowHint(GLFW_RESIZABLE, true);
// non-decorated windows can be used as splash screens: // non-decorated windows can be used as splash screens:
//glfwWindowHint( GLFW_DECORATED, false ); //glfwWindowHint( GLFW_DECORATED, false );
@ -142,13 +142,6 @@ void Graphics::setWindowSize(glm::uvec2 windowSize) {
this->windowSize = windowSize; this->windowSize = windowSize;
} }
void resizeCallback(Graphics* graphics, int newWidth, int newHeight)
{
// store the new window size and adjust the viewport:
graphics->setWindowSize(glm::uvec2( newWidth, newHeight));
glViewport( 0, 0, newWidth, newHeight);
}
glm::mat4 Graphics::buildFrustum( float phiInDegree, float _near, float _far, float aspectRatio) { glm::mat4 Graphics::buildFrustum( float phiInDegree, float _near, float _far, float aspectRatio) {
float phiHalfInRadians = 0.5*phiInDegree * (M_PI/180.0); float phiHalfInRadians = 0.5*phiInDegree * (M_PI/180.0);
@ -161,10 +154,10 @@ glm::mat4 Graphics::buildFrustum( float phiInDegree, float _near, float _far, fl
} }
glm::mat4 Graphics::buildViewMatrix(Level* level) { glm::mat4 Graphics::buildViewMatrix(Level* level) {
glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, level->getCamera().getDistance(), 0.0f); glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, level->getCamera()->getDistance(), 0.0f);
// rotate vector // rotate vector
glm::mat4 rotationMatrix = 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)); 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; cameraVector = rotationMatrix * cameraVector;
//construct lookAt (cameraPosition = cameraCenter + 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)); return glm::lookAt(level->getCameraCenter()->getPosition() + glm::vec3(cameraVector), level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));

View File

@ -11,8 +11,6 @@ class Graphics {
Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane); Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane);
Graphics(); Graphics();
void render(Level* level, ACGL::OpenGL::SharedShaderProgram shader); void render(Level* level, ACGL::OpenGL::SharedShaderProgram shader);
// gets called at window resize:
void resizeCallback( GLFWwindow *, int newWidth, int newHeight );
// to build the projection matrix: // to build the projection matrix:
glm::mat4 buildFrustum( float phiInDegree, float near, float far, float aspectRatio); glm::mat4 buildFrustum( float phiInDegree, float near, float far, float aspectRatio);
glm::mat4 buildViewMatrix(Level* level); glm::mat4 buildViewMatrix(Level* level);
@ -28,6 +26,4 @@ class Graphics {
GLFWwindow* window; GLFWwindow* window;
}; };
void resizeCallback(Graphics* graphics, int newWidth, int newHeight);
#endif #endif

View File

@ -15,11 +15,11 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
// currently hard coded should later read this stuff out of a file // currently hard coded should later read this stuff out of a file
this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f); this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f);
// load the geometry of the stanford bunny and build a VAO: // load the geometry of the stanford bunny and build a VAO:
Model model = Model("Bunny.obj", 0.25f); Model model = Model("Sphere.obj", 0.75f);
// load a texture: // load a texture:
Material material = Material("clownfishBunny.png", 0.1f, 0.5f, 0.5f, 3.0f); Material material = Material("stoneTexture.png", 0.1f, 0.5f, 0.5f, 3.0f);
//Create object //Create object
Object object = Object(model, material, glm::vec3(0.0f, 0.0f, -2.0f), Object object = Object(model, material, glm::vec3(0.0f, 1.0f, -2.0f),
glm::vec3(0.0f, 1.0472f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0472f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 0.0f), shader); glm::vec3(0.0f, 0.0f, 0.0f), shader);
@ -75,8 +75,8 @@ std::vector<Light> Level::getLights() {
return lights; return lights;
} }
Camera Level::getCamera() { Camera* Level::getCamera() {
return camera; return &camera;
} }
Object* Level::getCameraCenter() { Object* Level::getCameraCenter() {

View File

@ -20,7 +20,7 @@ class Level {
glm::vec3 getAmbientLight(); glm::vec3 getAmbientLight();
std::vector<Light> getLights(); std::vector<Light> getLights();
Object* getCameraCenter(); Object* getCameraCenter();
Camera getCamera(); Camera* getCamera();
private: private:
std::string filePath; std::string filePath;
std::vector<Object> objects; std::vector<Object> objects;

16
main.cc
View File

@ -60,6 +60,13 @@ void Application::init()
openGLCriticalError(); openGLCriticalError();
} }
void resizeCallback(GLFWwindow* window, int newWidth, int newHeight)
{
// store the new window size and adjust the viewport:
app.getGraphics()->setWindowSize(glm::uvec2( newWidth, newHeight));
glViewport( 0, 0, newWidth, newHeight);
}
static void keyCallback(GLFWwindow* _window, int _key, int, int _action, int) static void keyCallback(GLFWwindow* _window, int _key, int, int _action, int)
{ {
if (_key == GLFW_KEY_ESCAPE && _action == GLFW_PRESS) { if (_key == GLFW_KEY_ESCAPE && _action == GLFW_PRESS) {
@ -67,10 +74,14 @@ static void keyCallback(GLFWwindow* _window, int _key, int, int _action, int)
} }
} }
static void scrollCallback(GLFWwindow* window, double xoffset, double yoffset) {
app.getLevel()->getCamera()->updateDistance(-(float)yoffset);
}
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
Application app = Application(); //Application app = Application();
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// Create OpenGL capable window: // Create OpenGL capable window:
@ -89,8 +100,9 @@ int main( int argc, char *argv[] )
glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_STICKY_KEYS, 1); glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_STICKY_KEYS, 1);
// Hide mouse cursor // Hide mouse cursor
glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
//glfwSetWindowSizeCallback(app.getGraphics(), resizeCallback); glfwSetWindowSizeCallback(app.getGraphics()->getWindow(), resizeCallback);
glfwSetKeyCallback(app.getGraphics()->getWindow(), keyCallback ); glfwSetKeyCallback(app.getGraphics()->getWindow(), keyCallback );
glfwSetScrollCallback(app.getGraphics()->getWindow(), scrollCallback );
// Enable vertical sync (on cards that support it) with parameter 1 - 0 means off // Enable vertical sync (on cards that support it) with parameter 1 - 0 means off
glfwSwapInterval( 0 ); glfwSwapInterval( 0 );

View File

@ -25,4 +25,5 @@ class Application {
ACGL::OpenGL::SharedShaderProgram shader; ACGL::OpenGL::SharedShaderProgram shader;
}; };
Application app;
#endif #endif