Merge branch 'master' of https://github.com/Faerbit/swp
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 166 KiB |
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 344 KiB After Width: | Height: | Size: 344 KiB |
BIN
Levels/Textures/torchTexture.png
Normal file
After Width: | Height: | Size: 100 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
18
camera.cc
@ -19,6 +19,7 @@ float Camera::getDistance() {
|
||||
|
||||
void Camera::setDistance(float distance) {
|
||||
this->distance = distance;
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
glm::vec2 Camera::getRotation() {
|
||||
@ -27,9 +28,11 @@ glm::vec2 Camera::getRotation() {
|
||||
|
||||
void Camera::setRotation(glm::vec2 rotation) {
|
||||
this->rotation = rotation;
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Camera::updateRotation(glm::vec2 rotation) {
|
||||
this->rotation += rotation;
|
||||
if((this->rotation.x + rotation.x) >= 1.57f) {
|
||||
this->rotation.x = 1.57;
|
||||
this->rotation.y += rotation.y;
|
||||
@ -41,6 +44,7 @@ void Camera::updateRotation(glm::vec2 rotation) {
|
||||
else {
|
||||
this-> rotation += rotation;
|
||||
}
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Camera:: updateDistance(float distance) {
|
||||
@ -53,4 +57,18 @@ void Camera:: updateDistance(float distance) {
|
||||
else {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,12 @@ class Camera {
|
||||
glm::vec2 getRotation();
|
||||
void setRotation(glm::vec2 rotation);
|
||||
void updateRotation(glm::vec2 rotation); //adds to current rotation
|
||||
glm::vec3 getVector();
|
||||
private:
|
||||
void updatePosition();
|
||||
float distance;
|
||||
glm::vec2 rotation;
|
||||
glm::vec3 vector;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -154,11 +154,7 @@ 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()[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));
|
||||
return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()),
|
||||
level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
}
|
||||
|
4
main.cc
@ -37,8 +37,8 @@ void Application::init()
|
||||
// define where shaders and textures can be found:
|
||||
ACGL::Base::Settings::the()->setResourcePath("../");
|
||||
ACGL::Base::Settings::the()->setShaderPath("Shader/");
|
||||
ACGL::Base::Settings::the()->setTexturePath("Geometry/");
|
||||
ACGL::Base::Settings::the()->setGeometryPath("Geometry/");
|
||||
ACGL::Base::Settings::the()->setTexturePath("Levels/Textures/");
|
||||
ACGL::Base::Settings::the()->setGeometryPath("Levels/Geometry/");
|
||||
|
||||
// construct VAO to give shader correct Attribute locations
|
||||
ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>();
|
||||
|
14
terrain.cc
@ -13,10 +13,10 @@ Terrain::~Terrain() {
|
||||
|
||||
|
||||
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
|
||||
unsigned error = lodepng::decode(image, heightmapWidth, heightmapHeight, filePath + "heightmap.png");
|
||||
unsigned error = lodepng::decode(image, heightmapWidth, heightmapHeight, filePath);
|
||||
if (error) {
|
||||
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("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;
|
||||
int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1;
|
||||
float* abData = new float[numVertices * floatsPerVertex];
|
||||
@ -56,9 +56,9 @@ void Terrain::makeTriangleMesh(){
|
||||
else if (movingRight) {
|
||||
if (columnNum == this->heightmapWidth - 1) {
|
||||
set_abData(abData, dataCount, rowNum, columnNum);
|
||||
dataCount += abNumFloats;
|
||||
dataCount += floatsPerVertex;
|
||||
set_abData(abData, dataCount, rowNum, columnNum);
|
||||
dataCount += abNumFloats;
|
||||
dataCount += floatsPerVertex;
|
||||
movingRight = false;
|
||||
rowNum = rowNum + 1;
|
||||
}
|
||||
@ -71,9 +71,9 @@ void Terrain::makeTriangleMesh(){
|
||||
else {
|
||||
if (columnNum == 0){
|
||||
set_abData(abData, dataCount, rowNum, columnNum);
|
||||
dataCount += abNumFloats;
|
||||
dataCount += floatsPerVertex;
|
||||
set_abData(abData, dataCount, rowNum, columnNum);
|
||||
dataCount += abNumFloats;
|
||||
dataCount += floatsPerVertex;
|
||||
movingRight = true;
|
||||
rowNum = rowNum + 1;
|
||||
}
|
||||
|