Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

work flush

File size: 3.0 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{
38  this->owner = entity;
39
40  this->init();
41}
42
43
44/**
45 * destroys a AimingSystem
46*/
47AimingSystem::~AimingSystem ()
48{}
49
50
51/**
52 * initializes the AimingSystem
53 */
54void AimingSystem::init()
55{
56  this->setClassID(CL_CROSSHAIR, "AimingSystem");
57  this->setName("AimingSystem");
58
59  //this->loadModel("models/guns/targeting_system_body2.obj");
60//   this->loadModel("models/ships/fighter.obj");
61
62  // registering default reactions:
63  this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, CL_WORLD_ENTITY);
64
65  this->range = 10.0f;
66  this->sideLength = 2.0f;
67
68  // new obb tree
69  this->obbTree = new OBBTree();
70  this->obbTree->createBox(Vector(0.0f, 0.0f, 0.0f), Vector(this->range, this->sideLength, this->sideLength));
71  this->setOBBTree(this->obbTree);
72}
73
74
75
76/**
77 * get back the nearest target
78 * @returns the nerest target
79 */
80WorldEntity* AimingSystem::getNearestTarget()
81{
82
83//   PRINTF(0)("size: %i\n", this->selectionList.size());
84
85
86  if( this->selectionList.size() == 0)
87    return NULL;
88
89
90  WorldEntity* nearestEntity     = NULL;
91  float        distance          = 0.0f;
92  float        smalestDistance   = this->range * 5.0f;
93
94
95  for( int i = 0; i < this->selectionList.size(); i++)
96  {
97    distance = fabs((this->getAbsCoor() - this->selectionList[i]->getAbsCoor()).len());
98    if( distance < smalestDistance)
99    {
100      nearestEntity = this->selectionList[i];
101      smalestDistance = distance;
102    }
103  }
104
105  if( nearestEntity != this->owner)
106    return nearestEntity;
107  else
108    return NULL;
109}
110
111
112/**
113 * called when an object is "selected"
114 *  @param damage damage to be dealt
115 *  @param killer the entity
116 */
117void AimingSystem::hit(float damage, WorldEntity* killer)
118{
119  this->selectionList.push_back(killer);
120}
121
122
123
124/**
125 * ticks the AimingSystem
126 * @param dt the time to ticks
127 */
128void AimingSystem::tick(float dt)
129{
130
131//   this->selectionList.clear();
132}
133
134
135/**
136 * draws the crosshair
137 */
138void AimingSystem::draw() const
139{
140  WorldEntity::draw();
141
142//   glMatrixMode(GL_MODELVIEW);
143//   glPushMatrix();
144//
145//   /* translate */
146//   glTranslatef (this->getAbsCoor ().x,
147//                 this->getAbsCoor ().y,
148//                 this->getAbsCoor ().z);
149//   Vector tmpRot = this->getAbsDir().getSpacialAxis();
150//   glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
151//
152//   this->obbTree->drawBV(0, 1);
153//
154//   glPopMatrix();
155
156}
Note: See TracBrowser for help on using the repository browser.