a/math: Fix some truncation warnings.

This commit is contained in:
Ryan Pavlik 2021-09-20 10:20:55 -05:00
parent 72995a8298
commit 5f8cb4e227
3 changed files with 11 additions and 11 deletions

View file

@ -150,15 +150,15 @@ gravity_correction(struct m_imu_3dof *f,
if (f->grav.error_angle > min_tilt_error) {
// Correct 180° over 5 seconds, when moving.
float max_radians = M_PI * dt / 5;
float max_radians = (float)M_PI * (float)dt / 5;
// Correct 180° over 60 seconds, when stationary.
float min_radians = M_PI * dt / 60;
float min_radians = (float)M_PI * (float)dt / 60;
/*
* We're treating 0.5 * gyro_length as a unitless scale factor.
* Tested in a headset, 0.5 felt nice.
*/
float correction_radians = 0.5 * gyro_length * max_radians;
float correction_radians = 0.5f * gyro_length * max_radians;
// Clamp to the range [min_radians, max_radians]
correction_radians = fmaxf(min_radians, correction_radians);
correction_radians = fminf(max_radians, correction_radians);
@ -221,7 +221,7 @@ m_imu_3dof_update(struct m_imu_3dof *f,
uint64_t diff = timestamp_ns - f->last.timestamp_ns;
double dt = (double)diff / DUR_1S_IN_NS;
f->last.delta_ms = dt * 1000.0;
f->last.delta_ms = dt * 1000.0f;
f->last.timestamp_ns = timestamp_ns;
m_ff_vec3_f32_push(f->word_accel_ff, &world_accel, timestamp_ns);
@ -240,7 +240,7 @@ m_imu_3dof_update(struct m_imu_3dof *f,
gyro_biased.z / gyro_biased_length,
};
float rot_angle = gyro_biased_length * dt;
float rot_angle = gyro_biased_length * (float)dt;
struct xrt_quat delta_orient;
math_quat_from_angle_vector(rot_angle, &rot_axis, &delta_orient);

View file

@ -131,8 +131,8 @@ math_compute_fovs(double w_total,
return false;
}
fov->angle_left = -theta_1;
fov->angle_right = theta_2;
fov->angle_left = (float)-theta_1;
fov->angle_right = (float)theta_2;
double phi_1 = 0;
double phi_2 = 0;
@ -153,8 +153,8 @@ math_compute_fovs(double w_total,
}
/* phi_1 is "down" so we record this as negative. */
fov->angle_down = phi_1 * -1.0;
fov->angle_up = phi_2;
fov->angle_down = (float)(-phi_1);
fov->angle_up = (float)phi_2;
return true;
}

View file

@ -55,7 +55,7 @@ do_orientation(const struct xrt_space_relation *rel,
if (valid_orientation) {
math_quat_integrate_velocity(&rel->pose.orientation, // Old orientation
&accum, // Angular velocity
delta_s, // Delta in seconds
(float)delta_s, // Delta in seconds
&out_rel->pose.orientation); // Result
}
@ -93,7 +93,7 @@ do_position(const struct xrt_space_relation *rel,
}
if (valid_position) {
out_rel->pose.position = m_vec3_add(rel->pose.position, m_vec3_mul_scalar(accum, delta_s));
out_rel->pose.position = m_vec3_add(rel->pose.position, m_vec3_mul_scalar(accum, (float)delta_s));
}
// We use the new linear velocity with the acceleration integrated.