Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9947 in orxonox.OLD for branches/ai


Ignore:
Timestamp:
Nov 22, 2006, 5:36:10 PM (18 years ago)
Author:
tfahrni
Message:
 
Location:
branches/ai/src/world_entities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/ai/src/world_entities/npcs/npc_test.cc

    r9869 r9947  
    1919
    2020#include "npc_test.h"
    21 #include "obb_tree.h"
    2221
    23 #include "shader.h"
     22
    2423#include "state.h"
    2524#include "debug.h"
     
    2827#include "loading/load_param.h"
    2928
    30 #include "effects/explosion.h"
     29#include "md2/md2Model.h"
     30#include "player.h"
     31#include "playable.h"
    3132
    3233#include "class_id_DEPRECATED.h"
    3334ObjectListDefinitionID(NPC2, CL_NPC_TEST2);
    3435CREATE_FACTORY(NPC2);
     36
    3537
    3638NPC2::NPC2(const TiXmlElement* root)
     
    3941  this->registerObject(this, NPC2::_objectList);
    4042
    41   if ((float)rand()/RAND_MAX > .5f)
    42     this->loadModel("models/ships/bolido.obj", 6);
    43   else
    44     this->loadModel("models/ships/gobblin.obj", 6);
    45 
    46 
    47 
    48 
    49   this->shader = NULL;
    50 //  if (likely(Shader::checkShaderAbility()))
    51     //this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag");
    52 
    53   this->randomRotAxis = VECTOR_RAND(1);
    5443
    5544  if (root != NULL)
     
    6958
    7059
    71 void NPC2::destroy(WorldEntity* killer)
     60
     61
     62
     63void NPC2::tick(float dt)
    7264{
    73   Explosion::explode(this, Vector(10,10,10));
    74   this->toList(OM_DEAD);
     65  // animating the md2 model (uninteressant)
     66  if( likely(this->getModel(0) != NULL))
     67    ((MD2Model*)this->getModel(0))->tick(dt);
     68
     69
     70
     71  PRINTF(0)("====================\n");
     72  PRINTF(0)("NPC2::tick(%f)\n", dt);
     73
     74  // information gathering
     75
     76  Vector absPosition = this->getAbsCoor();
     77
     78  PRINTF(0)(" npc abs coor: %f, %f, %f\n", absPosition.x, absPosition.y, absPosition.z);
     79
     80  Player* pl = State::getPlayer();
     81  Vector playerAbsPos = pl->getPlayable()->getAbsCoor();
     82
     83  PRINTF(0)(" player abs coor: %f, %f, %f\n", playerAbsPos.x, playerAbsPos.y, playerAbsPos.z);
     84
     85
     86  // intelligent reaction
     87
     88  Vector distanceVector = playerAbsPos - absPosition;
     89  distanceVector.normalize();
     90
     91  float speed = 10.0f;
     92
     93  this->shiftCoor( distanceVector * speed * dt);
     94
     95
    7596
    7697}
     
    7899
    79100
    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  */
    86 void NPC2::draw() const
    87 {
    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 
    100 //   if (this->shader != NULL && this->shader != Shader::getActiveShader())
    101 //     shader->activateShader();
    102 
    103   this->getModel()->draw();
    104 //   shader->deactivateShader();
    105 
    106 
    107 /*  if (this->model)
    108     this->model->draw();*/
    109   glPopMatrix();
    110 }
    111 
    112 
    113 void NPC2::tick(float dt)
    114 {
    115 //  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
    116 
    117   //if (directin.len() < 100)
    118 //  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0));
    119 //  this->shiftDir(Quaternion(dt, this->randomRotAxis));
    120 
    121 }
    122 
    123 
    124 
  • branches/ai/src/world_entities/npcs/npc_test.h

    r9869 r9947  
    1717  virtual void loadParams(const TiXmlElement* root);
    1818
    19   void addAI(AI* ai);
    20 
    21   virtual void destroy(WorldEntity* killer);
    2219
    2320  virtual void tick(float dt);
    24   virtual void draw() const;
    2521
    2622 private:
    27    Vector   randomRotAxis;
    28    Shader*  shader;
     23
    2924};
    3025
  • branches/ai/src/world_entities/space_ships/spacecraft_2d.cc

    r9869 r9947  
    272272{
    273273  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
    274   this->setPlaymode(this->getPlaymode());
     274//  this->setPlaymode(this->getPlaymode());
     275  this->setPlaymode( Playable::Horizontal);
     276  this->setTravelSpeed( 10.0);
     277
    275278}
    276279
Note: See TracChangeset for help on using the changeset viewer.