Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/npcs/attractor_mine.cc @ 9175

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

better stuff

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