00001 /*---------------------------------------------------------------------------*\ 00002 * OpenSG * 00003 * * 00004 * * 00005 * Copyright 2000,2001 by OpenSG Forum * 00006 * * 00007 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de * 00008 * * 00009 \*---------------------------------------------------------------------------*/ 00010 /*---------------------------------------------------------------------------*\ 00011 * License * 00012 * * 00013 * This library is free software; you can redistribute it and/or modify it * 00014 * under the terms of the GNU Library General Public License as published * 00015 * by the Free Software Foundation, version 2. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, but * 00018 * WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00020 * Library General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Library General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00025 * * 00026 \*---------------------------------------------------------------------------*/ 00027 /*---------------------------------------------------------------------------*\ 00028 * Changes * 00029 * * 00030 * * 00031 * * 00032 * * 00033 * * 00034 * * 00035 \*---------------------------------------------------------------------------*/ 00036 00037 //--------------------------------------------------------------------------- 00038 // Includes 00039 //--------------------------------------------------------------------------- 00040 00041 #include <OSGConfig.h> 00042 #include <OSGDVRVertex.h> 00043 #include <OSGDVRTriangle.h> 00044 00045 OSG_BEGIN_NAMESPACE 00046 00047 inline 00048 bool DVRClipGeometry::isLocalMinimum(DVRVertex &vertex) 00049 { 00050 for(MFInt32::const_iterator triIdx = vertex.adjacentTriangles.begin(); 00051 triIdx != vertex.adjacentTriangles.end (); 00052 triIdx++) 00053 { 00054 const Int32 *vertIndices = _mfTriangles[*triIdx].vertices; 00055 00056 for(unsigned int j = 0; j < 3; j++) 00057 { 00058 if (&_mfVertices[vertIndices[j]] != &vertex) 00059 { 00060 if(_mfVertices[vertIndices[j]].isCloser( 00061 vertex.refPlaneDistance)) 00062 { 00063 return false; 00064 } 00065 } 00066 } 00067 } 00068 00069 return true; 00070 } 00071 00072 inline 00073 void DVRClipGeometry::renderTriangle(const DVRTriangle &tri) const 00074 { 00075 glBegin(GL_TRIANGLES); 00076 { 00077 for(unsigned int i = 0; i < 3; i++) 00078 glVertex3fv( 00079 _mfVertices[tri.vertices[i]].transformedPos.getValues()); 00080 } 00081 glEnd(); 00082 } 00083 00084 inline 00085 bool DVRClipGeometry::isBehindPlane(DVRTriangle &tri, 00086 Real32 dist2RefPlane) 00087 { 00088 bool switched; 00089 bool v[3]; 00090 00091 for(unsigned int i = 0; i < 3; i++) 00092 { 00093 v[i] = 00094 _mfVertices[tri.vertices[i]].isBehindPlane(dist2RefPlane,switched); 00095 } 00096 00097 return (v[0] && v[1] && v[2]); 00098 } 00099 00100 inline 00101 Pnt3f DVRClipGeometry::interpolate(DVRTriangle *tri, 00102 Int32 v1, 00103 Int32 v2, 00104 Real32 dist2RefPlane) 00105 { 00106 float weight = 00107 00108 ((_mfVertices[tri->vertices[v2]].refPlaneDistance - 00109 dist2RefPlane ) / 00110 (_mfVertices[tri->vertices[v2]].refPlaneDistance - 00111 _mfVertices[tri->vertices[v1]].refPlaneDistance )); 00112 00113 if(weight == 1.0) 00114 { 00115 // sorry, but without this we will have some really bad flickering... 00116 weight += 0.000001; 00117 } 00118 00119 return 00120 (_mfVertices[tri->vertices[v1]].transformedPos * weight) + 00121 (_mfVertices[tri->vertices[v2]].transformedPos * (1.0f - 00122 weight)).subZero(); 00123 } 00124 00125 00126 OSG_END_NAMESPACE 00127 00128 #define OSGDVRCLIPGEOMETRY_INLINE_CVSID "@(#)$Id: $" 00129
1.4.3