Commit ef4a7685 authored by Mike Kremer's avatar Mike Kremer

Reverted update_normals() after transformation and corrected mesh...

Reverted update_normals() after transformation and corrected mesh transformation routine to use inverse transposed matrix to correctly transform normals.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@10797 383ad7c9-94d9-4d36-a494-682f7c89f535
parent bdf64912
......@@ -439,10 +439,8 @@ void MovePlugin::moveObject(ACG::Matrix4x4d mat, int _id) {
if ( object->dataType() == DATA_TRIANGLE_MESH ) {
transformMesh(mat , *PluginFunctions::triMesh(object) );
PluginFunctions::triMesh(object)->update_normals();
} else if ( object->dataType() == DATA_POLY_MESH ) {
transformMesh(mat , *PluginFunctions::polyMesh(object) );
PluginFunctions::polyMesh(object)->update_normals();
#ifdef ENABLE_TSPLINEMESH_SUPPORT
} else if ( object->dataType() == DATA_TSPLINE_MESH ) {
transformMesh(mat , *PluginFunctions::tsplineMesh(object) );
......@@ -1645,6 +1643,9 @@ ACG::Matrix4x4d MovePlugin::getLastManipulatorMatrix(bool _reset) {
//------------------------------------------------------------------------------
/** \brief Transform a mesh with the given transformation matrix
*
* Note: The normals have to be transformed with the inverse
* transposed transformation matrix in order to yield correct results
*
* @param _mat transformation matrix
* @param _mesh the mesh
......@@ -1652,9 +1653,12 @@ ACG::Matrix4x4d MovePlugin::getLastManipulatorMatrix(bool _reset) {
template< typename MeshT >
void MovePlugin::transformMesh(ACG::Matrix4x4d _mat , MeshT& _mesh ) {
// Get the inverse matrix of the transformation for the normals
ACG::Matrix4x4d invMat = _mat;
invMat.invert ();
ACG::Matrix4x4d invTranspMat = _mat;
// Build inverse transposed matrix of _mat
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) {
......@@ -1663,11 +1667,9 @@ void MovePlugin::transformMesh(ACG::Matrix4x4d _mat , MeshT& _mesh ) {
_mesh.set_point(v_it,_mat.transform_point(_mesh.point(v_it)));
// transform the vertex normal
typename MeshT::Point n = invMat.transform_vector(_mesh.normal(v_it));
typename MeshT::Normal n = invTranspMat.transform_vector(_mesh.normal(v_it));
//re-normalize the vertex normal
if (n.length () != 0.0)
n *= (1.0/n.length ());
n.normalize();
_mesh.set_normal(v_it,n);
}
......@@ -1677,11 +1679,9 @@ void MovePlugin::transformMesh(ACG::Matrix4x4d _mat , MeshT& _mesh ) {
for (; f_it != f_end; ++f_it) {
// transform the face normal
typename MeshT::Point n = invMat.transform_vector(_mesh.normal(f_it));
typename MeshT::Normal n = invTranspMat.transform_vector(_mesh.normal(f_it));
//re-normalize the face normal
if (n.length () != 0.0)
n *= (1.0/n.length ());
n.normalize();
_mesh.set_normal(f_it,n);
}
......
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