Commit 858a1ff8 authored by Mike Kremer's avatar Mike Kremer

Added function to transform a whole mesh using a given transformation matrix....

Added function to transform a whole mesh using a given transformation matrix. This belongs here rather than into the Plugin-Move class.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12989 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 49a12724
......@@ -225,6 +225,44 @@ calc_angle_around( const MeshT& _mesh , const typename MeshT::VertexHandle _vh)
return angle;
}
template< typename MeshT >
void transformMesh(ACG::Matrix4x4d _matrix , MeshT& _mesh) {
// Get the inverse matrix of the transformation for the normals
ACG::Matrix4x4d invTranspMat = _matrix;
// Build inverse transposed matrix of _matrix
invTranspMat.invert();
invTranspMat.transpose();
typename MeshT::VertexIter v_it = _mesh.vertices_begin();
typename MeshT::VertexIter v_end = _mesh.vertices_end();
for (; v_it != v_end; ++v_it) {
// Transform the mesh vertex
_mesh.set_point(v_it, _matrix.transform_point(_mesh.point(v_it)));
// Transform the vertex normal
typename MeshT::Normal n = invTranspMat.transform_vector(_mesh.normal(v_it));
n.normalize();
_mesh.set_normal(v_it, n);
}
typename MeshT::FaceIter f_it = _mesh.faces_begin();
typename MeshT::FaceIter f_end = _mesh.faces_end();
for (; f_it != f_end; ++f_it) {
// Transform the face normal
typename MeshT::Normal n = invTranspMat.transform_vector(_mesh.normal(f_it));
n.normalize();
_mesh.set_normal(f_it, n);
}
}
//=============================================================================
} // MeshFunctions Namespace
//=============================================================================
......@@ -148,6 +148,15 @@ template < typename MeshT >
double
calc_angle_around( const MeshT& _mesh , const typename MeshT::VertexHandle _vh);
/**
* Transform geometry of the mesh using the specified
* transformation matrix.
* @param _matrix The transformation matrix
* @param _mesh The mesh that is to be transformed
*/
template< typename MeshT >
void transformMesh(ACG::Matrix4x4d _matrix , MeshT& _mesh);
//=============================================================================
} // MeshFunctions Namespace
//=============================================================================
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment