This commit is contained in:
Jasper 2014-11-17 13:36:35 +01:00
commit a77ed38625
16 changed files with 32 additions and 15 deletions

View File

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 166 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

Before

Width:  |  Height:  |  Size: 344 KiB

After

Width:  |  Height:  |  Size: 344 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View File

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -19,6 +19,7 @@ float Camera::getDistance() {
void Camera::setDistance(float distance) { void Camera::setDistance(float distance) {
this->distance = distance; this->distance = distance;
updatePosition();
} }
glm::vec2 Camera::getRotation() { glm::vec2 Camera::getRotation() {
@ -27,9 +28,11 @@ glm::vec2 Camera::getRotation() {
void Camera::setRotation(glm::vec2 rotation) { void Camera::setRotation(glm::vec2 rotation) {
this->rotation = rotation; this->rotation = rotation;
updatePosition();
} }
void Camera::updateRotation(glm::vec2 rotation) { void Camera::updateRotation(glm::vec2 rotation) {
this->rotation += rotation;
if((this->rotation.x + rotation.x) >= 1.57f) { if((this->rotation.x + rotation.x) >= 1.57f) {
this->rotation.x = 1.57; this->rotation.x = 1.57;
this->rotation.y += rotation.y; this->rotation.y += rotation.y;
@ -41,6 +44,7 @@ void Camera::updateRotation(glm::vec2 rotation) {
else { else {
this-> rotation += rotation; this-> rotation += rotation;
} }
updatePosition();
} }
void Camera:: updateDistance(float distance) { void Camera:: updateDistance(float distance) {
@ -53,4 +57,18 @@ void Camera:: updateDistance(float distance) {
else { else {
this->distance += distance; this->distance += distance;
} }
updatePosition();
} }
void Camera::updatePosition() {
glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, distance, 0.0f);
// rotate vector
glm::mat4 rotationMatrix =
glm::rotate<float>(rotation[1], glm::vec3(0.0f, 1.0f, 0.0f)) * glm::rotate<float>(rotation[0], glm::vec3(1.0f, 0.0f, 0.0f));
this->vector = glm::vec3(rotationMatrix * cameraVector);
}
glm::vec3 Camera::getVector() {
return vector;
}

View File

@ -14,9 +14,12 @@ class Camera {
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
glm::vec3 getVector();
private: private:
void updatePosition();
float distance; float distance;
glm::vec2 rotation; glm::vec2 rotation;
glm::vec3 vector;
}; };
#endif #endif

View File

@ -154,11 +154,7 @@ 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);
// 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));
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() + level->getCamera()->getVector()),
level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
} }

View File

@ -37,8 +37,8 @@ void Application::init()
// define where shaders and textures can be found: // define where shaders and textures can be found:
ACGL::Base::Settings::the()->setResourcePath("../"); ACGL::Base::Settings::the()->setResourcePath("../");
ACGL::Base::Settings::the()->setShaderPath("Shader/"); ACGL::Base::Settings::the()->setShaderPath("Shader/");
ACGL::Base::Settings::the()->setTexturePath("Geometry/"); ACGL::Base::Settings::the()->setTexturePath("Levels/Textures/");
ACGL::Base::Settings::the()->setGeometryPath("Geometry/"); ACGL::Base::Settings::the()->setGeometryPath("Levels/Geometry/");
// construct VAO to give shader correct Attribute locations // construct VAO to give shader correct Attribute locations
ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>(); ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>();

View File

@ -13,10 +13,10 @@ Terrain::~Terrain() {
void Terrain::load() { void Terrain::load() {
filePath = "../Levels/LevelTest/terrain/"; //TODO remove this, its only for testing filePath = "../Levels/heightmapLvlTest.png"; //TODO remove this, its only for testing
std::vector<unsigned char> image; //the raw pixels std::vector<unsigned char> image; //the raw pixels
unsigned error = lodepng::decode(image, heightmapWidth, heightmapHeight, filePath + "heightmap.png"); unsigned error = lodepng::decode(image, heightmapWidth, heightmapHeight, filePath);
if (error) { if (error) {
std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl;
} }
@ -41,7 +41,7 @@ void Terrain::makeTriangleMesh(){
ab->defineAttribute("aTexCoord", GL_FLOAT, 2); ab->defineAttribute("aTexCoord", GL_FLOAT, 2);
ab->defineAttribute("aNormal", GL_FLOAT, 3); ab->defineAttribute("aNormal", GL_FLOAT, 3);
unsigned int rowNum=0, columnNum=0, dataCount=0, abNumFloats=8; //initializing: unsigned int rowNum=0, columnNum=0, dataCount=0, floatsPerVertex=8; //initializing:
bool movingRight = true, isUp = true; bool movingRight = true, isUp = true;
int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1; int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1;
float* abData = new float[numVertices * floatsPerVertex]; float* abData = new float[numVertices * floatsPerVertex];
@ -56,9 +56,9 @@ void Terrain::makeTriangleMesh(){
else if (movingRight) { else if (movingRight) {
if (columnNum == this->heightmapWidth - 1) { if (columnNum == this->heightmapWidth - 1) {
set_abData(abData, dataCount, rowNum, columnNum); set_abData(abData, dataCount, rowNum, columnNum);
dataCount += abNumFloats; dataCount += floatsPerVertex;
set_abData(abData, dataCount, rowNum, columnNum); set_abData(abData, dataCount, rowNum, columnNum);
dataCount += abNumFloats; dataCount += floatsPerVertex;
movingRight = false; movingRight = false;
rowNum = rowNum + 1; rowNum = rowNum + 1;
} }
@ -71,9 +71,9 @@ void Terrain::makeTriangleMesh(){
else { else {
if (columnNum == 0){ if (columnNum == 0){
set_abData(abData, dataCount, rowNum, columnNum); set_abData(abData, dataCount, rowNum, columnNum);
dataCount += abNumFloats; dataCount += floatsPerVertex;
set_abData(abData, dataCount, rowNum, columnNum); set_abData(abData, dataCount, rowNum, columnNum);
dataCount += abNumFloats; dataCount += floatsPerVertex;
movingRight = true; movingRight = true;
rowNum = rowNum + 1; rowNum = rowNum + 1;
} }