glut - Camera Translation in OpenGL -


i trying class walk through world in opengl, having problems mathematics. idea here use function lookat glm set observer in position wanted, , operate points pass function. think functions rotations made correct, translation part in walk method seems wrong, , when try walk in world if translate, or rotated, things go right, when both things messed.

here class far:

#ifndef observer_h #define observer_h  #include <gl/gl.h> #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp>  class observer {  private:      glm::vec3 eye, center, upp;  public:      glm::mat4 view;      observer() {}     ~observer() {}          void initialize(glm::vec3 eye, glm::vec3 center, glm::vec3 upp);     void walk(glfloat distance);     void pitch(glfloat pitch);     void yaw(glfloat yaw);     void roll(glfloat roll);     void setview(); };  void observer::initialize(glm::vec3 eye, glm::vec3 center, glm::vec3 upp)  {     this->eye = eye;     this->center = center;     this->upp = upp; }  void observer::walk(glfloat distance)  {     glm::vec3 vector = glm::normalize(center - eye);     glm::vec3 translate = vector*distance - vector;      eye += translate;     center += translate;     upp += translate; }  void observer::roll(glfloat roll) {     glm::mat4 rotate(1.0f);      rotate = glm::rotate(rotate, roll, glm::vec3(center - eye));      center = glm::vec3(rotate * glm::vec4(center, 1.0f));     upp = glm::vec3(rotate * glm::vec4(upp, 1.0f)); }  void observer::yaw(glfloat yaw) {     glm::mat4 rotate(1.0f);      rotate = glm::rotate(rotate, yaw, glm::vec3(upp - eye));      center = glm::vec3(rotate * glm::vec4(center, 1.0f));     upp = glm::vec3(rotate * glm::vec4(upp, 1.0f)); }  void observer::pitch(glfloat pitch) {     glm::mat4 rotate(1.0f);     glm::vec3 cross = glm::cross(center - eye, upp - eye);      rotate = glm::rotate(rotate, pitch, cross);      center = glm::vec3(rotate * glm::vec4(center, 1.0f));     upp = glm::vec3(rotate * glm::vec4(upp, 1.0f)); }  void observer::setview()  {     view = glm::lookat(eye, center, upp); }  #endif 

so right before starting draw things set view matrix class in other part in program. can tell me if maths right?

when walk, want transform eye , center position, not upp vector. remove upp += translate; line.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -