Blender  V2.59
main.cpp
Go to the documentation of this file.
00001 
00029 #include "BSP_GhostTest3D.h"
00030 
00031 #include "BSP_TMesh.h"
00032 #include "MEM_SmartPtr.h"
00033 #include "BSP_PlyLoader.h"
00034 
00035 #include <iostream>
00036 
00037 using namespace std;
00038 #if 1
00039         MEM_SmartPtr<BSP_TMesh> 
00040 NewTestMesh(
00041         int x,
00042         int y,
00043         MT_Scalar fx,
00044         MT_Scalar fy,
00045         MT_Scalar ampx,
00046         MT_Scalar ampy,
00047         MT_Scalar sx,
00048         MT_Scalar sy
00049 ) {
00050 
00051         MEM_SmartPtr<BSP_TMesh> output = new BSP_TMesh;
00052 
00053         std::vector<BSP_TVertex> &verts = output->VertexSet();
00054 
00055         int i,j;
00056 
00057         MT_Scalar x_scale = fx*MT_PI/x;
00058         MT_Scalar y_scale = fy*MT_PI/y;
00059 
00060         MT_Scalar fsx = sx/x;
00061         MT_Scalar fsy = sy/y;
00062 
00063         for (j = 0; j < y; j++) {
00064                 for (i = 0; i < x; i++) {
00065                         float z = ampx*sin(x_scale * i) + ampy*sin(y_scale * j);
00066 
00067                         MT_Vector3 val(i*fsx - sx/2,j*fsy - sy/2,z);
00068 
00069                         BSP_TVertex chuff;
00070                         chuff.m_pos = val;
00071                         verts.push_back(chuff);
00072                 }
00073         }
00074 
00075         int poly[4];
00076 
00077         for (j = 0; j < (y-1); j++) {
00078                 for (i = 0; i < (x-1); i++) {
00079 
00080                         poly[0] = j*x + i;
00081                         poly[1] = poly[0] + 1;
00082                         poly[2] = poly[1] + y;
00083                         poly[3] = poly[2] -1;
00084 
00085                         output->AddFace(poly,4);
00086                 }
00087         }
00088 
00089         output->m_min = MT_Vector3(-sx/2,-sy/2,-ampx -ampy);
00090         output->m_max = MT_Vector3(sx/2,sy/2,ampx + ampy);
00091 
00092         return output;
00093 }
00094 #endif
00095 
00096 
00097 int main() {
00098 
00099         MT_Vector3 min,max;
00100         MT_Vector3 min2,max2;
00101 
00102 #if 1
00103         MEM_SmartPtr<BSP_TMesh> mesh1 = BSP_PlyLoader::NewMeshFromFile("bsp_cube.ply",min,max);
00104         MEM_SmartPtr<BSP_TMesh> mesh2 = BSP_PlyLoader::NewMeshFromFile("bsp_cube.ply",min2,max2);
00105 
00106         mesh1->m_min = min;
00107         mesh1->m_max = max;
00108         mesh2->m_min = min2;
00109         mesh1->m_max = max2;
00110 
00111 #else
00112         MEM_SmartPtr<BSP_TMesh> mesh1 = NewTestMesh(10,10,2,2,4,4,20,20);
00113         MEM_SmartPtr<BSP_TMesh> mesh2 = NewTestMesh(10,10,2,2,4,4,20,20);
00114 #endif  
00115 
00116         if (!mesh1) {
00117                 cout << "could not load mesh!";
00118                 return 0;
00119         }
00120 
00121 
00122 
00123 //      MEM_SmartPtr<BSP_TMesh> mesh2 = new BSP_TMesh(mesh1.Ref());
00124 
00125         BSP_GhostTestApp3D app;
00126 
00127         cout << "Mesh polygons :" << mesh1->FaceSet().size() << "\n";
00128         cout << "Mesh vertices :" << mesh1->VertexSet().size() << "\n";
00129 
00130         app.SetMesh(mesh1);
00131         app.SetMesh(mesh2);
00132 
00133 
00134         app.InitApp();
00135         
00136         app.Run();
00137 
00138     return 0;
00139 
00140 }
00141 
00142 
00143 
00144