/** * Call this function whenever the mouse moves while rotating the model. */ void Camera::rotate(int mouse_x, int mouse_y, float senstivity) { xrot += (mouse_y - mouse_pos.y) * senstivity; yrot += (mouse_x - mouse_pos.x) * senstivity; updateMVPMatrix(); mouse_pos = glm::vec2(mouse_x, mouse_y); }
/** * Call this function whenever the mouse moves while moving the model. */ void Camera::move(int mouse_x, int mouse_y) { pos.x -= (mouse_x - mouse_pos.x) * 0.1; pos.y += (mouse_y - mouse_pos.y) * 0.1; updateMVPMatrix(); mouse_pos = glm::vec2(mouse_x, mouse_y); }
/** * Call this function whenever the mouse moves while rotating the model. */ void Camera::rotate(int mouse_x, int mouse_y) { xrot += mouse_y - mouse_pos.y; yrot += mouse_x - mouse_pos.x; updateMVPMatrix(); mouse_pos = glm::vec2(mouse_x, mouse_y); }
void Camera::resetCamera() { xrot = 20.0f; yrot = -45.0f; zrot = 0.0f; pos = glm::vec3(0, 0, 170); updateMVPMatrix(); }
void Camera::loadCameraPose(char* filename) { std::ifstream ifs(filename); if (ifs.fail()) { std::cout << "Can't open file: " << filename << std::endl; } else { ifs >> xrot >> yrot >> zrot >> pos.x >> pos.y >> pos.z; updateMVPMatrix(); } }
void GLDrawUI::Common::setUp(SetUpPhase phase) { switch (phase) { case SetUpPhase::CompileLinkProgram: compileLinkProgram(); /* FALL THROUGH */ case SetUpPhase::UseProgram: useProgram(); /* FALL THROUGH */ case SetUpPhase::UpdateMVPMatrix: updateMVPMatrix(); /* FALL THROUGH */ default: break; } }
/** * Update perspective projection matrix, and then, update the model view projection matrix. */ void Camera::updatePMatrix(int width,int height) { _aspect = (float)width / (float)height; float zfar = 3000.0f; float znear = 0.1f; // projection行列 // ただし、mat4はcolumn majorなので、転置した感じで初期構築する。 // つまり、下記の一行目は、mat4の一列目に格納されるのだ。 pMatrix = glm::mat4( _f/_aspect, 0, 0, 0, 0, _f, 0, 0, 0, 0, (zfar+znear)/(znear-zfar), -1, 0, 0, (2.0f*zfar*znear)/(znear-zfar), 0); updateMVPMatrix(); }
/** * Update perspective projection matrix, and then, update the model view projection matrix. */ void Camera::updatePMatrix(int width,int height) { float aspect = (float)width / (float)height; float zfar = 1000.0f; float znear = 10.0f; float f = 1.0f / tan(fovy * M_PI / 360.0f); // projection行列 // ただし、mat4はcolumn majorなので、転置した感じで初期構築する。 // つまり、下記の一行目は、mat4の一列目に格納されるのだ。 pMatrix = glm::mat4( f/aspect, 0, 0, 0, 0, f, 0, 0, -center.x, -center.y, (zfar+znear)/(znear-zfar), -1, 0, 0, (2.0f*zfar*znear)/(znear-zfar), 0); updateMVPMatrix(); }
/** * Call this function whenever the mouse moves while zooming. */ void Camera::zoom(int mouse_x, int mouse_y) { pos.z += (mouse_pos.y - mouse_y) * 0.5f; updateMVPMatrix(); mouse_pos = glm::vec2(mouse_x, mouse_y); }
/** * Call this function whenever the mouse moves while zooming. */ void Camera::zoom(float delta) { pos.z -= delta; updateMVPMatrix(); }