Skip to content

Commit

Permalink
implemented parsing of camera parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Cbeed committed Aug 28, 2014
1 parent 0466218 commit 02d085f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
24 changes: 20 additions & 4 deletions framework/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,32 @@
*/

#include "Camera.hpp"
#define GLM_FORCE_RADIANS
#include "glm/detail/type_vec.hpp"
#include "glm/gtc/matrix_transform.hpp"

Camera::Camera():
name("unnamed"),
fovX(100),
transformation(glm::mat4x4())
transformation(glm::mat4x4()),
transformation_inv(glm::mat4x4())
{}

Camera::Camera(const std::string name, const int fovX):
Camera::Camera(std::string const& name, const int fovX):
name(name),
fovX(fovX),
transformation(glm::mat4x4())
{}
transformation(glm::mat4x4()),
transformation_inv(glm::mat4x4())
{}

void Camera::translate(glm::vec3 const& transl) {
auto m = glm::translate(glm::mat4(), transl);
transformation = m * transformation;
transformation_inv = transformation_inv * m;
}

void Camera::rotate(float angle, glm::vec3 const& axis) {
auto m = glm::rotate(glm::mat4(), angle, axis);
transformation = m * transformation;
transformation_inv = transformation_inv * m;
}
6 changes: 5 additions & 1 deletion framework/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@
class Camera {
public:
Camera();
Camera(std::string const name, int const fovX);
Camera(std::string const& name, int const fovX);
int GetFovX() const {
return fovX;
}

glm::mat4 GetTransformation() const {
return transformation;
}

void translate(glm::vec3 const& transl);
void rotate(float angle, glm::vec3 const& axis);

private:
std::string name;
int fovX;
glm::mat4 transformation;
glm::mat4 transformation_inv;
};

#endif /* CAMERA_HPP */
Expand Down
37 changes: 37 additions & 0 deletions framework/SDFLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,43 @@ Scene SDFLoader::load(std::string const& scenefile) {
int fovX;
ss >> fovX;
scene.camera = Camera(cameraname,fovX);

if (!ss.eof()){
glm::vec3 pos;
ss >> pos.x;
ss >> pos.y;
ss >> pos.z;
scene.camera.translate(pos);

//direction
if (!ss.eof()){
glm::vec3 dir;
ss >> dir.x;
ss >> dir.y;
ss >> dir.z;
auto regularDir = glm::vec3(0.0f,0.0f,-1.0f);
//angle between 0,0,-1 and dir
float angleXY =glm::dot(regularDir,dir)/(glm::length(regularDir)*glm::length(dir));
//rotate around y and x
scene.camera.rotate(angleXY,glm::vec3(1,1,0));

//up vector
if (!ss.eof()){
glm::vec3 up;
ss >> up.x;
ss >> up.y;
ss >> up.z;
auto regularUp = glm::vec3(0.0f,1.0f,0.0f);
//angle between 0,1,0 and up
float angleZ =glm::dot(regularUp,up)/(glm::length(regularUp)*glm::length(up));
//rotate around z
scene.camera.rotate(angleZ,glm::vec3(0,0,1));
}
}
}



cout << "camera: "<<cameraname<<"("<<fovX<<")"<<endl;
} else if (firstWord=="light"){
string type;
Expand Down

0 comments on commit 02d085f

Please sign in to comment.