[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 | |
---|
[5682] | 20 | #include "npc_test.h" |
---|
[5033] | 21 | #include "obb_tree.h" |
---|
[1853] | 22 | |
---|
[5266] | 23 | #include "shader.h" |
---|
[4984] | 24 | #include "state.h" |
---|
[5511] | 25 | #include "debug.h" |
---|
[4984] | 26 | |
---|
[9235] | 27 | #include "loading/factory.h" |
---|
| 28 | #include "loading/load_param.h" |
---|
[5511] | 29 | |
---|
[9235] | 30 | #include "effects/explosion.h" |
---|
[1853] | 31 | |
---|
[9869] | 32 | #include "class_id_DEPRECATED.h" |
---|
| 33 | ObjectListDefinitionID(NPC2, CL_NPC_TEST2); |
---|
| 34 | CREATE_FACTORY(NPC2); |
---|
[1858] | 35 | |
---|
[9235] | 36 | NPC2::NPC2(const TiXmlElement* root) |
---|
[8724] | 37 | : NPC(NULL) |
---|
[1931] | 38 | { |
---|
[9869] | 39 | this->registerObject(this, NPC2::_objectList); |
---|
[4976] | 40 | |
---|
[5621] | 41 | if ((float)rand()/RAND_MAX > .5f) |
---|
[9235] | 42 | this->loadModel("models/ships/bolido.obj", 6); |
---|
[5621] | 43 | else |
---|
[9235] | 44 | this->loadModel("models/ships/gobblin.obj", 6); |
---|
[5621] | 45 | |
---|
[9235] | 46 | |
---|
| 47 | |
---|
| 48 | |
---|
[5333] | 49 | this->shader = NULL; |
---|
[9869] | 50 | // if (likely(Shader::checkShaderAbility())) |
---|
| 51 | //this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag"); |
---|
[5059] | 52 | |
---|
[9235] | 53 | this->randomRotAxis = VECTOR_RAND(1); |
---|
[5266] | 54 | |
---|
[9235] | 55 | if (root != NULL) |
---|
| 56 | this->loadParams(root); |
---|
[1931] | 57 | } |
---|
[1853] | 58 | |
---|
[5034] | 59 | |
---|
[5267] | 60 | NPC2::~NPC2 () |
---|
[9869] | 61 | {} |
---|
[1853] | 62 | |
---|
[5267] | 63 | |
---|
[9235] | 64 | void NPC2::loadParams(const TiXmlElement* root) |
---|
| 65 | { |
---|
| 66 | NPC::loadParams(root); |
---|
[1931] | 67 | |
---|
[9235] | 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | void NPC2::destroy(WorldEntity* killer) |
---|
| 72 | { |
---|
| 73 | Explosion::explode(this, Vector(10,10,10)); |
---|
| 74 | this->toList(OM_DEAD); |
---|
| 75 | |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | |
---|
[5266] | 80 | /** |
---|
| 81 | * the entity is drawn onto the screen with this function |
---|
| 82 | * |
---|
| 83 | * This is a central function of an entity: call it to let the entity painted to the screen. |
---|
| 84 | * Just override this function with whatever you want to be drawn. |
---|
| 85 | */ |
---|
[5500] | 86 | void NPC2::draw() const |
---|
[4984] | 87 | { |
---|
[9235] | 88 | glMatrixMode(GL_MODELVIEW); |
---|
| 89 | glPushMatrix(); |
---|
| 90 | float matrix[4][4]; |
---|
| 91 | |
---|
| 92 | /* translate */ |
---|
| 93 | glTranslatef (this->getAbsCoor ().x, |
---|
| 94 | this->getAbsCoor ().y, |
---|
| 95 | this->getAbsCoor ().z); |
---|
| 96 | /* rotate */ |
---|
| 97 | this->getAbsDir ().matrix (matrix); |
---|
| 98 | glMultMatrixf((float*)matrix); |
---|
| 99 | |
---|
[6004] | 100 | // if (this->shader != NULL && this->shader != Shader::getActiveShader()) |
---|
| 101 | // shader->activateShader(); |
---|
[9235] | 102 | |
---|
| 103 | this->getModel()->draw(); |
---|
[6004] | 104 | // shader->deactivateShader(); |
---|
[9235] | 105 | |
---|
| 106 | |
---|
| 107 | /* if (this->model) |
---|
| 108 | this->model->draw();*/ |
---|
| 109 | glPopMatrix(); |
---|
[5266] | 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | void NPC2::tick(float dt) |
---|
| 114 | { |
---|
[5257] | 115 | // Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor()); |
---|
[2036] | 116 | |
---|
[4986] | 117 | //if (directin.len() < 100) |
---|
[5257] | 118 | // this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0)); |
---|
[9235] | 119 | // this->shiftDir(Quaternion(dt, this->randomRotAxis)); |
---|
[4986] | 120 | |
---|
[4984] | 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
[5033] | 124 | |
---|