$search
00001 00009 #include <stdio.h> 00010 00011 #include <blort/TomGine/tgEngine.h> 00012 #include <blort/TomGine/tgRenderModel.h> 00013 #include <blort/TomGine/tgModelLoader.h> 00014 #include <blort/TomGine/tgShapeCreator.h> 00015 #include <blort/TomGine/tgCollission.h> 00016 #include <blort/TomGine/tgFont.h> 00017 00018 #include <time.h> 00019 00020 using namespace TomGine; 00021 using namespace std; 00022 00023 typedef vector<vec3> PointList; 00024 00025 // float avgI16FB(int x, int y, unsigned res, tgTexture &tex){ 00026 // int lvl = ilog2(res)+1; 00027 // glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY16, x, y, res, res, 0); 00028 // 00029 // float pix[4] = {0,0,0,0}; 00030 // glGetTexImage(GL_TEXTURE_2D, lvl-1, GL_RED, GL_FLOAT, pix); 00031 // float avg = 0; 00032 // for(unsigned i=0; i<4; i++) 00033 // avg += 0.25 * pix[i]; 00034 // return avg; 00035 // } 00036 00037 int main(int argc, char *argv[]) 00038 { 00039 unsigned width = 800; 00040 unsigned height = 600; 00041 // char avg_time[128]; 00042 tgEngine render(width,height, 1.0f, 0.1f, "TomGine Render Engine", true); 00043 00044 printf("\n Demo TomGine\n\n"); 00045 00046 printf(" TomGine control\n"); 00047 printf(" -------------------------------------------\n"); 00048 printf(" [Left Mouse Button] Rotate\n"); 00049 printf(" [Right Mouse Button] Move\n"); 00050 printf(" [Scroll Wheel] Zoom\n"); 00051 printf(" [w] Switch to wireframe mode\n"); 00052 printf(" [f] Switch to flat/smooth shading\n"); 00053 printf(" \n\n"); 00054 00055 srand(time(NULL)); 00056 float fTime; 00057 tgTimer timer; 00058 PointList m_points; 00059 vec3 v; 00060 tgShapeCreator shape_creator; 00061 00062 printf("[TomGine/main.cpp] Warning HARDCODED font file\n"); 00063 00064 // Load Model 00065 // for more materials visit: http://wiki.delphigl.com/index.php/Materialsammlung 00066 tgMaterial matSilver; 00067 matSilver.ambient = vec4(0.19f,0.19f,0.19f,1.0f); 00068 matSilver.diffuse = vec4(0.51f,0.51f,0.51f,1.0f); 00069 matSilver.specular = vec4(0.77f,0.77f,0.77f,1.0f); 00070 matSilver.shininess = 51.2f; 00071 00072 tgMaterial matRed; 00073 matRed.Color(1.0f, 0.0f, 0.0f); 00074 00075 tgMaterial matBlueBlend; 00076 matBlueBlend.Color(0.0f, 0.0f, 1.0f, 0.5f); 00077 00078 tgRenderModel camera; 00079 tgRenderModel camera2; 00080 tgModelLoader loader; 00081 printf("[TomGine/main.cpp] Warning HARDCODED ply file\n"); 00082 loader.LoadPly(camera, "../Resources/ply/camera.ply"); 00083 loader.LoadPly(camera2, "../Resources/ply/camera.ply"); 00084 00085 camera.m_material = matRed; 00086 camera.m_pose.t = vec3(0.0f,0.1f,0.0f); 00087 camera.ComputeBoundingSphere(); 00088 00089 camera2.m_pose.t = vec3(0.1f,0.1f,0.0f); 00090 camera2.ComputeBoundingSphere(); 00091 00092 tgRenderModel shape; 00093 00094 // shape_creator.CreateSphere(shape, 0.05, 3, ICOSAHEDRON); 00095 // shape_creator.CreateBox(shape, 0.1,0.1,0.1); 00096 shape_creator.CreateCylinder(shape, 0.1f, 0.2f, 64, 2, true); 00097 shape.m_material = matBlueBlend; 00098 00099 tgRenderModel poly; 00100 // std::vector<vec3> pointlist; 00101 // pointlist.push_back(vec3(0.1f,0.01f,-0.1f)); 00102 // pointlist.push_back(vec3(0.00f,0.0,-0.03f)); 00103 // pointlist.push_back(vec3(-0.1f,0.01f,-0.1f)); 00104 // pointlist.push_back(vec3(0.0f,0.01f,0.2f)); 00105 // shape_creator.TriangulatePolygon(poly, pointlist); 00106 // poly.ComputeFaceNormals(); 00107 00108 tgRay ray; 00109 ray.start = render.GetCameraPosition(); 00110 ray.dir = vec3(0.01f,0.0f,0.0f) - (render.GetCameraPosition()*2.0f); 00111 00112 vec3 p; 00113 std::vector<vec3> pl; 00114 std::vector<vec3> nl; 00115 std::vector<double> zl; 00116 00117 // bool b = tgCollission::IntersectRayTriangle(p, z, ray, pointlist[0], pointlist[1], pointlist[2]); 00118 bool b = tgCollission::IntersectRayModel(pl, nl, zl, ray, shape); 00119 00120 // tgTexture tex; 00121 // glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); 00122 // tex.Load("../Resources/img/smiley.jpg"); 00123 00124 //tgFont m_font; 00125 00126 // Rendering loop 00127 while(render.Update(fTime=timer.Update())){ 00128 00129 glDisable(GL_LIGHTING); 00130 glBegin(GL_LINES); 00131 glVertex3f(ray.start.x, ray.start.y, ray.start.z); 00132 glVertex3f(ray.start.x + ray.dir.x, ray.start.y + ray.dir.y, ray.start.z + ray.dir.z); 00133 glEnd(); 00134 glDisable(GL_TEXTURE_2D); 00135 00136 render.Activate3D(); 00137 for(unsigned int i=0; i< pl.size(); i++) 00138 { 00139 glDisable(GL_DEPTH_TEST); 00140 glPointSize(3); 00141 glBegin(GL_POINTS); 00142 glColor3f(1.0f-b,b,0.0f); 00143 glVertex3f(pl[i].x, pl[i].y, pl[i].z); 00144 glEnd(); 00145 glEnable(GL_DEPTH_TEST); 00146 } 00147 glEnable(GL_LIGHTING); 00148 00149 //poly.DrawFaces(); 00150 camera.m_pose.Rotate(0.0f,3.14f*fTime, 0.0f); 00151 glColor3f(1,1,1); 00152 if(tgCollission::IntersectModels(camera, camera2)) 00153 render.PrintText2D("collission", vec2(50,50)); 00154 00155 camera.DrawFaces(); 00156 camera2.DrawFaces(); 00157 glEnable(GL_BLEND); 00158 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00159 matBlueBlend.Apply(); 00160 camera.DrawBoundingSphere(); 00161 camera2.DrawBoundingSphere(); 00162 shape.DrawFaces(); 00163 glDisable(GL_BLEND); 00164 00165 glColor3f(1,1,1); 00166 render.PrintText3D("Logitech", camera.m_pose.t); 00167 00168 // Super fast calculation of average 00169 // render.Activate2D(); 00170 // timer.Update(); 00171 // glEnable(GL_TEXTURE_2D); 00172 // tgTexture tex; 00173 // for(unsigned i=0; i<100; i++){ 00174 // avgI16FB(x,y,res,tex); 00175 // } 00176 // sprintf(avg_time, "Averaging time: %.0f ms", timer.Update() * 1000); 00177 // m_font.Print(avg_time, 18, width - 200, 7); 00178 00179 glColor3f(1,1,1); 00180 render.PrintText2D("TomGine Render Engine", vec2(7,7), 12); 00181 00182 #ifdef LINUX 00183 usleep(5000); // not to overload GPU 00184 #endif 00185 00186 #ifdef WIN32 00187 Sleep(10); 00188 #endif 00189 00190 } 00191 00192 return 0; 00193 } 00194 00195 00196