Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/npcs/npc_test.cc @ 9168

Last change on this file since 9168 was 9164, checked in by bensch, 18 years ago

better npc

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