Skip to content

Commit

Permalink
stick_vector: ensure we do not divide by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Sep 3, 2024
1 parent b2ff500 commit db844c3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/flight/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ vec3_t input_stick_vector(float rx_input[]) {
.yaw = fastcos(roll) * fastcos(pitch),
};

const float length = (stickvector.roll * stickvector.roll + stickvector.pitch * stickvector.pitch);
if (length > 0) {
const float mag = 1.0f / sqrtf(length / (1 - stickvector.yaw * stickvector.yaw));
if (stickvector.yaw < 1.0f) {
const float length = (stickvector.roll * stickvector.roll + stickvector.pitch * stickvector.pitch);
const float mag = 1.0f / sqrtf(length / (1.0f - stickvector.yaw * stickvector.yaw));
stickvector.roll *= mag;
stickvector.pitch *= mag;
} else {
Expand Down

0 comments on commit db844c3

Please sign in to comment.