Merge branch 'master' of github.com:Faerbit/swp
This commit is contained in:
commit
51359d065f
2069
Geometry/Sphere.obj
Normal file
2069
Geometry/Sphere.obj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
Geometry/stoneTexture.png
Normal file
BIN
Geometry/stoneTexture.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
12
camera.cc
12
camera.cc
@ -42,3 +42,15 @@ void Camera::updateRotation(glm::vec2 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;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ class Camera {
|
||||
~Camera();
|
||||
float getDistance();
|
||||
void setDistance(float distance);
|
||||
void updateDistance(float distance); //adds to current distance
|
||||
glm::vec2 getRotation();
|
||||
void setRotation(glm::vec2 rotation);
|
||||
void updateRotation(glm::vec2 rotation); //adds to current rotation
|
||||
|
13
graphics.cc
13
graphics.cc
@ -68,7 +68,7 @@ bool Graphics::createWindow()
|
||||
glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, true );
|
||||
|
||||
// define whether the window can get resized:
|
||||
glfwWindowHint(GLFW_RESIZABLE, false);
|
||||
glfwWindowHint(GLFW_RESIZABLE, true);
|
||||
|
||||
// non-decorated windows can be used as splash screens:
|
||||
//glfwWindowHint( GLFW_DECORATED, false );
|
||||
@ -142,13 +142,6 @@ void Graphics::setWindowSize(glm::uvec2 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) {
|
||||
|
||||
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::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
|
||||
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;
|
||||
//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));
|
||||
|
@ -11,8 +11,6 @@ class Graphics {
|
||||
Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane);
|
||||
Graphics();
|
||||
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:
|
||||
glm::mat4 buildFrustum( float phiInDegree, float near, float far, float aspectRatio);
|
||||
glm::mat4 buildViewMatrix(Level* level);
|
||||
@ -28,6 +26,4 @@ class Graphics {
|
||||
GLFWwindow* window;
|
||||
};
|
||||
|
||||
void resizeCallback(Graphics* graphics, int newWidth, int newHeight);
|
||||
|
||||
#endif
|
||||
|
10
level.cc
10
level.cc
@ -15,11 +15,11 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||
// currently hard coded should later read this stuff out of a file
|
||||
this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f);
|
||||
// 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:
|
||||
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
|
||||
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, 0.0f, 0.0f), shader);
|
||||
|
||||
@ -75,8 +75,8 @@ std::vector<Light> Level::getLights() {
|
||||
return lights;
|
||||
}
|
||||
|
||||
Camera Level::getCamera() {
|
||||
return camera;
|
||||
Camera* Level::getCamera() {
|
||||
return &camera;
|
||||
}
|
||||
|
||||
Object* Level::getCameraCenter() {
|
||||
|
2
level.hh
2
level.hh
@ -20,7 +20,7 @@ class Level {
|
||||
glm::vec3 getAmbientLight();
|
||||
std::vector<Light> getLights();
|
||||
Object* getCameraCenter();
|
||||
Camera getCamera();
|
||||
Camera* getCamera();
|
||||
private:
|
||||
std::string filePath;
|
||||
std::vector<Object> objects;
|
||||
|
16
main.cc
16
main.cc
@ -60,6 +60,13 @@ void Application::init()
|
||||
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)
|
||||
{
|
||||
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[] )
|
||||
{
|
||||
Application app = Application();
|
||||
//Application app = Application();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Create OpenGL capable window:
|
||||
@ -89,8 +100,9 @@ int main( int argc, char *argv[] )
|
||||
glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_STICKY_KEYS, 1);
|
||||
// Hide mouse cursor
|
||||
glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
//glfwSetWindowSizeCallback(app.getGraphics(), resizeCallback);
|
||||
glfwSetWindowSizeCallback(app.getGraphics()->getWindow(), resizeCallback);
|
||||
glfwSetKeyCallback(app.getGraphics()->getWindow(), keyCallback );
|
||||
glfwSetScrollCallback(app.getGraphics()->getWindow(), scrollCallback );
|
||||
|
||||
// Enable vertical sync (on cards that support it) with parameter 1 - 0 means off
|
||||
glfwSwapInterval( 0 );
|
||||
|
Loading…
Reference in New Issue
Block a user