mirror of
https://github.com/Garux/netradiant-custom.git
synced 2026-09-28 00:00:03 +02:00
snap angle, angles keys on transform to zero to avoid scientific notation in saved string
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user