Skip to content
Snippets Groups Projects
Commit 105fefba authored by Martin Štourač's avatar Martin Štourač
Browse files

frame methods added

parent ed7c85a0
No related branches found
No related tags found
No related merge requests found
......@@ -13,20 +13,25 @@
class Controller
{
protected:
//zrusit, pouzivat frame, camera tez
glm::vec3 frontVec = glm::vec3(0.0f, 0.0f, -1.0f);
glm::vec3 upVec = glm::vec3(0.0f, 1.0f, 0.0f);
float speed = 2.5f;
float step = 0;
//shared ptr
Frame &bound_frame;
public:
Controller(Frame &frame)
: bound_frame{frame} {}
glm::vec3 getFrontVec() { return frontVec; }
glm::vec3 getUpVec() { return upVec; }
// glm::vec3 getFrontVec() { return frontVec; }
// glm::vec3 getUpVec() { return upVec; }
virtual glm::vec3 getFrontVec() { return frontVec; }
virtual glm::vec3 getUpVec() { return upVec; }
virtual void setFrontVec() = 0;
//void setUpVec(); TO DO
......
......@@ -20,13 +20,21 @@ public:
{
setRotationQuat(rotation);
}
glm::vec3 getPosition() { return positionVec; }
glm::quat getRotation() { return rotationQuat; }
glm::mat4 getModelMat() { return glm::translate(glm::mat4(1.0f), positionVec); }
glm::mat4 getViewMat() { return glm::inverse(getModelMat()); }
// Normalize?
glm::vec3 getRotationAxisX() { return glm::vec3(glm::axis(rotationQuat).x, 0, 0); }
glm::vec3 getRotationAxisY() { return glm::vec3(0, glm::axis(rotationQuat).y, 0); }
glm::vec3 getRotationAxisZ() { return glm::vec3(0, 0, glm::axis(rotationQuat).z); }
glm::mat4 getTranslationMat() { return glm::translate(glm::mat4(1.0f), positionVec); }
glm::mat4 getRotationMat() { return glm::toMat4(rotationQuat); }
glm::mat4 getModelMat() { return getTranslationMat() * getRotationMat(); }
glm::mat4 getViewMat() { return glm::inverse(getModelMat()); }
void setPosVec(glm::vec3 new_position) { positionVec = new_position; }
void translatePosVec(glm::vec3 direction) { positionVec += direction; }
void setRotationQuat(glm::vec3 new_rotation) { rotationQuat = glm::tquat(glm::radians(new_rotation)); }
......
......@@ -11,10 +11,12 @@
class Object
{
// vectory do bufferu
std::vector<float> vertices;
std::vector<unsigned int> indices;
std::vector<float> normals;
//shared ptr, VBO do VAO
VAO _VAO;
VBO _VBO_vertex;
VBO _VBO_normal;
......
......@@ -27,27 +27,27 @@ void Controller::move(const std::unordered_set<std::string> &pressed_keys)
void Controller::forward()
{
bound_frame.translatePosVec(step * frontVec);
bound_frame.translatePosVec(step * getFrontVec());
}
void Controller::backward()
{
bound_frame.translatePosVec(-step * frontVec);
bound_frame.translatePosVec(-step * getFrontVec());
}
void Controller::left()
{
bound_frame.translatePosVec(-step * glm::normalize(glm::cross(frontVec, upVec)));
bound_frame.translatePosVec(-step * glm::normalize(glm::cross(getFrontVec(), getUpVec())));
}
void Controller::right()
{
bound_frame.translatePosVec(step * glm::normalize(glm::cross(frontVec, upVec)));
bound_frame.translatePosVec(step * glm::normalize(glm::cross(getFrontVec(), getUpVec())));
}
void Controller::up()
{
bound_frame.translatePosVec(step * upVec);
bound_frame.translatePosVec(step * getUpVec());
}
void Controller::down()
{
bound_frame.translatePosVec(-step * upVec);
bound_frame.translatePosVec(-step * getUpVec());
}
void Controller::rotate(glm::vec3 rotational_difference)
......
......@@ -2,5 +2,5 @@
void ObjectController::setFrontVec() // temporary implementation
{
frontVec = glm::vec3(0.0f, 0.0f, -1.0f);
//frontVec = glm::vec3(0.0f, 0.0f, -1.0f);
}
\ No newline at end of file
......@@ -102,7 +102,7 @@ void gfx_draw(Shader &myShader,
/* ---------------------------------------------------------------- */
// DRAW CUBE
glm::mat4 model = obj_frame.getModelMat() * obj_frame.getRotationMat();
glm::mat4 model = obj_frame.getModelMat();
glm::mat4 view;
view = glm::lookAt(cam_frame.getPosition(), cam_frame.getPosition() + cam_control.getFrontVec(), cam_control.getUpVec());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment