snap angle, angles keys on transform to zero to avoid scientific notation in saved string

This commit is contained in:
Garux
2025-05-03 16:30:26 +05:00
parent 4cf97f5651
commit 05f3f66be7
4 changed files with 34 additions and 17 deletions
+9 -4
View File
@@ -78,9 +78,13 @@ public:
}
};
inline float float_snapped_to_zero( float value ){
return fabs( value ) < 1e-6 ? 0.f : value;
}
/*
zero snap angle value to avoid scientific notation after sprinf %g
it's not supported in e.g. Q3:
https://github.com/id-Software/Quake-III-Arena/blob/master/code/game/bg_lib.c#L910
0.0001f is least value, which produces no scientific notation, must be good nuff precision too 🤞🏿
*/
const float ANGLEKEY_SMALLEST = 0.0001f;
inline float angle_rotated( float angle, const Quaternion& rotation ){
return float_snapped_to_zero(
@@ -89,6 +93,7 @@ inline float angle_rotated( float angle, const Quaternion& rotation ){
matrix4_rotation_for_quaternion_quantised( rotation ),
matrix4_rotation_for_z_degrees( angle )
)
).z()
).z(),
ANGLEKEY_SMALLEST
);
}
+6 -12
View File
@@ -105,33 +105,27 @@ inline Matrix4 matrix4_rotation_for_euler_xyz_degrees_quantised( const Vector3&
return matrix4_rotation_for_euler_xyz_degrees( angles );
}
inline Vector3 angles_snapped_to_zero( const Vector3& angles ){
const float epsilon = ( fabs( angles[0] ) > 0.001f || fabs( angles[1] ) > 0.001f || fabs( angles[2] ) > 0.001f ) ? 5e-5 : 1e-6;
return Vector3( fabs( angles[0] ) < epsilon ? 0.f : angles[0],
fabs( angles[1] ) < epsilon ? 0.f : angles[1],
fabs( angles[2] ) < epsilon ? 0.f : angles[2]
);
}
inline Vector3 angles_rotated( const Vector3& angles, const Quaternion& rotation ){
return angles_snapped_to_zero(
return vector3_snapped_to_zero(
matrix4_get_rotation_euler_xyz_degrees(
matrix4_multiplied_by_matrix4(
matrix4_rotation_for_quaternion_quantised( rotation ),
matrix4_rotation_for_euler_xyz_degrees_quantised( angles )
)
)
),
ANGLEKEY_SMALLEST
);
}
#if 0
inline Vector3 angles_rotated_for_rotated_pivot( const Vector3& angles, const Quaternion& rotation ){
return angles_snapped_to_zero(
return vector3_snapped_to_zero(
matrix4_get_rotation_euler_xyz_degrees(
matrix4_multiplied_by_matrix4(
matrix4_rotation_for_euler_xyz_degrees_quantised( angles ),
matrix4_rotation_for_quaternion_quantised( rotation )
)
)
),
ANGLEKEY_SMALLEST
);
}
#endif
+1 -1
View File
@@ -339,7 +339,7 @@ public:
m_scale = matrix4_get_scale_vec3( mat );
#endif
//m_angles = angles_snapped_to_zero( matrix4_get_rotation_euler_xyz_degrees( mat ) );
//m_angles = vector3_snapped_to_zero( matrix4_get_rotation_euler_xyz_degrees( mat ), ANGLEKEY_SMALLEST );
}
void snapto( float snap ){
m_originKey.m_origin = origin_snapped( m_originKey.m_origin, snap );