Skip to content

Commit f022a53

Browse files
committed
cameraerrorrotation
1 parent 148d4e6 commit f022a53

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

src/Game.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,15 @@ void Game::render() {
6363

6464
glm::mat4x4 model(1.0f);
6565

66-
static float angle = 0.0f;
67-
model = glm::translate(model, glm::vec3(0.0f, 0.12f * glm::sin(glm::radians(angle) * 2.718f), 0.0f));
68-
model = glm::rotate(model, glm::radians(angle), glm::vec3(0.0f, 1.0f, 0.0f));
69-
model = glm::scale(model, glm::vec3(0.7f));
70-
angle += 0.5f;
71-
7266
glColor3f(0.9f, 0.6f, 0.1f);
7367

74-
CHECK_GL(glMatrixMode(GL_MODELVIEW));
75-
model = glm::translate(glm::mat4x4(1), glm::vec3(0.8f, 0, 0)) * model;
76-
CHECK_GL(glLoadMatrixf(glm::value_ptr(view * model)));
77-
m_private->monkey.draw_obj(true);
68+
/* CHECK_GL(glMatrixMode(GL_MODELVIEW)); */
69+
/* model = glm::translate(glm::mat4x4(1), glm::vec3(0.8f, 0, 0)) * model; */
70+
/* CHECK_GL(glLoadMatrixf(glm::value_ptr(view * model))); */
71+
/* m_private->monkey.draw_obj(true); */
7872

7973
CHECK_GL(glMatrixMode(GL_MODELVIEW));
80-
model = glm::translate(glm::mat4x4(1), -2.0f * glm::vec3(0.8f, 0, 0)) * model;
74+
/* model = glm::translate(glm::mat4x4(1), -2.0f * glm::vec3(0.8f, 0, 0)) * model; */
8175
CHECK_GL(glLoadMatrixf(glm::value_ptr(view * model)));
82-
m_private->monkey.draw_obj(false);
76+
m_private->monkey.draw_obj(true);
8377
}

src/InputCtl.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,6 @@ struct CameraState {
8585
// update eye and lookat coordinates
8686
eye = glm::vec3(transformation * glm::vec4(eye, 1));
8787
lookat = glm::vec3(transformation * glm::vec4(lookat, 1));
88-
89-
// try to keep the camera horizontal line correct (eval right axis error)
90-
float right_o_up = glm::dot(right_vector, keep_up_axis);
91-
float right_handness = glm::dot(glm::cross(keep_up_axis, right_vector), front_vector);
92-
float angle_Z_err = glm::asin(right_o_up);
93-
angle_Z_err *= glm::atan(right_handness);
94-
// rotation for up: cancel out the camera horizontal line drift
95-
glm::mat4x4 rotation_matrixZ = glm::rotate(glm::mat4x4(1), angle_Z_err, front_vector);
96-
up_vector = glm::mat3x3(rotation_matrixZ) * up_vector;
9788
}
9889

9990
void zoom(InputCtl::InputPreference const &pref, float delta, bool isHitchcock) {
@@ -180,14 +171,14 @@ void InputCtl::cursor_pos_callback(double xpos, double ypos) {
180171
}
181172
m_private->lastpos = pos;
182173

183-
if (m_inputPref.clamp_cursor && !m_private->curclamped && xpos >= width || ypos >= height || xpos <= 0 || ypos <= 0) {
174+
if (m_inputPref.clamp_cursor && !m_private->curclamped && (xpos >= width - 1 || ypos >= height - 1 || xpos <= 1 || ypos <= 1)) {
184175
// clamp mouse cursor inside the window (ZHI JING Blender)
185-
xpos = std::fmod(xpos + width, width);
186-
ypos = std::fmod(ypos + height, height);
176+
xpos = std::fmod(xpos + width - 3, width - 2) + 1;
177+
ypos = std::fmod(ypos + height - 3, height - 2) + 1;
187178
glfwSetCursorPos(m_private->window, xpos, ypos);
188-
m_private->curclamped = true;
179+
/* m_private->curclamped = true; */
189180
} else {
190-
m_private->curclamped = false;
181+
/* m_private->curclamped = false; */
191182
}
192183
}
193184

src/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ int main() {
8787
// Print diagnostic information
8888
std::cerr << "OpenGL version: " << (const char *)glGetString(GL_VERSION) << '\n';
8989

90+
// Enable V-Sync
91+
glfwSwapInterval(1);
92+
9093
// Create game instance
9194
auto &game = Game::get();
9295
game.set_window(window);

0 commit comments

Comments
 (0)