matrix4_for_normal_transform, matrix4_transformed_normal, plane3_transformed_affine_full functions

This commit is contained in:
Garux
2018-05-16 14:16:43 +03:00
parent e1bc4a8ba9
commit ae1bd2c066
4 changed files with 28 additions and 30 deletions

View File

@@ -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(

View File

@@ -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() );
}