Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged the presentation back

File size: 3.7 KB
RevLine 
[1853]1
2
[4597]3/*
[1853]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.
[1855]12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:
[1853]16*/
[5357]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
[1853]18
19
[9173]20#include "attractor_mine.h"
[1853]21
[9173]22
[5266]23#include "shader.h"
[4984]24#include "state.h"
[5511]25#include "debug.h"
[4984]26
[9175]27#include "player.h"
28#include "playable.h"
29
[9161]30#include "loading/factory.h"
31#include "loading/load_param.h"
[5511]32
[9164]33#include "effects/explosion.h"
34
[9173]35CREATE_FACTORY(AttractorMine, CL_ATTRACTOR_MINE);
[9178]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                       );
[1853]45
[1858]46
[9178]47
48
[9173]49AttractorMine::AttractorMine(const TiXmlElement* root)
[9175]50    : NPC(NULL)
[1931]51{
[9173]52  this->setClassID(CL_ATTRACTOR_MINE, "AttractorMine");
[4976]53
[9179]54  this->toList(OM_GROUP_02);
55
[5621]56  if ((float)rand()/RAND_MAX > .5f)
[9176]57    this->loadModel("models/ships/noxon_battle_drone.obj", .3);
[5621]58  else
[9176]59    this->loadModel("models/ships/noxon_battle_drone.obj", .2);
[5621]60
[9198]61  this->setDamage(30.0f);
[9164]62
63
64
[5333]65  this->shader = NULL;
66  if (likely(Shader::checkShaderAbility()))
67    this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag");
[5059]68
69  this->randomRotAxis = VECTOR_RAND(1);
[9161]70
71  if (root != NULL)
72    this->loadParams(root);
[1931]73}
[1853]74
[5034]75
[9173]76AttractorMine::~AttractorMine ()
[5267]77{
[5363]78  if (this->shader)
79    Shader::unload(this->shader);
[5267]80}
[1853]81
[5267]82
[9173]83void AttractorMine::loadParams(const TiXmlElement* root)
[9161]84{
85  NPC::loadParams(root);
[1931]86
[9161]87}
88
89
[9173]90void AttractorMine::destroy(WorldEntity* killer)
[9164]91{
92  Explosion::explode(this, Vector(10,10,10));
93  this->toList(OM_DEAD);
[9161]94
[9164]95}
96
97
98
[5266]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 */
[9173]105void AttractorMine::draw() const
[4984]106{
[9161]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
[9175]119  //   if (this->shader != NULL && this->shader != Shader::getActiveShader())
120  //     shader->activateShader();
[9164]121
122  this->getModel()->draw();
[9175]123  //   shader->deactivateShader();
[9161]124
125
[9175]126  /*  if (this->model)
127      this->model->draw();*/
[9161]128  glPopMatrix();
[5266]129}
130
131
[9173]132void AttractorMine::tick(float dt)
[5266]133{
[9175]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  }
[2036]144
[9175]145  this->shiftCoor(this->velocity * dt);
146
147  //  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
148
[4986]149  //if (directin.len() < 100)
[9175]150  //  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0));
[9176]151  this->shiftDir(Quaternion(.5 * dt, this->randomRotAxis));
[4986]152
[4984]153}
154
155
[5033]156
Note: See TracBrowser for help on using the repository browser.