* support scale 0 in AP Texdef_transformLocked

This commit is contained in:
Garux 2017-12-05 14:39:14 +03:00
parent 0e29985090
commit 7103ac23de

View File

@ -1688,13 +1688,35 @@ void Texdef_transformLocked( TextureProjection& projection, std::size_t width, s
} }
const Vector3 oldInvariant( centroid ); const Vector3 oldInvariant( centroid );
const Vector3 offset = matrix4_transformed_point( identity2transformed, Vector3( 0, 0, 0 ) );
#if 0//not ok, if scaling #if 0//not ok, if scaling
const Vector3 offset = matrix4_transformed_point( identity2transformed, Vector3( 0, 0, 0 ) );
Vector3 newNormal = matrix4_transformed_point( identity2transformed, plane.normal() ) - offset; Vector3 newNormal = matrix4_transformed_point( identity2transformed, plane.normal() ) - offset;
#else #else
Matrix4 maa( matrix4_affine_inverse( identity2transformed ) ); Matrix4 maa( identity2transformed );
if( maa.xx() != 0 && maa.yy() != 0 && maa.zz() != 0 ){
matrix4_affine_invert( maa );
matrix4_transpose( maa ); matrix4_transpose( maa );
}
else{ /* we are only performing scale alone, so this must work; sup with more complex (+non orthonormal) matrices? */
if( maa.xx() == 0 ){
maa.xx() = 1;
maa.yy() = 0;
maa.zz() = 0;
}
else if( maa.yy() == 0 ){
maa.xx() = 0;
maa.yy() = 1;
maa.zz() = 0;
}
else if( maa.zz() == 0 ){
maa.xx() = 0;
maa.yy() = 0;
maa.zz() = 1;
}
}
// globalOutputStream() << "maa: " << maa << "\n";
Vector3 newNormal( vector3_normalised( matrix4_transformed_direction( maa, plane.normal() ) ) ); Vector3 newNormal( vector3_normalised( matrix4_transformed_direction( maa, plane.normal() ) ) );
// globalOutputStream() << plane.normal() << newNormal << "\n";
#endif #endif
#if 0 #if 0
// fix some rounding errors - if the old and new texture axes are almost the same, use the old axis // fix some rounding errors - if the old and new texture axes are almost the same, use the old axis
@ -1721,8 +1743,8 @@ void Texdef_transformLocked( TextureProjection& projection, std::size_t width, s
const Vector3 oldYAxisOnBoundary = plane3_project_point( plane, yAxis * projection.m_texdef.scale[1], zAxis ) - boundaryOffset; const Vector3 oldYAxisOnBoundary = plane3_project_point( plane, yAxis * projection.m_texdef.scale[1], zAxis ) - boundaryOffset;
// transform the projected texture axes and compensate the translational component // transform the projected texture axes and compensate the translational component
const Vector3 transformedXAxis = matrix4_transformed_point( identity2transformed, oldXAxisOnBoundary ) - offset; const Vector3 transformedXAxis = matrix4_transformed_direction( identity2transformed, oldXAxisOnBoundary );
const Vector3 transformedYAxis = matrix4_transformed_point( identity2transformed, oldYAxisOnBoundary ) - offset; const Vector3 transformedYAxis = matrix4_transformed_direction( identity2transformed, oldYAxisOnBoundary );
// obtain the new texture plane norm and the new base texture axes // obtain the new texture plane norm and the new base texture axes
const std::size_t newIndex = planeNormalIndex( newNormal ); const std::size_t newIndex = planeNormalIndex( newNormal );
@ -1827,7 +1849,7 @@ void Texdef_transformLocked( TextureProjection& projection, std::size_t width, s
Matrix4 transformed2stTransformed; Matrix4 transformed2stTransformed;
Texdef_basisForNormal( projection, normalTransformed, transformed2stTransformed ); Texdef_basisForNormal( projection, normalTransformed, transformed2stTransformed );
Matrix4 stTransformed2identity( matrix4_affine_inverse( matrix4_multiplied_by_matrix4( transformed2stTransformed, identity2transformed ) ) ); Matrix4 stTransformed2identity( matrix4_affine_inverse( matrix4_multiplied_by_matrix4( transformed2stTransformed, identity2transformed ) ) ); //QNAN here, if some scale = 0
Matrix4 stIdentity2stOriginal; Matrix4 stIdentity2stOriginal;
Texdef_toTransform( projection, (float)width, (float)height, stIdentity2stOriginal ); Texdef_toTransform( projection, (float)width, (float)height, stIdentity2stOriginal );