Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file was 10718, checked in by rennerc, 18 years ago

dead gui :D

File size: 3.1 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"
[9869]23#include "debug.h"
[9156]24
[9166]25#include "aabb.h"
[9168]26#include "obb_tree.h"
[9166]27
[9156]28
[9160]29
[9869]30ObjectListDefinition(AimingSystem);
[9156]31
32/**
33 * standart constructor
34 */
[9168]35AimingSystem::AimingSystem (WorldEntity* entity)
[9186]36  : WorldEntity()
[9156]37{
[9172]38  this->owner = entity;
39
[9156]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{
[9869]56  this->registerObject(this, AimingSystem::_objectList);
[9156]57  this->setName("AimingSystem");
[9166]58
[9172]59  //this->loadModel("models/guns/targeting_system_body2.obj");
60//   this->loadModel("models/ships/fighter.obj");
[9156]61
[9168]62  // registering default reactions:
[10013]63  this->unsubscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE);
64  this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID());
[9172]65
[9189]66  this->range = 1000.0f;
[9174]67  this->sideLength = 2.0f;
[9172]68
69  // new obb tree
70  this->obbTree = new OBBTree();
71  this->obbTree->createBox(Vector(0.0f, 0.0f, 0.0f), Vector(this->range, this->sideLength, this->sideLength));
[9174]72  this->setOBBTree(this->obbTree);
[9156]73}
74
75
76
[9160]77/**
78 * get back the nearest target
[9163]79 * @returns the nerest target
[9160]80 */
[9166]81WorldEntity* AimingSystem::getNearestTarget()
[9160]82{
83  if( this->selectionList.size() == 0)
84    return NULL;
[9156]85
[9172]86
[9168]87  WorldEntity* nearestEntity     = NULL;
[9163]88  float        distance          = 0.0f;
89  float        smalestDistance   = this->range * 5.0f;
[9160]90
[9163]91
[9406]92  for(unsigned int i = 0; i < this->selectionList.size(); i++)
[9160]93  {
[9163]94    distance = fabs((this->getAbsCoor() - this->selectionList[i]->getAbsCoor()).len());
95    if( distance < smalestDistance)
96    {
97      nearestEntity = this->selectionList[i];
98      smalestDistance = distance;
99    }
100  }
[9160]101
[10718]102  return nearestEntity;
[9160]103}
104
105
[9156]106/**
[9160]107 * called when an object is "selected"
108 *  @param damage damage to be dealt
109 *  @param killer the entity
110 */
111void AimingSystem::hit(float damage, WorldEntity* killer)
112{
[10698]113  if( this->owner != killer && killer != this && !killer->isA( AimingSystem::staticClassID() ) )
[9192]114  {
[9406]115    //PRINTF(0)("real hit: %s\n", killer->getClassCName());
[9191]116    this->selectionList.push_back(killer);
[9192]117  }
[9160]118}
119
120
121
122/**
[9156]123 * ticks the AimingSystem
124 * @param dt the time to ticks
125 */
126void AimingSystem::tick(float dt)
127{
128}
129
130
131/**
132 * draws the crosshair
133 */
134void AimingSystem::draw() const
135{
[9174]136  WorldEntity::draw();
[9168]137
[9174]138//   glMatrixMode(GL_MODELVIEW);
139//   glPushMatrix();
140//
141//   /* translate */
142//   glTranslatef (this->getAbsCoor ().x,
143//                 this->getAbsCoor ().y,
144//                 this->getAbsCoor ().z);
145//   Vector tmpRot = this->getAbsDir().getSpacialAxis();
146//   glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
147//
148//   this->obbTree->drawBV(0, 1);
149//
150//   glPopMatrix();
[9172]151
[9156]152}
Note: See TracBrowser for help on using the repository browser.