Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

better cleanup and stuff

File size: 2.9 KB
Line 
1  /*
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:
12   main-programmer: Patrick Boenzli
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"
21
22#include "state.h"
23
24#include "aabb.h"
25#include "obb_tree.h"
26
27#include <vector>
28
29
30using namespace std;
31
32
33/**
34 * standart constructor
35 */
36AimingSystem::AimingSystem (WorldEntity* entity)
37  : WorldEntity()
38{
39  this->owner = entity;
40
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{
57  this->setClassID(CL_AIMING_SYSTEM, "AimingSystem");
58  this->setName("AimingSystem");
59
60  //this->loadModel("models/guns/targeting_system_body2.obj");
61//   this->loadModel("models/ships/fighter.obj");
62
63  // registering default reactions:
64  this->unsubscribeReaction(CREngine::CR_OBJECT_DAMAGE);
65  this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, CL_WORLD_ENTITY);
66
67  this->range = 1000.0f;
68  this->sideLength = 2.0f;
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));
73  this->setOBBTree(this->obbTree);
74}
75
76
77
78/**
79 * get back the nearest target
80 * @returns the nerest target
81 */
82WorldEntity* AimingSystem::getNearestTarget()
83{
84  if( this->selectionList.size() == 0)
85    return NULL;
86
87
88  WorldEntity* nearestEntity     = NULL;
89  float        distance          = 0.0f;
90  float        smalestDistance   = this->range * 5.0f;
91
92
93  for( int i = 0; i < this->selectionList.size(); i++)
94  {
95    distance = fabs((this->getAbsCoor() - this->selectionList[i]->getAbsCoor()).len());
96    if( distance < smalestDistance)
97    {
98      nearestEntity = this->selectionList[i];
99      smalestDistance = distance;
100    }
101  }
102
103
104    return nearestEntity;
105}
106
107
108/**
109 * called when an object is "selected"
110 *  @param damage damage to be dealt
111 *  @param killer the entity
112 */
113void AimingSystem::hit(float damage, WorldEntity* killer)
114{
115  if( this->owner != killer)
116    this->selectionList.push_back(killer);
117}
118
119
120
121/**
122 * ticks the AimingSystem
123 * @param dt the time to ticks
124 */
125void AimingSystem::tick(float dt)
126{
127
128
129}
130
131
132/**
133 * draws the crosshair
134 */
135void AimingSystem::draw() const
136{
137  WorldEntity::draw();
138
139//   glMatrixMode(GL_MODELVIEW);
140//   glPushMatrix();
141//
142//   /* translate */
143//   glTranslatef (this->getAbsCoor ().x,
144//                 this->getAbsCoor ().y,
145//                 this->getAbsCoor ().z);
146//   Vector tmpRot = this->getAbsDir().getSpacialAxis();
147//   glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
148//
149//   this->obbTree->drawBV(0, 1);
150//
151//   glPopMatrix();
152
153}
Note: See TracBrowser for help on using the repository browser.