00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013
00017
00019
00020
00021
00023
00024 #ifndef _ECCAMERA_H
00025 #define _ECCAMERA_H
00026
00027 #include <eclipseray/eclipse.h>
00028 #include <eclipseray/yrtypes.h>
00029
00030 class Mesh;
00031 class Film;
00032
00034
00039
00057
00059 class LightmapCamera : public YRCamera, public EclipseObject
00060 {
00061 DECLARE_PYTHON_HEADER;
00062
00063 public:
00064
00070 LightmapCamera( Film* a_pFilm, Mesh* a_pMesh );
00071
00072
00073
00074
00075
00081 static bool PyTypeCheck( PYOBJECT a_pObject );
00082
00088 virtual PYOBJECT PyAsString();
00089
00090
00091
00092
00093
00094
00095 virtual YRRay shootRay( YRPFloat px, YRPFloat py, float u, float v, YRPFloat &wt) const;
00096 virtual int resX() const { return m_nFilmWidth; }
00097 virtual int resY() const { return m_nFilmHeight; }
00098 virtual bool sampleLense() const {return false; }
00099
00100
00101
00102
00103
00104 struct sEdge
00105 {
00106 float LineEquation[2];
00107 int Triangles[2];
00108 int Points[2];
00109 bool ZeroTriangleSign;
00110 };
00111
00112 struct sSlab
00113 {
00114 sSlab( float a_fU ):FilmU(a_fU){}
00115 std::vector<sEdge> Edges;
00116 float FilmU;
00117 float NextSlabU;
00118 };
00119
00120 struct sTriangle
00121 {
00122 float BMatrix[4];
00123 int Points[3];
00124 YRuv UV;
00125 YRVector3D Normal;
00126 };
00127
00128
00129 protected:
00130
00131
00132 ~LightmapCamera();
00133
00139 virtual void DeleteObject();
00140
00141 private:
00142
00143
00144 bool PreProcessMesh();
00145
00146
00147 int GetSlab( float a_fFilmU ) const;
00148
00149
00150
00151 bool ConfigureEdge( sEdge& a_edge, YRuv& a_uv1, YRuv& a_uv2, int a_nFirstTriangle, int a_nP1, int a_nP2, YRuv& a_corner );
00152
00153
00154 sTriangle CalculateBarycentricTriangle( YRVector3D& a_vNormal, int a_p1, int a_p2, int a_p3, YRuv& a_uv1, YRuv& a_uv2, YRuv& a_uv3 );
00155
00156
00157 void InsertEdge( int a_nTriangleIndex, int a_nP1, int a_nP2, YRuv a_uv1, YRuv a_uv2, YRuv& a_corner );
00158
00159
00160
00161 bool QueryMap( YRPFloat a_fU, YRPFloat a_fV, YRPoint3D& a_vPoint, YRVector3D& a_vNormal ) const;
00162
00163 std::vector<sSlab> m_slabs;
00164 std::vector<sTriangle> m_triangles;
00165 int m_nFilmWidth;
00166 int m_nFilmHeight;
00167 Mesh* m_pMesh;
00168
00169
00170 static const int INVALID_ID = -1;
00171 };
00172
00173
00174 #endif