diff --git a/libs/math/matrix.h b/libs/math/matrix.h index 1b990b1a..0b95800f 100644 --- a/libs/math/matrix.h +++ b/libs/math/matrix.h @@ -1125,6 +1125,17 @@ inline Vector3 matrix4_get_scale_vec3( const Matrix4& self ){ ); } +/// \brief Calculates and returns signed (x, y, z) scale values that produce the scale component of \p self. +/// \p self must be affine and orthogonal to produce a meaningful result. +/// \p self must not contain rotation to produce meaningful signs. +inline Vector3 matrix4_get_scale_vec3_signed( const Matrix4& self ){ + return Vector3( + static_cast( std::copysign( vector3_length( self.x().vec3() ), vector3_dot( self.x().vec3(), g_vector3_axis_x ) ) ), + static_cast( std::copysign( vector3_length( self.y().vec3() ), vector3_dot( self.y().vec3(), g_vector3_axis_y ) ) ), + static_cast( std::copysign( vector3_length( self.z().vec3() ), vector3_dot( self.z().vec3(), g_vector3_axis_z ) ) ) + ); +} + /// \brief Scales \p self by \p scale. inline void matrix4_scale_by_vec3( Matrix4& self, const Vector3& scale ){ matrix4_multiply_by_matrix4( self, matrix4_scale_for_vec3( scale ) ); diff --git a/plugins/entity/miscmodel.cpp b/plugins/entity/miscmodel.cpp index 477fc5b7..fb3cb984 100644 --- a/plugins/entity/miscmodel.cpp +++ b/plugins/entity/miscmodel.cpp @@ -311,12 +311,27 @@ public: } void scale( const Vector3& scaling ){ //m_scale = scale_scaled( m_scale, scaling ); - +#if 1 + const Matrix4 rot = matrix4_rotation_for_euler_xyz_degrees( m_anglesKey.m_angles ); + m_scale = matrix4_get_scale_vec3_signed( + matrix4_multiplied_by_matrix4( + matrix4_affine_inverse( rot ), + matrix4_multiplied_by_matrix4( + matrix4_scale_for_vec3( scaling ), + matrix4_multiplied_by_matrix4( + rot, + matrix4_scale_for_vec3( m_scale ) + ) + ) + ) + ); +#else Matrix4 mat( matrix4_scale_for_vec3( scaling ) ); matrix4_multiply_by_matrix4( mat, matrix4_rotation_for_euler_xyz_degrees( m_anglesKey.m_angles ) ); matrix4_scale_by_vec3( mat, m_scale ); m_scale = matrix4_get_scale_vec3( mat ); +#endif //m_angles = angles_snapped_to_zero( matrix4_get_rotation_euler_xyz_degrees( mat ) ); } void snapto( float snap ){ diff --git a/tools/quake3/q3map2/model.cpp b/tools/quake3/q3map2/model.cpp index ed01f630..e466a76d 100644 --- a/tools/quake3/q3map2/model.cpp +++ b/tools/quake3/q3map2/model.cpp @@ -362,6 +362,7 @@ std::vector LoadModelWalker( const char *name, int frame ) void InsertModel( const char *name, int skin, int frame, const Matrix4& transform, const std::list *remaps, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, float clipDepth ){ int i, j, k; const Matrix4 nTransform( matrix4_for_normal_transform( transform ) ); + const bool transform_lefthanded = MATRIX4_LEFTHANDED == matrix4_handedness( transform ); AssModel *model; shaderInfo_t *si; mapDrawSurface_t *ds; @@ -622,6 +623,9 @@ void InsertModel( const char *name, int skin, int frame, const Matrix4& transfor for ( size_t i = 0; i < 3; i++ ){ ds->indexes[idCopied++] = face.mIndices[i]; } + if( transform_lefthanded ){ + std::swap( ds->indexes[idCopied - 1], ds->indexes[idCopied - 2] ); + } } }