Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/npcs/attractor_mine.cc @ 9575

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

merged the presentation back

File size: 3.7 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#include "script_class.h"
37CREATE_SCRIPTABLE_CLASS(AttractorMine, CL_ATTRACTOR_MINE,
38                        addMethod("setName", ExecutorLua1<BaseObject,const std::string&>(&BaseObject::setName))
39                       //Coordinates
40                        ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
41                        ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
42                        ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
43                        ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
44                       );
45
46
47
48
49AttractorMine::AttractorMine(const TiXmlElement* root)
50    : NPC(NULL)
51{
52  this->setClassID(CL_ATTRACTOR_MINE, "AttractorMine");
53
54  this->toList(OM_GROUP_02);
55
56  if ((float)rand()/RAND_MAX > .5f)
57    this->loadModel("models/ships/noxon_battle_drone.obj", .3);
58  else
59    this->loadModel("models/ships/noxon_battle_drone.obj", .2);
60
61  this->setDamage(30.0f);
62
63
64
65  this->shader = NULL;
66  if (likely(Shader::checkShaderAbility()))
67    this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag");
68
69  this->randomRotAxis = VECTOR_RAND(1);
70
71  if (root != NULL)
72    this->loadParams(root);
73}
74
75
76AttractorMine::~AttractorMine ()
77{
78  if (this->shader)
79    Shader::unload(this->shader);
80}
81
82
83void AttractorMine::loadParams(const TiXmlElement* root)
84{
85  NPC::loadParams(root);
86
87}
88
89
90void AttractorMine::destroy(WorldEntity* killer)
91{
92  Explosion::explode(this, Vector(10,10,10));
93  this->toList(OM_DEAD);
94
95}
96
97
98
99/**
100 *  the entity is drawn onto the screen with this function
101 *
102 * This is a central function of an entity: call it to let the entity painted to the screen.
103 * Just override this function with whatever you want to be drawn.
104 */
105void AttractorMine::draw() const
106{
107  glMatrixMode(GL_MODELVIEW);
108  glPushMatrix();
109  float matrix[4][4];
110
111  /* translate */
112  glTranslatef (this->getAbsCoor ().x,
113                this->getAbsCoor ().y,
114                this->getAbsCoor ().z);
115  /* rotate */
116  this->getAbsDir ().matrix (matrix);
117  glMultMatrixf((float*)matrix);
118
119  //   if (this->shader != NULL && this->shader != Shader::getActiveShader())
120  //     shader->activateShader();
121
122  this->getModel()->draw();
123  //   shader->deactivateShader();
124
125
126  /*  if (this->model)
127      this->model->draw();*/
128  glPopMatrix();
129}
130
131
132void AttractorMine::tick(float dt)
133{
134  PNode* attractNode = State::getPlayer()->getPlayable();
135  if (attractNode != NULL)
136  {
137    if (this->distance(attractNode) < 80)
138    {
139      Vector dist = (attractNode->getAbsCoor() -  this->getAbsCoor());
140      float distance = dist.len();
141      this->velocity += dist * (( 250.0 - distance) / distance * dt);
142    }
143  }
144
145  this->shiftCoor(this->velocity * dt);
146
147  //  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
148
149  //if (directin.len() < 100)
150  //  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0));
151  this->shiftDir(Quaternion(.5 * dt, this->randomRotAxis));
152
153}
154
155
156
Note: See TracBrowser for help on using the repository browser.