src/engine/eSensor.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "eSensor.h"
00029 #include "eWall.h"
00030 #include "eDebugLine.h"
00031 #include "eGrid.h"
00032 
00033 #ifdef DEBUG
00034 //#define DEBUGLINE
00035 #endif
00036 
00037 eSensor::eSensor(eGameObject *o,const eCoord &start,const eCoord &d)
00038         :eStackGameObject(o->grid, start,d,o->currentFace)
00039         ,hit(1000),ehit(NULL),lr(0), owned(o) , inverseSpeed_(0)
00040 {
00041     if (owned)
00042     {
00043         currentFace=owned->currentFace;
00044 
00045         // find a better current face if our start postion is not really at the
00046         // current position of the owner
00047         if ( grid && !currentFace || !currentFace->IsInside( pos ) && currentFace->IsInside( owned->pos ) )
00048         {
00049             currentFace = o->grid->FindSurroundingFace( pos, currentFace );
00050         }
00051     }
00052     else
00053         currentFace=NULL;
00054 }
00055 
00056 void eSensor::PassEdge(const eWall *w,REAL time,REAL a,int){
00057     if (!w->Massive()){
00058         return;
00059     }
00060 
00061     // extrapolate the hit time
00062     REAL hitTime = owned->LastTime() + time * inverseSpeed_;
00063 
00064     if (owned && !owned->EdgeIsDangerous(w, hitTime, a))
00065         return;
00066 
00067     lr=0;
00068 
00069     const eHalfEdge *e = w->Edge();
00070 
00071     eCoord eEdge_dir=w->Vec();
00072     eCoord collPos = w->Point( a );
00073 
00074     // con << dir << eEdge_dir << '\n';
00075     REAL dec=- eEdge_dir*dir;
00076 
00077     if (dec>0)
00078         lr=1;
00079     else if (dec<0)
00080         lr=-1;
00081     else
00082         lr=0;
00083 
00084     hit=time;
00085     ehit=e;
00086     before_hit=collPos-dir*.000001;
00087 
00088     throw eSensorFinished();
00089 }
00090 
00091 //void eSensor::PassEdge(eEdge *e,REAL time,REAL a,int recursion){
00092 //  PassEdge((const eEdge *)e,time,a,recursion);
00093 //}
00094 
00095 void eSensor::detect(REAL range){
00096     //  eCoord start = pos;
00097     //  pos=pos+dir*.01;
00098     before_hit=pos+dir*(range-.001);
00099     hit=range+.00001f;
00100     ehit = 0;
00101 
00102     /*
00103     {
00104       ePoint a(pos);
00105       ePoint b(pos+dir*range);
00106       eEdge e(&a,&b);
00107 
00108       
00109       for(int i=eGameObject::gameObjects.Len()-1;i>=0;i--){
00110         eGameObject *target=gameobject::gameObjects(i);
00111         
00112         if (target->type()==ArmageTron_CYCLE){
00113     gCycle *c=(gCycle *)target;
00114     if (c->Alive() && c!=owned){
00115      const eEdge *oe=c->Edge();
00116      if (oe){
00117        ePoint *meet=e.IntersectWith(oe);
00118      
00119        if (meet){ // whoops. Hit!
00120          REAL ratio=oe->Ratio(*meet);
00121          // gPlayerWall *w=(gPlayerWall *)oe->w;
00122          REAL time=e.Ratio(*meet)*range;
00123          PassEdge(oe,time,ratio,1);
00124          delete meet;
00125        }
00126      }
00127     }
00128         }
00129       } 
00130     }
00131     */
00132 
00133     try
00134     {
00135         Move(pos+dir*range,0,range);
00136     }
00137     catch( eSensorFinished & e )
00138     {
00139     }
00140 
00141 #ifdef DEBUGLINE
00142     if (hit < range)
00143     {
00144         eDebugLine::SetColor  (0, 1, 1);
00145         eDebugLine::Draw(start, .1, before_hit, .1);
00146 
00147         eDebugLine::SetColor  (0, .5, 1);
00148         eDebugLine::Draw(before_hit, .1, before_hit, 2.0);
00149     }
00150     else
00151     {
00152         eDebugLine::SetColor  (1, 0, 0);
00153         eDebugLine::Draw(start, .5, pos, .5);
00154     }
00155 #endif
00156 }
00157 
00158 

Generated on Sat Mar 15 22:55:47 2008 for Armagetron Advanced by  doxygen 1.5.4