00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <freecloth/geom/geMesh.h>
00020 #include <freecloth/geom/geVector.h>
00021
00022
00023
00024
00025 FREECLOTH_NAMESPACE_START
00026
00027
00028
00029
00030
00031
00032 const GeMesh::VertexType* GeMesh::getVertexArray() const
00033 {
00034 return &_vertices.front();
00035 }
00036
00037
00038
00039 const GeMesh::TextureVertexType* GeMesh::getTextureVertexArray() const
00040 {
00041 return &_textureVertices.front();
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051 Float GeMesh::FaceWrapper::calcArea() const
00052 {
00053 GeVector v1( getVertex( 0 ), getVertex( 1 ) );
00054 GeVector v2( getVertex( 1 ), getVertex( 2 ) );
00055 return v1.cross( v2 ).length() / 2;
00056 }
00057
00058
00059
00060 GeVector GeMesh::FaceWrapper::calcNormal() const
00061 {
00062 GeVector v1( getVertex( 0 ), getVertex( 1 ) );
00063 GeVector v2( getVertex( 1 ), getVertex( 2 ) );
00064 return v1.cross( v2 ).getUnit();
00065 }
00066
00067
00068
00069 GePoint GeMesh::FaceWrapper::calcBarycentric( const GePoint& p ) const
00070 {
00071 return calcBarycentric( p, getVertex( 0 ), getVertex( 1 ), getVertex( 2 ) );
00072 }
00073
00074
00075
00076 GePoint GeMesh::FaceWrapper::calcBarycentric(
00077 const GePoint& p,
00078 const GePoint& v1,
00079 const GePoint& v2,
00080 const GePoint& v3
00081 ) {
00082 Float denom =
00083 ( v2._x - v1._x ) * ( v3._y - v1._y ) -
00084 ( v3._x - v1._x ) * ( v2._y - v1._y );
00085
00086
00087
00088 return GePoint(
00089 ( ( v2._x - p._x ) * ( v3._y - p._y ) -
00090 ( v3._x - p._x ) * ( v2._y - p._y ) ) / denom,
00091 ( ( v3._x - p._x ) * ( v1._y - p._y ) -
00092 ( v1._x - p._x ) * ( v3._y - p._y ) ) / denom,
00093 ( ( v1._x - p._x ) * ( v2._y - p._y ) -
00094 ( v2._x - p._x ) * ( v1._y - p._y ) ) / denom
00095 );
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105 std::ostream& operator<<( std::ostream& os, const GeMesh& mesh )
00106 {
00107 os << "GeMesh {" << std::endl;
00108
00109 GeMesh::VertexConstIterator vi;
00110 UInt32 i;
00111
00112 os << "vertices = " << std::endl;
00113 for ( vi = mesh.beginVertex(), i = 0; vi != mesh.endVertex(); ++vi, ++i ) {
00114 os << "[" << i << "] " << *vi << std::endl;
00115 }
00116
00117 GeMesh::TextureVertexConstIterator tvi;
00118 os << "texture vertices = " << std::endl;
00119 for (
00120 tvi = mesh.beginTextureVertex(), i = 0;
00121 tvi != mesh.endTextureVertex();
00122 ++tvi, ++i
00123 ) {
00124 os << "[" << i << "] " << *tvi << std::endl;
00125 }
00126
00127 GeMesh::FaceConstIterator fi;
00128 os << "faces = " << std::endl;
00129 for ( fi = mesh.beginFace(), i = 0; fi != mesh.endFace(); ++fi, ++i ) {
00130 os << "[" << i << "] " << *fi << std::endl;
00131 }
00132 os << "}";
00133 return os;
00134 }
00135
00136
00137
00138 std::ostream& operator<<( std::ostream& os, const GeMesh::FaceWrapper& face )
00139 {
00140 os << "{ vids={ "
00141 << face.getVertexId( 0 ) << ","
00142 << face.getVertexId( 1 ) << ","
00143 << face.getVertexId( 2 )
00144 << " }, tvids={ "
00145 << face.getTextureVertexId( 0 ) << ","
00146 << face.getTextureVertexId( 1 ) << ","
00147 << face.getTextureVertexId( 2 )
00148 << " } }";
00149 return os;
00150 }
00151
00152 FREECLOTH_NAMESPACE_END