Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/aiming_system.cc @ 9189

Last change on this file since 9189 was 9189, checked in by patrick, 18 years ago

aiming system regrouping and reparenting

File size: 3.0 KB
RevLine 
[9172]1  /*
[9156]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
[9168]12   main-programmer: Patrick Boenzli
[9156]13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "aiming_system.h"
19
20#include "util/loading/load_param.h"
[9160]21
[9156]22#include "state.h"
23
[9166]24#include "aabb.h"
[9168]25#include "obb_tree.h"
[9166]26
[9160]27#include <vector>
[9156]28
[9160]29
[9156]30using namespace std;
31
32
33/**
34 * standart constructor
35 */
[9168]36AimingSystem::AimingSystem (WorldEntity* entity)
[9186]37  : WorldEntity()
[9156]38{
[9172]39  this->owner = entity;
40
[9156]41  this->init();
42}
43
44
45/**
46 * destroys a AimingSystem
47*/
48AimingSystem::~AimingSystem ()
49{}
50
51
52/**
53 * initializes the AimingSystem
54 */
55void AimingSystem::init()
56{
[9185]57  this->setClassID(CL_AIMING_SYSTEM, "AimingSystem");
[9156]58  this->setName("AimingSystem");
[9166]59
[9172]60  //this->loadModel("models/guns/targeting_system_body2.obj");
61//   this->loadModel("models/ships/fighter.obj");
[9156]62
[9168]63  // registering default reactions:
[9188]64  this->unsubscribeReaction(CREngine::CR_OBJECT_DAMAGE);
[9168]65  this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, CL_WORLD_ENTITY);
[9172]66
[9189]67  this->range = 1000.0f;
[9174]68  this->sideLength = 2.0f;
[9172]69
70  // new obb tree
71  this->obbTree = new OBBTree();
72  this->obbTree->createBox(Vector(0.0f, 0.0f, 0.0f), Vector(this->range, this->sideLength, this->sideLength));
[9174]73  this->setOBBTree(this->obbTree);
[9156]74}
75
76
77
[9160]78/**
79 * get back the nearest target
[9163]80 * @returns the nerest target
[9160]81 */
[9166]82WorldEntity* AimingSystem::getNearestTarget()
[9160]83{
[9172]84
85//   PRINTF(0)("size: %i\n", this->selectionList.size());
86
87
[9160]88  if( this->selectionList.size() == 0)
89    return NULL;
[9156]90
[9172]91
[9168]92  WorldEntity* nearestEntity     = NULL;
[9163]93  float        distance          = 0.0f;
94  float        smalestDistance   = this->range * 5.0f;
[9160]95
[9163]96
[9160]97  for( int i = 0; i < this->selectionList.size(); i++)
98  {
[9163]99    distance = fabs((this->getAbsCoor() - this->selectionList[i]->getAbsCoor()).len());
100    if( distance < smalestDistance)
101    {
102      nearestEntity = this->selectionList[i];
103      smalestDistance = distance;
104    }
105  }
[9160]106
[9168]107  if( nearestEntity != this->owner)
108    return nearestEntity;
[9172]109  else
110    return NULL;
[9160]111}
112
113
[9156]114/**
[9160]115 * called when an object is "selected"
116 *  @param damage damage to be dealt
117 *  @param killer the entity
118 */
119void AimingSystem::hit(float damage, WorldEntity* killer)
120{
121  this->selectionList.push_back(killer);
122}
123
124
125
126/**
[9156]127 * ticks the AimingSystem
128 * @param dt the time to ticks
129 */
130void AimingSystem::tick(float dt)
131{
[9163]132
[9188]133
[9156]134}
135
136
137/**
138 * draws the crosshair
139 */
140void AimingSystem::draw() const
141{
[9174]142  WorldEntity::draw();
[9168]143
[9174]144//   glMatrixMode(GL_MODELVIEW);
145//   glPushMatrix();
146//
147//   /* translate */
148//   glTranslatef (this->getAbsCoor ().x,
149//                 this->getAbsCoor ().y,
150//                 this->getAbsCoor ().z);
151//   Vector tmpRot = this->getAbsDir().getSpacialAxis();
152//   glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
153//
154//   this->obbTree->drawBV(0, 1);
155//
156//   glPopMatrix();
[9172]157
[9156]158}
Note: See TracBrowser for help on using the repository browser.