Trying to get first-person movement going

master
Martin Felis 2021-10-29 12:13:13 +02:00
parent 0b12991f10
commit cc1a106bb9
2 changed files with 17 additions and 4 deletions

View File

@ -22,8 +22,6 @@ void CameraState_CalcFromMatrix(CameraState* camera_state, simd4x4f* mtx) {
camera_state->heading = atan2(forward[2], -forward[0]);
camera_state->pitch = asin(-forward[1]);
gLog("eye: %f %f %f", camera_state->pos[0], camera_state->pos[1], camera_state->pos[2]);
simd4x4f rot_mat = *mtx;
rot_mat.w = simd4f_create(0.f, 0.f, 0.f, 1.f);
simd4x4f_transpose_inplace(&rot_mat);
@ -31,7 +29,6 @@ void CameraState_CalcFromMatrix(CameraState* camera_state, simd4x4f* mtx) {
simd4f eye;
simd4x4f_matrix_point3_mul(&rot_mat, &mtx->w, &eye);
gLog ("eye: %f, %f, %f", simd4f_get_y(eye), simd4f_get_z(eye));
camera_state->pos[0] = -simd4f_get_x(eye);
camera_state->pos[1] = -simd4f_get_y(eye);
camera_state->pos[2] = -simd4f_get_z(eye);

View File

@ -586,10 +586,26 @@ int main(void) {
bool changed = false;
changed = ImGui::SliderFloat("Heading", &gCameraState->heading, -M_PI * 0.98, M_PI * 0.98);
changed = changed || ImGui::SliderFloat("Pitch", &gCameraState->pitch, -M_PI * 0.98, M_PI * 0.98);
changed = changed || ImGui::SliderFloat("Pitch", &gCameraState->pitch, -M_PI * 0.49, M_PI * 0.49);
float camera_accel[3] = {0.f, 0.f, 0.f};
if (glfwGetKey(gWindow, GLFW_KEY_W)) {
camera_accel[0] -= 100.f;
}
if (glfwGetKey(gWindow, GLFW_KEY_S)) {
camera_accel[0] += 100.f;
}
if (glfwGetKey(gWindow, GLFW_KEY_A)) {
camera_accel[2] += 100.f;
}
if (glfwGetKey(gWindow, GLFW_KEY_D)) {
camera_accel[2] -= 100.f;
}
if (changed) {
CameraState_CalcToMatrix(gCameraState, &gCameraState->mtxView);
} else {
CameraState_Update(gCameraState, frame_delta_time, 0.f, 0.f, camera_accel);
}
ImGui::End();