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