Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10114 was 10114, checked in by patrick, 17 years ago

merged network back to trunk

File size: 3.8 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
[10114]35
36ObjectListDefinition(AttractorMine);
[9869]37CREATE_FACTORY(AttractorMine);
[9178]38#include "script_class.h"
[9869]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))
[9178]46                       );
[1853]47
[1858]48
[9178]49
50
[9173]51AttractorMine::AttractorMine(const TiXmlElement* root)
[9175]52    : NPC(NULL)
[1931]53{
[9869]54  this->registerObject(this, AttractorMine::_objectList);
[4976]55
[9179]56  this->toList(OM_GROUP_02);
57
[5621]58  if ((float)rand()/RAND_MAX > .5f)
[9176]59    this->loadModel("models/ships/noxon_battle_drone.obj", .3);
[5621]60  else
[9176]61    this->loadModel("models/ships/noxon_battle_drone.obj", .2);
[5621]62
[9198]63  this->setDamage(30.0f);
[10013]64  this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Playable::staticClassID());
[9164]65
66
67
[5333]68  this->shader = NULL;
[9869]69  //if (likely(Shader::checkShaderAbility()))
70//    this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag");
[5059]71
72  this->randomRotAxis = VECTOR_RAND(1);
[9161]73
74  if (root != NULL)
75    this->loadParams(root);
[1931]76}
[1853]77
[5034]78
[9173]79AttractorMine::~AttractorMine ()
[5267]80{
81}
[1853]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.