| [1853] | 1 |  | 
|---|
 | 2 |  | 
|---|
| [4597] | 3 | /* | 
|---|
| [1853] | 4 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
 | 5 |  | 
|---|
 | 6 |    Copyright (C) 2004 orx | 
|---|
 | 7 |  | 
|---|
 | 8 |    This program is free software; you can redistribute it and/or modify | 
|---|
 | 9 |    it under the terms of the GNU General Public License as published by | 
|---|
 | 10 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
 | 11 |    any later version. | 
|---|
| [1855] | 12 |  | 
|---|
 | 13 |    ### File Specific: | 
|---|
 | 14 |    main-programmer: Patrick Boenzli | 
|---|
 | 15 |    co-programmer: | 
|---|
| [1853] | 16 | */ | 
|---|
| [5357] | 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY | 
|---|
| [1853] | 18 |  | 
|---|
 | 19 |  | 
|---|
| [5266] | 20 | #include "npc2.h" | 
|---|
| [5033] | 21 | #include "obb_tree.h" | 
|---|
| [1853] | 22 |  | 
|---|
| [5266] | 23 | #include "shader.h" | 
|---|
| [4984] | 24 | #include "state.h" | 
|---|
| [5064] | 25 | #include "list.h" | 
|---|
| [5427] | 26 | #include "stdlibincl.h" | 
|---|
| [4984] | 27 |  | 
|---|
| [1858] | 28 | using namespace std; | 
|---|
| [1853] | 29 |  | 
|---|
| [1858] | 30 |  | 
|---|
| [5266] | 31 | NPC2::NPC2() | 
|---|
| [1931] | 32 | { | 
|---|
| [4597] | 33 |   this->setClassID(CL_NPC, "NPC"); | 
|---|
| [4976] | 34 |  | 
|---|
| [5266] | 35 |   this->loadModelWithScale("models/ships/bolido.obj", 3); | 
|---|
| [5333] | 36 |   this->shader = NULL; | 
|---|
 | 37 |   if (likely(Shader::checkShaderAbility())) | 
|---|
 | 38 |     this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag"); | 
|---|
| [5059] | 39 |  | 
|---|
| [5266] | 40 |   this->obj = gluNewQuadric(); | 
|---|
 | 41 |  | 
|---|
| [5059] | 42 |   this->randomRotAxis = VECTOR_RAND(1); | 
|---|
| [1931] | 43 | } | 
|---|
| [1853] | 44 |  | 
|---|
| [5034] | 45 |  | 
|---|
| [5267] | 46 | NPC2::~NPC2 () | 
|---|
 | 47 | { | 
|---|
| [5363] | 48 |   if (this->shader) | 
|---|
 | 49 |     Shader::unload(this->shader); | 
|---|
| [5313] | 50 |   gluDeleteQuadric(this->obj); | 
|---|
| [5267] | 51 | } | 
|---|
| [1853] | 52 |  | 
|---|
| [5267] | 53 |  | 
|---|
| [5266] | 54 | void NPC2::collidesWith(WorldEntity* entity, const Vector& location) | 
|---|
| [5029] | 55 | { | 
|---|
| [5053] | 56 |   if (entity->isA(CL_PROJECTILE)) | 
|---|
| [5258] | 57 |   { | 
|---|
| [5065] | 58 |     PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z); | 
|---|
| [5258] | 59 |     this->applyForce(Vector(0,0,0)-location*1000); | 
|---|
 | 60 |   } | 
|---|
| [5259] | 61 |   else if (entity->isA(CL_PLAYER)) | 
|---|
 | 62 |     this->applyForce(Vector(0,0,0)-location*100); | 
|---|
 | 63 |   else | 
|---|
| [5258] | 64 |   { | 
|---|
 | 65 |     this->setVisibiliy(false); | 
|---|
 | 66 |    State::getWorldEntityList()->remove(this); | 
|---|
 | 67 |   } | 
|---|
| [1931] | 68 | } | 
|---|
 | 69 |  | 
|---|
| [5029] | 70 |  | 
|---|
| [5266] | 71 | /** | 
|---|
 | 72 |  *  the entity is drawn onto the screen with this function | 
|---|
 | 73 |  * | 
|---|
 | 74 |  * This is a central function of an entity: call it to let the entity painted to the screen. | 
|---|
 | 75 |  * Just override this function with whatever you want to be drawn. | 
|---|
 | 76 |  */ | 
|---|
 | 77 | void NPC2::draw() | 
|---|
| [4984] | 78 | { | 
|---|
| [5266] | 79 |   glMatrixMode(GL_MODELVIEW); | 
|---|
 | 80 |   glPushMatrix(); | 
|---|
 | 81 |   float matrix[4][4]; | 
|---|
 | 82 |  | 
|---|
 | 83 |   /* translate */ | 
|---|
 | 84 |   glTranslatef (this->getAbsCoor ().x, | 
|---|
 | 85 |                 this->getAbsCoor ().y, | 
|---|
 | 86 |                 this->getAbsCoor ().z); | 
|---|
 | 87 |   /* rotate */ | 
|---|
 | 88 |   this->getAbsDir ().matrix (matrix); | 
|---|
 | 89 |   glMultMatrixf((float*)matrix); | 
|---|
 | 90 |  | 
|---|
| [5323] | 91 |   if (this->shader != NULL && this->shader != Shader::getActiveShader()) | 
|---|
 | 92 |     shader->activateShader(); | 
|---|
| [5268] | 93 |   gluSphere(this->obj, 3, 10, 10); | 
|---|
| [5333] | 94 |   shader->deactivateShader(); | 
|---|
| [5266] | 95 |  | 
|---|
 | 96 |  | 
|---|
 | 97 | /*  if (this->model) | 
|---|
 | 98 |     this->model->draw();*/ | 
|---|
 | 99 |   glPopMatrix(); | 
|---|
 | 100 | } | 
|---|
 | 101 |  | 
|---|
 | 102 |  | 
|---|
 | 103 | void NPC2::tick(float dt) | 
|---|
 | 104 | { | 
|---|
| [5257] | 105 | //  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor()); | 
|---|
| [2036] | 106 |  | 
|---|
| [4986] | 107 |   //if (directin.len() < 100) | 
|---|
| [5257] | 108 | //  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0)); | 
|---|
| [5060] | 109 |   this->shiftDir(Quaternion(dt, this->randomRotAxis)); | 
|---|
| [4986] | 110 |  | 
|---|
| [4984] | 111 | } | 
|---|
 | 112 |  | 
|---|
 | 113 |  | 
|---|
| [5033] | 114 |  | 
|---|