Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/world_entities/npcs/npc_test.cc @ 5913

Last change on this file since 5913 was 5750, checked in by bensch, 19 years ago

orxonox/trunk: merged the WorldEntities into the Trunk.
Merged with command:
svn merge branches/world_entities/ trunk/ -r5516:HEAD

conflics from world_entities changed in favor of branches/world_entity
all other conflict in favor of the trunk

File size: 2.6 KB
Line 
1
2
3/*
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.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
19
20#include "npc_test.h"
21#include "obb_tree.h"
22
23#include "shader.h"
24#include "state.h"
25#include "list.h"
26#include "stdlibincl.h"
27#include "debug.h"
28
29
30using namespace std;
31
32
33NPC2::NPC2()
34{
35  this->setClassID(CL_NPC, "NPC");
36
37  if ((float)rand()/RAND_MAX > .5f)
38    this->loadModel("models/ships/bolido.obj", 3);
39  else
40    this->loadModel("models/ships/gobblin.obj", 3);
41
42  this->shader = NULL;
43  if (likely(Shader::checkShaderAbility()))
44    this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag");
45
46  this->obj = gluNewQuadric();
47
48  this->randomRotAxis = VECTOR_RAND(1);
49}
50
51
52NPC2::~NPC2 ()
53{
54  if (this->shader)
55    Shader::unload(this->shader);
56  gluDeleteQuadric(this->obj);
57}
58
59
60void NPC2::collidesWith(WorldEntity* entity, const Vector& location)
61{
62  if (entity->isA(CL_PROJECTILE))
63  {
64    PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z);
65    this->applyForce(Vector(0,0,0)-location*1000);
66  }
67  else if (entity->isA(CL_PLAYER))
68    this->applyForce(Vector(0,0,0)-location*100);
69  else
70  {
71    this->setVisibiliy(false);
72   State::getWorldEntityList()->remove(this);
73  }
74}
75
76
77/**
78 *  the entity is drawn onto the screen with this function
79 *
80 * This is a central function of an entity: call it to let the entity painted to the screen.
81 * Just override this function with whatever you want to be drawn.
82 */
83void NPC2::draw() const
84{
85  glMatrixMode(GL_MODELVIEW);
86  glPushMatrix();
87  float matrix[4][4];
88
89  /* translate */
90  glTranslatef (this->getAbsCoor ().x,
91                this->getAbsCoor ().y,
92                this->getAbsCoor ().z);
93  /* rotate */
94  this->getAbsDir ().matrix (matrix);
95  glMultMatrixf((float*)matrix);
96
97  if (this->shader != NULL && this->shader != Shader::getActiveShader())
98    shader->activateShader();
99  gluSphere(this->obj, 3, 10, 10);
100  shader->deactivateShader();
101
102
103/*  if (this->model)
104    this->model->draw();*/
105  glPopMatrix();
106}
107
108
109void NPC2::tick(float dt)
110{
111//  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
112
113  //if (directin.len() < 100)
114//  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0));
115  this->shiftDir(Quaternion(dt, this->randomRotAxis));
116
117}
118
119
120
Note: See TracBrowser for help on using the repository browser.