@@ -140,13 +140,13 @@ void display()
|
|
140
140
|
mat4 cityModelMatrix(1.0f);
|
141
141
|
|
142
142
|
// Set up the view matrix
|
143
|
-
//
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
mat4 viewMatrix =
|
143
|
+
// use camera direction as -z axis and compute the x (cameraRight) and y (cameraUp) base vectors
|
144
|
+
vec3 cameraRight = normalize(cross(cameraDirection, worldUp));
|
145
|
+
vec3 cameraUp = normalize(cross(cameraRight, cameraDirection));
|
146
|
+
|
147
|
+
mat3 cameraBaseVectorsWorldSpace(cameraRight, cameraUp, -cameraDirection);
|
148
|
+
mat4 cameraRotation = mat4(transpose(cameraBaseVectorsWorldSpace));
|
149
|
+
mat4 viewMatrix = cameraRotation * translate(-cameraPosition);
|
150
150
|
|
151
151
|
// Setup the projection matrix
|
152
152
|
if(w != old_w || h != old_h)
|
@@ -245,7 +245,10 @@ bool handleEvents(void)
|
|
245
245
|
int delta_y = event.motion.y - g_prevMouseCoords.y;
|
246
246
|
if(event.button.button == SDL_BUTTON_LEFT)
|
247
247
|
{
|
248
|
-
|
248
|
+
float rotationSpeed = 0.005f;
|
249
|
+
mat4 yaw = rotate(rotationSpeed * -delta_x, worldUp);
|
250
|
+
mat4 pitch = rotate(rotationSpeed * -delta_y, normalize(cross(cameraDirection, worldUp)));
|
251
|
+
cameraDirection = vec3(pitch * yaw * vec4(cameraDirection, 0.0f));
|
249
252
|
}
|
250
253
|
g_prevMouseCoords.x = event.motion.x;
|
251
254
|
g_prevMouseCoords.y = event.motion.y;
|