Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/world_entities/npcs/attractor_mine.cc @ 9716

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

more renamings

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