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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 int main(int argc, char *argv[])
00038 {
00039 unsigned width = 800;
00040 unsigned height = 600;
00041
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
00065
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
00095
00096 shape_creator.CreateCylinder(shape, 0.1f, 0.2f, 64, 2, true);
00097 shape.m_material = matBlueBlend;
00098
00099 tgRenderModel poly;
00100
00101
00102
00103
00104
00105
00106
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
00118 bool b = tgCollission::IntersectRayModel(pl, nl, zl, ray, shape);
00119
00120
00121
00122
00123
00124
00125
00126
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
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
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 glColor3f(1,1,1);
00180 render.PrintText2D("TomGine Render Engine", vec2(7,7), 12);
00181
00182 #ifdef LINUX
00183 usleep(5000);
00184 #endif
00185
00186 #ifdef WIN32
00187 Sleep(10);
00188 #endif
00189
00190 }
00191
00192 return 0;
00193 }
00194
00195
00196