Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/heathaze/src/world_entities/npcs/attractor_mine.cc

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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,
40                        addMethod("setName", Executor1<BaseObject, lua_State*,const std::string&>(&BaseObject::setName))
41                        //Coordinates
42                        ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor))
43                        ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX))
44                        ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))
45                        ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, 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}
81
82void AttractorMine::loadParams(const TiXmlElement* root)
83{
84  NPC::loadParams(root);
85
86}
87
88
89void AttractorMine::destroy(WorldEntity* killer)
90{
91  Explosion::explode(this, Vector(10,10,10));
92  this->toList(OM_DEAD);
93
94}
95
96
97
98/**
99 *  the entity is drawn onto the screen with this function
100 *
101 * This is a central function of an entity: call it to let the entity painted to the screen.
102 * Just override this function with whatever you want to be drawn.
103 */
104void AttractorMine::draw() const
105{
106  glMatrixMode(GL_MODELVIEW);
107  glPushMatrix();
108  float matrix[4][4];
109
110  /* translate */
111  glTranslatef (this->getAbsCoor ().x,
112                this->getAbsCoor ().y,
113                this->getAbsCoor ().z);
114  /* rotate */
115  this->getAbsDir ().matrix (matrix);
116  glMultMatrixf((float*)matrix);
117
118  //   if (this->shader != NULL && this->shader != Shader::getActiveShader())
119  //     shader->activateShader();
120
121  this->getModel()->draw();
122  //   shader->deactivateShader();
123
124
125  /*  if (this->model)
126      this->model->draw();*/
127  glPopMatrix();
128}
129
130
131void AttractorMine::tick(float dt)
132{
133  PNode* attractNode = State::getPlayer()->getPlayable();
134  if (attractNode != NULL)
135  {
136    if (this->distance(attractNode) < 80)
137    {
138      Vector dist = (attractNode->getAbsCoor() -  this->getAbsCoor());
139      float distance = dist.len();
140      this->velocity += dist * (( 250.0 - distance) / distance * dt);
141    }
142  }
143
144  this->shiftCoor(this->velocity * dt);
145
146  //  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
147
148  //if (directin.len() < 100)
149  //  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0));
150  this->shiftDir(Quaternion(.5 * dt, this->randomRotAxis));
151
152}
153
154
155
Note: See TracBrowser for help on using the repository browser.