main.cpp
上传用户:qccn516
上传日期:2013-05-02
资源大小:3382k
文件大小:19k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /* 3D Engine_v0.2 physic demo
  2.  *
  3.  * Copyright (C) 2003-2004, Alexander Zaprjagaev <frustum@frustum.org>
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  */
  19. #include <stdio.h>
  20. #include "glapp.h"
  21. #include "alapp.h"
  22. #include "engine.h"
  23. #include "console.h"
  24. #include "light.h"
  25. #include "flare.h"
  26. #include "particles.h"
  27. #include "object.h"
  28. #include "objectmesh.h"
  29. #include "objectskinnedmesh.h"
  30. #include "skinnedmesh.h"
  31. #include "ragdoll.h"
  32. #include "objectparticles.h"
  33. #include "texture.h"
  34. #include "rigidbody.h"
  35. #include "collide.h"
  36. #include "joint.h"
  37. #ifdef GRAB
  38. #include "video.h"
  39. #define WIDTH 400
  40. #define HEIGHT 300
  41. #else
  42. #define WIDTH 1024
  43. #define HEIGHT 768
  44. #endif
  45. /*
  46.  */
  47. class GLAppMain : public GLApp, ALApp {
  48. public:
  49. int init();
  50. void idle();
  51. void render();
  52. void keyPress(int key);
  53. float time;
  54. int pause_toggle; // state toggles
  55. int info_toggle;
  56. int flash_light_toggle;
  57. int robot_toggle;
  58. float phi,psi; // free camera parameters
  59. vec3 camera,speed,dir;
  60. Collide *collide;
  61. mat4 modelview; // view matrixes
  62. mat4 projection;
  63. Object *robot; // robot body
  64. JointHinge *j0,*j1,*j2,*j3; // wheel - robot body joints
  65. float angle; // direction
  66. float velocity; // velocity of the robot
  67. Light *flash_light; // flash light
  68. Light *shoot_light; // shoot light
  69. Sound *shoot_sound; // shoot sound
  70. ObjectParticles *shoot_particles; // particles
  71. Texture *cross_tex; // cross
  72. Object *lamp; // lamp
  73. Light *lamp_light; // lamp light
  74. #ifdef GRAB
  75. Video *video; // video grabber
  76. unsigned char *buffer;
  77. #endif
  78. };
  79. /*
  80.  */
  81. static void quit(int,char**,void*) {
  82. GLApp::exit();
  83. }
  84. static void help(int,char**,void*) {
  85. Engine::console->printf(0.77,1.0,0.15,
  86. "w,a,s,d - camera controln"
  87. "cursors - robot controln"
  88. "left mouse button - shootn"
  89. "n"
  90. "other keys:n"
  91. "'`' - console togglen"
  92. "n"
  93. "'h' - help togglen"
  94. "'i' - info togglen"
  95. "'f' - flash light togglen"
  96. "'r' - robot view togglen"
  97. "' ' - pause toggle"
  98. "n"
  99. "'1' - vertex lighting toggle //%sn"
  100. "'2' - Teylor toggle //%sn"
  101. "'3' - half angle specular toggle //%sn"
  102. "n"
  103. "('z'|'v'|'c')&middle button - add rigid body objectn"
  104. "n"
  105. "console commands:n"
  106. ""ls" - prints all variables and commandsn"
  107. ""set" - sets value of variablen"
  108. ""clear" - clears consolen",
  109. Engine::isDefine("VERTEX") ? "on" : "off",
  110. Engine::isDefine("TEYLOR") ? "on" : "off",
  111. Engine::isDefine("HALF") ? "on" : "off");
  112. }
  113. /*****************************************************************************/
  114. /*                                                                           */
  115. /* extern load                                                               */
  116. /*                                                                           */
  117. /*****************************************************************************/
  118. /*
  119.  */
  120. void extern_load(void *data) {
  121. GLAppMain *glapp = (GLAppMain*)data;
  122. { // robot
  123. ObjectMesh *mesh0,*mesh1,*mesh2,*mesh3,*mesh4;
  124. RigidBody *rb0,*rb1,*rb2,*rb3,*rb4;
  125. mesh0 = new ObjectMesh(Engine::loadMesh("robot_wheel.mesh"));
  126. mesh0->bindMaterial("*",Engine::loadMaterial("robot_wheel.mat"));
  127. mesh1 = new ObjectMesh(Engine::loadMesh("robot_wheel.mesh"));
  128. mesh1->bindMaterial("*",Engine::loadMaterial("robot_wheel.mat"));
  129. mesh2 = new ObjectMesh(Engine::loadMesh("robot_wheel.mesh"));
  130. mesh2->bindMaterial("*",Engine::loadMaterial("robot_wheel.mat"));
  131. mesh3 = new ObjectMesh(Engine::loadMesh("robot_wheel.mesh"));
  132. mesh3->bindMaterial("*",Engine::loadMaterial("robot_wheel.mat"));
  133. mesh4 = new ObjectMesh(Engine::loadMesh("robot.mesh"));
  134. mesh4->bindMaterial("robot",Engine::loadMaterial("robot_body.mat"));
  135. mesh4->bindMaterial("camera",Engine::loadMaterial("robot_camera.mat"));
  136. rb0 = new RigidBody(mesh0,10,0.1,0.6,RigidBody::COLLIDE_SPHERE | RigidBody::BODY_SPHERE);
  137. rb1 = new RigidBody(mesh1,10,0.1,0.6,RigidBody::COLLIDE_SPHERE | RigidBody::BODY_SPHERE);
  138. rb2 = new RigidBody(mesh2,10,0.1,0.6,RigidBody::COLLIDE_SPHERE | RigidBody::BODY_SPHERE);
  139. rb3 = new RigidBody(mesh3,10,0.1,0.6,RigidBody::COLLIDE_SPHERE | RigidBody::BODY_SPHERE);
  140. rb4 = new RigidBody(mesh4,10,0.2,0.2,RigidBody::COLLIDE_MESH | RigidBody::BODY_BOX);
  141. mesh0->setRigidBody(rb0);
  142. mesh1->setRigidBody(rb1);
  143. mesh2->setRigidBody(rb2);
  144. mesh3->setRigidBody(rb3);
  145. mesh4->setRigidBody(rb4);
  146. vec3 pos = vec3(-21,26,0.5);
  147. mesh0->set(vec3(0.549,-0.565,0) + pos);
  148. mesh1->set(vec3(-0.549,-0.565,0) + pos);
  149. mesh2->set(vec3(0.549,0.562,0) + pos);
  150. mesh3->set(vec3(-0.549,0.562,0) + pos);
  151. mesh4->set(vec3(0,0,0.15) + pos);
  152. glapp->j0 = new JointHinge(rb4,rb0,vec3(0.549,-0.565,0) + pos,vec3(1,0,0));
  153. glapp->j1 = new JointHinge(rb4,rb1,vec3(-0.549,-0.565,0) + pos,vec3(1,0,0));
  154. glapp->j2 = new JointHinge(rb4,rb2,vec3(0.549,0.562,0) + pos,vec3(1,0,0));
  155. glapp->j3 = new JointHinge(rb4,rb3,vec3(-0.549,0.562,0) + pos,vec3(1,0,0));
  156. Engine::addObject(mesh0);
  157. Engine::addObject(mesh1);
  158. Engine::addObject(mesh2);
  159. Engine::addObject(mesh3);
  160. Engine::addObject(mesh4);
  161. glapp->angle = 0;
  162. glapp->velocity = 0;
  163. glapp->robot = mesh4;
  164. }
  165. // flash light
  166. glapp->flash_light = new Light(vec3(0,0,0),15,vec4(1.0,1.0,1.0,1.0),0);
  167. glapp->flash_light->bindMaterial("*",Engine::loadMaterial("flash_light.mat"));
  168. // shoot light
  169. glapp->shoot_light = new Light(vec3(0,0,0),20,vec4(1.0,0.4,0.1,1.0));
  170. glapp->shoot_particles = new ObjectParticles(new Particles(128,Particles::OFF,0.3,0.3,vec3(0,0,-3),0.5,0.1,vec4(0.8,0.3,0.2,1.0)));
  171. glapp->shoot_particles->bindMaterial("*",Engine::loadMaterial("fire.mat"));
  172. Engine::addObject(glapp->shoot_particles);
  173. { // lamp 0
  174. ObjectSkinnedMesh *mesh = new ObjectSkinnedMesh("lamp/lamp.txt");
  175. mesh->bindMaterial("*",Engine::loadMaterial("default.mat"));
  176. mesh->setShadows(0);
  177. mesh->set(vec3(-4.975,31.403,2.92));
  178. Engine::addObject(mesh);
  179. RagDoll *ragdoll = new RagDoll(mesh->skinnedmesh,"lamp/lamp.conf");
  180. mesh->setRagDoll(ragdoll);
  181. glapp->lamp = mesh;
  182. glapp->lamp_light = new Light(vec3(0,0,1000),6,vec4(0.9,0.9,0.9,1.0));
  183. glapp->lamp_light->bindMaterial("*",Engine::loadMaterial("lamp_light.mat"));
  184. Engine::addLight(glapp->lamp_light);
  185. glapp->lamp_light->setFlare(new Flare(0,0.6,0.12));
  186. }
  187. { // ufo
  188. ObjectSkinnedMesh *mesh = new ObjectSkinnedMesh("ufo/ragdoll.txt");
  189. mesh->bindMaterial("*",Engine::loadMaterial("ufo_body.mat"));
  190. mesh->set(mat4(2,40,2) * mat4(1,0,0,45));
  191. Engine::addObject(mesh);
  192. RagDoll *ragdoll = new RagDoll(mesh->skinnedmesh,"ufo/ragdoll.conf");
  193. mesh->setRagDoll(ragdoll);
  194. }
  195. }
  196. /*****************************************************************************/
  197. /*                                                                           */
  198. /* init                                                                      */
  199. /*                                                                           */
  200. /*****************************************************************************/
  201. /*
  202.  */
  203. int GLAppMain::init() {
  204. // absolute minimum
  205. checkExtension("GL_ARB_vertex_program");
  206. checkExtension("GL_ARB_vertex_buffer_object");
  207. // toggles
  208. pause_toggle = 0;
  209. info_toggle = 0;
  210. flash_light_toggle = 0;
  211. robot_toggle = 0;
  212. // camera
  213. psi = 35.0;
  214. phi = 10.0;
  215. camera = vec3(-0.79,2.58,0.67);
  216. speed = vec3(0,0,0);
  217. collide = new Collide();
  218. // shoot
  219. shoot_sound = new Sound("data/fire.wav");
  220. cross_tex = new Texture("data/cross.tga",Texture::TEXTURE_2D,Texture::RGBA | Texture::LINEAR_MIPMAP_LINEAR);
  221. // engine
  222. Engine::addPath("data/,"
  223. "data/engine/,"
  224. "data/textures/,"
  225. "data/textures/cube/,"
  226. "data/materials/,"
  227. "data/shaders/,"
  228. "data/meshes/,"
  229. "data/physic/");
  230. if(Engine::init("data/engine.conf") == 0) return 0;
  231. Engine::console->addCommand("quit",quit);
  232. Engine::console->addCommand("help",help);
  233. Engine::setExternLoad(extern_load,this);
  234. Engine::load("physic.map");
  235. GLApp::error(); // errors
  236. ALApp::error();
  237. #ifdef GRAB
  238. video = new Video("video.mpg",WIDTH,HEIGHT,16000000);
  239. buffer = new unsigned char[WIDTH * HEIGHT * 4];
  240. #endif
  241. return 1;
  242. }
  243. /*****************************************************************************/
  244. /*                                                                           */
  245. /* render                                                                    */
  246. /*                                                                           */
  247. /*****************************************************************************/
  248. /*
  249.  */
  250. void GLAppMain::render() {
  251. glMatrixMode(GL_PROJECTION);
  252.     glLoadMatrixf(projection);
  253.     glMatrixMode(GL_MODELVIEW);
  254. glLoadMatrixf(modelview);
  255. // engine render
  256. Engine::update(pause_toggle ? 0 : ifps);
  257. Engine::render(ifps);
  258. // it`s all :)
  259. GLApp::error();
  260. ALApp::error();
  261. // cross
  262. if(!Engine::console->getActivity() && robot_toggle == 0) {
  263. glMatrixMode(GL_PROJECTION);
  264. glLoadIdentity();
  265. glOrtho(-30,30,-22.5,22.5,-1,1);
  266. glMatrixMode(GL_MODELVIEW);
  267. glLoadIdentity();
  268. glDepthFunc(GL_ALWAYS);
  269. glEnable(GL_BLEND);
  270. glBlendFunc(GL_SRC_ALPHA,GL_ONE);
  271. cross_tex->enable();
  272. cross_tex->bind();
  273. cross_tex->render();
  274. cross_tex->disable();
  275. glDisable(GL_BLEND);
  276. }
  277. #ifndef GRAB
  278. if(!Engine::console->getActivity()) {
  279. // fps
  280. Engine::console->enable(800,600);
  281. glColor3f(0.19,0.0,0.82);
  282. Engine::console->printf(9,9,"fps: %.0f",fps);
  283. glColor3f(0.77,1.0,0.15);
  284. Engine::console->printf(8,8,"fps: %.0f",fps);
  285. Engine::console->disable();
  286. // info
  287. if(info_toggle) {
  288. Engine::console->enable(1024,768);
  289. vec3 c = modelview.inverse() * vec3(0,0,0);
  290. glColor3f(0.19,0.0,0.82);
  291. Engine::console->printf(13,35,"triangles: %dnsectors %dnlights %dnrun "help" for more informationn%f %f %f",
  292. Engine::num_triangles,Bsp::num_visible_sectors,Engine::num_visible_lights,c.x,c.y,c.z);
  293. glColor3f(0.77,1.0,0.15);
  294. Engine::console->printf(12,34,"triangles: %dnsectors %dnlights %dnrun "help" for more informationn%f %f %f",
  295. Engine::num_triangles,Bsp::num_visible_sectors,Engine::num_visible_lights,c.x,c.y,c.z);
  296. Engine::console->disable();
  297. }
  298. glColor3f(1,1,1);
  299. }
  300. #endif
  301. #ifdef GRAB
  302. static float count = 0;
  303. count += ifps;
  304. if(count > 1.0 / 25.0) {
  305. glReadPixels(0,0,WIDTH,HEIGHT,GL_RGB,GL_UNSIGNED_BYTE,buffer);
  306. video->save(buffer,true);
  307. count -= 1.0 / 25.0;
  308. }
  309. #endif
  310. }
  311. /*****************************************************************************/
  312. /*                                                                           */
  313. /* idle                                                                      */
  314. /*                                                                           */
  315. /*****************************************************************************/
  316. /*
  317.  */
  318. void GLAppMain::idle() {
  319. time += ifps;
  320. // toggles
  321. if(!Engine::console->getActivity()) {
  322. if(keys[(int)' ']) {
  323. pause_toggle = !pause_toggle;
  324. keys[(int)' '] = 0;
  325. }
  326. if(keys[(int)'i']) {
  327. info_toggle = !info_toggle;
  328. keys[(int)'i'] = 0;
  329. }
  330. if(keys[(int)'f']) {
  331. flash_light_toggle = !flash_light_toggle;
  332. keys[(int)'f'] = 0;
  333. }
  334. if(keys[(int)'r']) {
  335. robot_toggle = !robot_toggle;
  336. keys[(int)'r'] = 0;
  337. }
  338. }
  339. // from camera
  340. static int look = 0;
  341. // shoot before camera
  342. if(robot_toggle == 0) {
  343. static int shoot = 0;
  344. static float shoot_time = 0;
  345. shoot_light->set(modelview.inverse());
  346. GLint state;
  347. alGetSourcei(shoot_sound->source,AL_SOURCE_STATE,&state);
  348. alSourcef(shoot_sound->source,AL_GAIN,0.1);
  349. if(state == AL_PLAYING) {
  350. float k = 1.0 - (time - shoot_time) * 4.0;
  351. if(k < 0) {
  352. Engine::removeLight(shoot_light);
  353. shoot_light->setColor(vec4(1.0,0.4,0.1,1.0));
  354. } else {
  355. shoot_light->setColor(vec4(1.0,0.4,0.1,1.0) * k);
  356. }
  357. }
  358. if(look && shoot == 0 && state != AL_PLAYING && mouseButton & BUTTON_LEFT) {
  359. vec3 point,normal;
  360. Object *object = Engine::intersection(camera,camera + dir * 1000,point,normal);
  361. shoot_sound->play();
  362. if(object) {
  363. if(object->rigidbody) {
  364. object->rigidbody->addImpulse(point,-normal * 100 * fabs(normal * dir));
  365. }
  366. shoot_particles->set(point - dir * 0.2);
  367. shoot_particles->setOffTime(0.2);
  368. shoot_time = time;
  369. Engine::addLight(shoot_light);
  370. }
  371. shoot = 1;
  372. } else {
  373. if(state != AL_PLAYING) shoot = 1;
  374. else shoot = 0;
  375. }
  376. if(!(mouseButton & BUTTON_LEFT)) shoot = 0;
  377. }
  378. // camera movement
  379. if(robot_toggle) { // robot view
  380. look = 0;
  381. modelview = mat4(0,0,1,180) * mat4(1,0,0,70) * mat4(0.0,0.25,-0.60) * robot->transform.inverse();
  382. projection.perspective(89,(float)windowWidth / (float)windowHeight,0.1,500);
  383. } else { // free camera
  384. mat4 m0,m1,m2;
  385. if(!look && mouseButton & BUTTON_LEFT) {
  386. setCursor(windowWidth / 2,windowHeight / 2);
  387. mouseX = windowWidth / 2;
  388. mouseY = windowHeight / 2;
  389. look = 1;
  390. }
  391. if(mouseButton & BUTTON_RIGHT) look = 0;
  392. if(look) {
  393. showCursor(0);
  394. psi += (mouseX - windowWidth / 2) * 0.2;
  395. phi += (mouseY - windowHeight / 2) * 0.2;
  396. if(phi < -89) phi = -89;
  397. if(phi > 89) phi = 89;
  398. setCursor(windowWidth / 2,windowHeight / 2);
  399. } else showCursor(1);
  400. float vel = 20;
  401. if(!Engine::console->getActivity()) {
  402. if(keys[(int)'w']) speed.x += vel * ifps;
  403. if(keys[(int)'s']) speed.x -= vel * ifps;
  404. if(keys[(int)'a']) speed.y -= vel * ifps;
  405. if(keys[(int)'d']) speed.y += vel * ifps;
  406. if(keys[KEY_SHIFT]) speed.z += vel * ifps;
  407. if(keys[KEY_CTRL]) speed.z -= vel * ifps;
  408. }
  409. speed -= speed * 5 * ifps;
  410. quat q0,q1;
  411. q0.set(vec3(0,0,1),-psi);
  412. q1.set(vec3(0,1,0),phi);
  413. dir = (q0 * q1).to_matrix() * vec3(1,0,0);
  414. vec3 x,y,z;
  415. x = dir;
  416. y.cross(dir,vec3(0,0,1));
  417. y.normalize();
  418. z.cross(y,x);
  419. camera += (x * speed.x + y * speed.y + z * speed.z) * ifps;
  420. for(int i = 0; i < 4; i++) {
  421. collide->collide(NULL,camera + (x * speed.x + y * speed.y + z * speed.z) * ifps / 4.0f,0.25);
  422. for(int j = 0; j < collide->num_contacts; j++) {
  423. camera += collide->contacts[j].normal * collide->contacts[j].depth / (float)collide->num_contacts;
  424. }
  425. }
  426. modelview.look_at(camera,camera + dir,vec3(0,0,1));
  427. projection.perspective(89,(float)windowWidth / (float)windowHeight,0.1,500);
  428. }
  429. // robot controls
  430. if(keys[KEY_UP]) velocity += ifps * 1;
  431. if(keys[KEY_DOWN]) velocity -= ifps * 1;
  432. velocity -= velocity * ifps;
  433. if(velocity > 1) velocity = 0.5;
  434. if(velocity < -1) velocity = -0.5;
  435. if(fabs(velocity) > 0.1) {
  436. j0->setAngularVelocity1(velocity);
  437. j1->setAngularVelocity1(velocity);
  438. j2->setAngularVelocity1(velocity);
  439. j3->setAngularVelocity1(velocity);
  440. }
  441. if(keys[KEY_LEFT]) angle += 80 * ifps;
  442. if(keys[KEY_RIGHT]) angle -= 80 * ifps;
  443. if(angle > 30) angle = 30;
  444. if(angle < -30) angle = -30;
  445. float rad,radius = 1.127f / tan(angle * DEG2RAD);
  446. rad = atan(1.127f / (radius - 0.549f));
  447. j0->setAxis0(vec3(cos(rad),sin(rad),0));
  448. j2->setAxis0(vec3(cos(rad),-sin(rad),0));
  449. rad = atan(1.127f / (radius + 0.549f));
  450. j1->setAxis0(vec3(cos(rad),sin(rad),0));
  451. j3->setAxis0(vec3(cos(rad),-sin(rad),0));
  452. // flash light
  453. static int flash = 0;
  454. flash_light->set(modelview.inverse());
  455. if(flash_light_toggle) {
  456. if(flash == 0) {
  457. Engine::addLight(flash_light);
  458. flash = 1;
  459. }
  460. } else {
  461. if(flash == 1) {
  462. Engine::removeLight(flash_light);
  463. flash = 0;
  464. }
  465. }
  466. // lamp
  467. ObjectSkinnedMesh *sm = reinterpret_cast<ObjectSkinnedMesh*>(lamp);
  468. lamp_light->set(sm->transform * sm->getBoneTransform(sm->getBone("end")) * mat4(0,0,-0.25));
  469. lamp->set(vec3(-4.975,31.403,3.1));
  470. // add object
  471. if(robot_toggle == 0) {
  472. mat4 m0,m1,m2,m3;
  473. m0.rotate(0,0,1,90);
  474. m1.rotate(0,1,0,-90);
  475. m2.translate(-2,0,0);
  476. m3.rotate(0,1,0,180);
  477. static Object *mesh = NULL;
  478. static int press = 0;
  479. if(mouseButton & BUTTON_MIDDLE) {
  480. if(!press) {
  481. if(keys[(int)'z']) {
  482. mesh = new ObjectMesh(Engine::loadMesh("box.mesh"));
  483. mesh->bindMaterial("*",Engine::loadMaterial("box.mat"));
  484. mesh->setRigidBody(new RigidBody(mesh,10,0.3,0.5,RigidBody::COLLIDE_MESH | RigidBody::BODY_BOX));
  485. Engine::addObject(mesh);
  486. mesh->set(modelview.inverse() * m0 * m1 * m2 * m3);
  487. press = 1;
  488. }
  489. if(keys[(int)'x']) {
  490. mesh = new ObjectMesh(Engine::loadMesh("barrel.mesh"));
  491. mesh->bindMaterial("*",Engine::loadMaterial("barrel.mat"));
  492. mesh->setRigidBody(new RigidBody(mesh,40,0.3,0.5,RigidBody::COLLIDE_MESH | RigidBody::BODY_CYLINDER));
  493. Engine::addObject(mesh);
  494. mesh->set(modelview.inverse() * m0 * m1 * m2 * m3);
  495. press = 1;
  496. }
  497. if(keys[(int)'c']) {
  498. mesh = new ObjectMesh(Engine::loadMesh("chair.mesh"));
  499. mesh->bindMaterial("*",Engine::loadMaterial("chair.mat"));
  500. mesh->setRigidBody(new RigidBody(mesh,20,0.3,0.5,RigidBody::COLLIDE_MESH | RigidBody::BODY_BOX));
  501. Engine::addObject(mesh);
  502. mesh->set(modelview.inverse() * m0 * m1 * m2 * m3);
  503. press = 1;
  504. }
  505. }
  506. }
  507. if(!(mouseButton & BUTTON_MIDDLE)) press = 0;
  508. else if(mesh) mesh->set(modelview.inverse() * m0 * m1 * m2 * m3);
  509. }
  510. // sound update
  511. ALApp::update();
  512. }
  513. /*
  514.  */
  515. void GLAppMain::keyPress(int key) {
  516. if(key == KEY_UP) Engine::console->keyPress('1');
  517. else if(key == KEY_DOWN) Engine::console->keyPress('2');
  518. else if(key == KEY_RETURN) Engine::console->keyPress('n');
  519. else if(key == KEY_BACKSPACE) Engine::console->keyPress('b');
  520. else if(key < 256) Engine::console->keyPress(key);
  521. if(Engine::console->getActivity()) return;
  522. if(key == '1') {
  523. if(Engine::isDefine("VERTEX")) Engine::undef("VERTEX");
  524. else Engine::define("VERTEX");
  525. Engine::reload();
  526. } else if(key == '2') {
  527. if(Engine::isDefine("TEYLOR")) Engine::undef("TEYLOR");
  528. else Engine::define("TEYLOR");
  529. Engine::reload();
  530. } else if(key == '3') {
  531. if(Engine::isDefine("HALF")) Engine::undef("HALF");
  532. else Engine::define("HALF");
  533. Engine::reload();
  534. }
  535. }
  536. /*****************************************************************************/
  537. /*                                                                           */
  538. /* main                                                                      */
  539. /*                                                                           */
  540. /*****************************************************************************/
  541. /*
  542.  */
  543. int main(int argc,char **argv) {
  544. GLAppMain *glApp = new GLAppMain();
  545. int w = WIDTH;
  546. int h = HEIGHT;
  547. int fs = 0;
  548. for(int i = 1; i < argc; i++) {
  549. if(!strcmp(argv[i],"-fs")) fs = 1;
  550. else if(!strcmp(argv[i],"-w")) sscanf(argv[++i],"%d",&w);
  551. else if(!strcmp(argv[i],"-h")) sscanf(argv[++i],"%d",&h);
  552. }
  553. if(glApp->setVideoMode(w,h,fs) == 0) return 0;
  554. glApp->setTitle("3D Engine demo v0.2 http://frustum.org");
  555. if(glApp->init() == 0) {
  556. delete glApp;
  557. return 0;
  558. }
  559. glApp->main();
  560. Engine::clear();
  561. delete glApp;
  562. return 0;
  563. }