added updating of vertex and face normals

This commit is contained in:
ganovelli 2007-11-14 11:56:23 +00:00
parent 75eba3e96d
commit 79067524eb
2 changed files with 60 additions and 1 deletions

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.14 2007/07/12 23:11:35 cignoni
added the missing PerVertexNormalizedPerFaceNormalized
Revision 1.13 2007/01/10 17:25:14 matteodelle
*** empty log message ***
@ -230,6 +233,48 @@ static void PerVertexNormalized(ComputeMeshType &m)
(*vi).N().Normalize();
}
/// multiply the vertex normals by the matrix passed. By default, the scale component is removed
static void PerVertexMatrix(ComputeMeshType &m, const Matrix44<ScalarType> &mat, bool remove_scaling= true){
float pos_33;
float scale;
Matrix33<ScalarType> mat33(mat,3);
if( !m.HasPerVertexNormal()) return;
if(remove_scaling){
scale = pow(mat33.Determinant(),1/(float)3.0);
mat33[0][0]/=scale;
mat33[1][1]/=scale;
mat33[2][2]/=scale;
}
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
if( !(*vi).IsD() && (*vi).IsRW() )
(*vi).N() = mat33*(*vi).N();
}
/// multiply the face normals by the matrix passed. By default, the scale component is removed
static void PerFaceMatrix(ComputeMeshType &m, const Matrix44<ScalarType> &mat, bool remove_scaling= true){
float pos_33;
float scale;
Matrix33<ScalarType> mat33(mat,3);
if( !m.HasPerFaceNormal()) return;
if(remove_scaling){
scale = pow(mat33.Determinant(),1/(float)3.0);
mat33[0][0]/=scale;
mat33[1][1]/=scale;
mat33[2][2]/=scale;
}
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
if( !(*fi).IsD() && (*fi).IsRW() )
(*fi).N() = mat33* (*fi).N();
}
}; // end class
} // End namespace

View File

@ -24,11 +24,16 @@
History
$Log: not supported by cvs2svn $
Revision 1.1 2005/07/06 08:02:27 cignoni
Initial commit
****************************************************************************/
#ifndef __VCG_TRI_UPDATE_POSITION
#define __VCG_TRI_UPDATE_POSITION
#include "normal.h"
namespace vcg {
namespace tri {
@ -51,11 +56,20 @@ typedef typename MeshType::FacePointer FacePointer;
typedef typename MeshType::FaceIterator FaceIterator;
/// Multiply
static void Matrix(ComputeMeshType &m, const Matrix44<ScalarType> &M)
static void Matrix(ComputeMeshType &m, const Matrix44<ScalarType> &M, bool update_also_normals = true)
{
VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD()) (*vi).P()=M*(*vi).cP();
if(update_also_normals){
if(m.HasPerVertexNormal()){
UpdateNormals<ComputeMeshType>::PerVertexMatrix(m,M);
}
if(m.HasPerFaceNormal()){
UpdateNormals<ComputeMeshType>::PerFaceMatrix(m,M);
}
}
}