@@ -54,6 +54,7 @@ const float SIMULATION_DELTA = 1.0f / SIMULATION_FREQ;
5454float simSpeeds[] =
5555{
5656 0 .0f ,
57+ 0 .03f / SIMULATION_FREQ,
5758 0 .1f / SIMULATION_FREQ,
5859 1 .0f / SIMULATION_FREQ,
5960 5 .0f / SIMULATION_FREQ,
@@ -62,7 +63,6 @@ float simSpeeds[] =
6263 200 .0f / SIMULATION_FREQ,
6364 400 .0f / SIMULATION_FREQ,
6465 800 .0f / SIMULATION_FREQ,
65- 1200 .0f / SIMULATION_FREQ,
6666};
6767double simulationTime;
6868float simulationTick = simSpeeds[2 ];
@@ -153,13 +153,15 @@ void OnKeyPressedCallback(GLFWwindow* window, int key, int scancode, int action,
153153
154154/* *
155155 * Called when the cursor position changed. Triggers also on hidden cursors!
156- * The function updates the camera based on the cursor movement
156+ * The function updates the camera based on the cursor movement.
157157 */
158158void OnCursorPosChangedCallback (GLFWwindow* window, double x, double y)
159159{
160- // This variable is hack to stop glfwSetCursorPos from triggering an event callback to Mouse(...)
161- // This avoids it being called recursively and hanging up the event loop
162- static bool just_warped = false ;
160+ // This variable is a hack to prevent the initial camera jump when the cursor isn't caught yet
161+ static bool caught_cursor = false ;
162+ // This variable is a hack to stop glfwSetCursorPos from triggering OnCursorPosChangedCallback() recursively.
163+ // Maybe using GLFW_CURSOR_DISABLED is the correct approach?
164+ static bool just_warped = false ;
163165
164166 if (just_warped) {
165167 just_warped = false ;
@@ -170,17 +172,18 @@ void OnCursorPosChangedCallback(GLFWwindow* window, double x, double y)
170172 int dx = (int )x - windowWidth / 2 ;
171173 int dy = (int )y - windowHeight / 2 ;
172174
173- if (dx ) {
175+ if (caught_cursor ) {
174176 camera->RotateYaw ((float )dx);
175- }
176-
177- if (dy) {
178- camera->RotatePitch ((float )-dy);
177+ camera->RotatePitch ((float )-dy);
179178 }
180179
181180 just_warped = true ;
181+ caught_cursor = true ;
182182 glfwSetCursorPos (window, windowWidth / 2 , windowHeight / 2 );
183183 }
184+ else {
185+ caught_cursor = false ;
186+ }
184187}
185188
186189
@@ -428,8 +431,8 @@ void InitGraphics()
428431 GLuint defaultVShader = LoadShader (GL_VERTEX_SHADER, " shader\\ master.vert" );
429432 GLuint defaultFShader = LoadShader (GL_FRAGMENT_SHADER, " shader\\ masterOptimised.frag" );
430433 lightingShader.Create (defaultVShader, defaultFShader);
431- lightingShader.RegisterUniform (" useTexture[1]" ); // uniform doesn't count as active, so register it manually
432- lightingShader.RegisterUniform (" texTransform[1]" ); // uniform doesn't count as active, so register it manually
434+ lightingShader.RegisterUniform (" useTexture[1]" ); // uniform doesn't count as active, so register it manually?
435+ lightingShader.RegisterUniform (" texTransform[1]" ); // uniform doesn't count as active, so register it manually?
433436
434437 GLuint shadowVShader = LoadShader (GL_VERTEX_SHADER, " shader\\ vsm.vert" );
435438 GLuint shadowFShader = LoadShader (GL_FRAGMENT_SHADER, " shader\\ vsm.frag" );
0 commit comments