Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9869 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
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
[9869]35#include "class_id_DEPRECATED.h"
36ObjectListDefinitionID(AttractorMine, CL_ATTRACTOR_MINE);
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);
[9164]64
65
66
[5333]67  this->shader = NULL;
[9869]68  //if (likely(Shader::checkShaderAbility()))
69//    this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag");
[5059]70
71  this->randomRotAxis = VECTOR_RAND(1);
[9161]72
73  if (root != NULL)
74    this->loadParams(root);
[1931]75}
[1853]76
[5034]77
[9173]78AttractorMine::~AttractorMine ()
[5267]79{
80}
[1853]81
[9173]82void AttractorMine::loadParams(const TiXmlElement* root)
[9161]83{
84  NPC::loadParams(root);
[1931]85
[9161]86}
87
88
[9173]89void AttractorMine::destroy(WorldEntity* killer)
[9164]90{
91  Explosion::explode(this, Vector(10,10,10));
92  this->toList(OM_DEAD);
[9161]93
[9164]94}
95
96
97
[5266]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 */
[9173]104void AttractorMine::draw() const
[4984]105{
[9161]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
[9175]118  //   if (this->shader != NULL && this->shader != Shader::getActiveShader())
119  //     shader->activateShader();
[9164]120
121  this->getModel()->draw();
[9175]122  //   shader->deactivateShader();
[9161]123
124
[9175]125  /*  if (this->model)
126      this->model->draw();*/
[9161]127  glPopMatrix();
[5266]128}
129
130
[9173]131void AttractorMine::tick(float dt)
[5266]132{
[9175]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  }
[2036]143
[9175]144  this->shiftCoor(this->velocity * dt);
145
146  //  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
147
[4986]148  //if (directin.len() < 100)
[9175]149  //  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0));
[9176]150  this->shiftDir(Quaternion(.5 * dt, this->randomRotAxis));
[4986]151
[4984]152}
153
154
[5033]155
Note: See TracBrowser for help on using the repository browser.