matrix4_for_normal_transform, matrix4_transformed_normal, plane3_transformed_affine_full functions
This commit is contained in:
parent
e1bc4a8ba9
commit
ae1bd2c066
|
|
@ -398,8 +398,8 @@ inline BasicVector3<Element> matrix4_transformed_direction( const Matrix4& self,
|
|||
|
||||
/// \brief Transforms \p direction by \p self in-place.
|
||||
template<typename Element>
|
||||
inline void matrix4_transform_direction( const Matrix4& self, BasicVector3<Element>& normal ){
|
||||
normal = matrix4_transformed_direction( self, normal );
|
||||
inline void matrix4_transform_direction( const Matrix4& self, BasicVector3<Element>& direction ){
|
||||
direction = matrix4_transformed_direction( self, direction );
|
||||
}
|
||||
|
||||
/// \brief Returns \p vector4 transformed by \p self.
|
||||
|
|
@ -591,6 +591,18 @@ inline void matrix4_full_invert( Matrix4& self ){
|
|||
}
|
||||
|
||||
|
||||
/// lets say M is a transformation matrix, then transforming vertex v is just M*v
|
||||
/// but transforming the normal is M^(-T) n
|
||||
inline Matrix4 matrix4_for_normal_transform( const Matrix4& matrix ){
|
||||
return matrix4_transposed( matrix4_affine_inverse( matrix ) );
|
||||
}
|
||||
|
||||
template<typename Element>
|
||||
inline BasicVector3<Element> matrix4_transformed_normal( const Matrix4& matrix, const BasicVector3<Element>& normal ){
|
||||
return vector3_normalised( matrix4_transformed_direction( matrix4_for_normal_transform( matrix ), normal ) );
|
||||
}
|
||||
|
||||
|
||||
/// \brief Constructs a pure-translation matrix from \p translation.
|
||||
inline Matrix4 matrix4_translation_for_vec3( const Vector3& translation ){
|
||||
return Matrix4(
|
||||
|
|
|
|||
|
|
@ -99,6 +99,12 @@ inline Plane3 plane3_inverse_transformed( const Plane3& plane, const Matrix4& tr
|
|||
);
|
||||
}
|
||||
|
||||
inline Plane3 plane3_transformed_affine_full( const Plane3& plane, const Matrix4& transform ){
|
||||
const DoubleVector3 anchor( matrix4_transformed_point( transform, plane.normal() * plane.dist() ) );
|
||||
const DoubleVector3 normal( matrix4_transformed_normal( transform, plane.normal() ) );
|
||||
return Plane3( normal, vector3_dot( normal, anchor ) );
|
||||
}
|
||||
|
||||
inline Plane3 plane3_flipped( const Plane3& plane ){
|
||||
return Plane3( vector3_negated( plane.normal() ), -plane.dist() );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -633,22 +633,12 @@ inline Plane3 Plane3_applyTranslation( const Plane3& plane, const Vector3& trans
|
|||
return Plane3( tmp.normal(), -tmp.dist() );
|
||||
}
|
||||
|
||||
/// lets say M is a transformation matrix, then transforming vertex v is just M*v
|
||||
/// but transforming the normal is M^(-T) n
|
||||
inline Plane3 Plane3_applyTransform( const Plane3& plane, const Matrix4& matrix ){
|
||||
/* fails for scaling */
|
||||
//Plane3 tmp( plane3_transformed( Plane3( plane.normal(), -plane.dist() ), matrix ) );
|
||||
//return Plane3( tmp.normal(), -tmp.dist() );
|
||||
/* ok */
|
||||
// Vector4 anchor = matrix4_transformed_vector4( matrix, Vector4( plane.normal() * plane.dist(), 1 ) );
|
||||
// Matrix4 mat = matrix4_transposed( matrix4_full_inverse( matrix ) );
|
||||
// Vector4 normal = matrix4_transformed_vector4( mat, Vector4( plane.normal(), 0 ) );
|
||||
// return plane3_normalised( Plane3( vector4_to_vector3( normal ), vector3_dot( vector4_to_vector3( normal ), vector4_to_vector3( anchor ) ) ) );
|
||||
|
||||
const DoubleVector3 anchor( matrix4_transformed_point( matrix, plane.normal() * plane.dist() ) );
|
||||
const Matrix4 mat( matrix4_transposed( matrix4_affine_inverse( matrix ) ) );
|
||||
const DoubleVector3 normal( vector3_normalised( matrix4_transformed_direction( mat, plane.normal() ) ) );
|
||||
return Plane3( normal, vector3_dot( normal, anchor ) );
|
||||
return plane3_transformed_affine_full( plane, matrix );
|
||||
}
|
||||
|
||||
class FacePlane
|
||||
|
|
|
|||
|
|
@ -1494,13 +1494,10 @@ void Texdef_transformLocked_original( TextureProjection& projection, std::size_t
|
|||
|
||||
//globalOutputStream() << "plane.normal(): " << plane.normal() << "\n";
|
||||
#if 0
|
||||
Vector3 normalTransformed( matrix4_transformed_direction( identity2transformed, plane.normal() ) );
|
||||
const Vector3 normalTransformed( matrix4_transformed_direction( identity2transformed, plane.normal() ) );
|
||||
#else //preserves scale in BP while scaling, but not shift //fixes QNAN
|
||||
Matrix4 maa( matrix4_affine_inverse( identity2transformed ) );
|
||||
matrix4_transpose( maa );
|
||||
//Vector4 vec4 = matrix4_transformed_vector4( maa, Vector4( plane.normal(), 0 ) );
|
||||
//Vector3 normalTransformed( vector3_normalised( vector4_to_vector3( vec4 ) ) );
|
||||
Vector3 normalTransformed( vector3_normalised( matrix4_transformed_direction( maa, plane.normal() ) ) );
|
||||
const Matrix4 maa( matrix4_for_normal_transform( identity2transformed ) );
|
||||
const Vector3 normalTransformed( vector3_normalised( matrix4_transformed_direction( maa, plane.normal() ) ) );
|
||||
#endif
|
||||
|
||||
//globalOutputStream() << "normalTransformed: " << normalTransformed << "\n";
|
||||
|
|
@ -1707,9 +1704,7 @@ void Texdef_transformLocked( TextureProjection& projection, std::size_t width, s
|
|||
}
|
||||
|
||||
#if 0
|
||||
Matrix4 maa( matrix4_affine_inverse( identity2transformed ) );
|
||||
matrix4_transpose( maa );
|
||||
const DoubleVector3 normalTransformed( vector3_normalised( matrix4_transformed_direction( maa, plane.normal() ) ) );
|
||||
const DoubleVector3 normalTransformed( matrix4_transformed_normal( identity2transformed, plane.normal() ) );
|
||||
#else
|
||||
/* this is also handling scale = 0 case */
|
||||
DoubleVector3 normalTransformed( plane3_for_points( points ).normal() );
|
||||
|
|
@ -1731,10 +1726,7 @@ void Texdef_transformLocked( TextureProjection& projection, std::size_t width, s
|
|||
const Vector3 offset = matrix4_transformed_point( identity2transformed, Vector3( 0, 0, 0 ) );
|
||||
Vector3 newNormal = matrix4_transformed_point( identity2transformed, plane.normal() ) - offset;
|
||||
#elif 0
|
||||
const Matrix4 maa( matrix4_transposed( matrix4_affine_inverse( identity2transformed ) ) );
|
||||
// globalOutputStream() << "maa: " << maa << "\n";
|
||||
Vector3 newNormal( vector3_normalised( matrix4_transformed_direction( maa, plane.normal() ) ) );
|
||||
// globalOutputStream() << plane.normal() << newNormal << "\n";
|
||||
const Vector3 newNormal( matrix4_transformed_normal( identity2transformed, plane.normal() ) );
|
||||
#elif 1
|
||||
/* this is also handling scale = 0 case */
|
||||
DoubleVector3 texX, texY;
|
||||
|
|
@ -1855,10 +1847,8 @@ void Texdef_transformLocked( TextureProjection& projection, std::size_t width, s
|
|||
}
|
||||
|
||||
//globalOutputStream() << "plane.normal(): " << plane.normal() << "\n";
|
||||
Matrix4 maa( matrix4_affine_inverse( identity2transformed ) );
|
||||
matrix4_transpose( maa );
|
||||
Vector3 normalTransformed( vector3_normalised( matrix4_transformed_direction( maa, plane.normal() ) ) );
|
||||
|
||||
const Matrix4 maa( matrix4_for_normal_transform( identity2transformed ) );
|
||||
const Vector3 normalTransformed( vector3_normalised( matrix4_transformed_direction( maa, plane.normal() ) ) );
|
||||
//globalOutputStream() << "normalTransformed: " << normalTransformed << "\n";
|
||||
|
||||
// identity: identity space
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user