/* * osgDB::wrl - a VRML 1.0 loader for OpenSceneGraph * Copyright (C) 2002 Ruben Lopez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "normals.h" #define CREASE_ANGLE 3.14159265356 * 45 / 180 float difAng(osg::Vec3 a, osg::Vec3 b) { float div = a.length() * b.length(); return (div != 0.0f ? acosf( (a*b) / div) : 0.0f ); } osg::Vec3 calcNormal(osg::Vec3 &a, osg::Vec3 &b, osg::Vec3 &c) { osg::Vec3 norm; osg::Vec3 v1; osg::Vec3 v2; v1=b-c; v2=a-b; norm=v1 ^ v2; // cross product norm.normalize(); return norm; } void get3v(VertexList &vertices, VertexIndexList &vindex, int &a, int &b, int &c) { unsigned tam=vindex.size(); unsigned i; b=0;c=0; a=vindex[0]; for (i=1;i 2) { int v0,v1,v2; get3v(vertices,vindex,v0,v1,v2); if (v0 == v1 || v0 == v2) { std::cerr << "ERROR: Vertices alineados: nv=" << vindex.size() << std::endl; } normales_polys[poly] = calcNormal(vertices[v0], vertices[v1], vertices[v2]); if (normales_polys[poly] == osg::Vec3(0,0,0) && vindex.size() > 2) { std::cerr << "##***" << "Normal nula VERTICES=" << vindex.size() << " " << vertices[v0] << " " << vertices[v1] << " " << vertices[v2] << std::endl; } } } /* Phase 2: Selective smooth depending on crease angle */ for (poly=0;poly