TargetSpace.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #if !defined(__INCLUDE_TargetSpaceh_INCLUDE__)
00022 #define __INCLUDE_TargetSpaceh_INCLUDE__
00023 
00024 #include <target/Target.h>
00025 #include <map>
00026 #include <set>
00027 #include <vector>
00028 
00029 class ScorchedContext;
00030 class TargetSpace
00031 {
00032 public:
00033         TargetSpace();
00034         virtual ~TargetSpace();
00035 
00036         void updateTarget(Target *target);
00037         void setContext(ScorchedContext *context) { context_ = context; }
00038 
00039         Target *getCollision(FixedVector &position);
00040         void getCollisionSet(FixedVector &position, fixed radius, 
00041                 std::map<unsigned int, Target *> &collisionTargets, 
00042                 bool ignoreHeight = false);
00043 
00044         void draw();
00045 
00046 protected:
00047         class Square
00048         {
00049         public:
00050                 std::map<unsigned int, Target *> targets;
00051                 int squarenum;
00052         };
00053 
00054         ScorchedContext *context_;
00055         Square *squares_;
00056         int spaceX_, spaceY_; // Position of bottom left of space
00057         int spaceW_, spaceH_; // Width, height of space
00058         int spaceWSq_, spaceHSq_; // Number of squares in width and height
00059         int spaceSq_; // Width of each square
00060         int noSquares_; // The total number of squares
00061 
00062         void normalizeCoords(int &x, int &y)
00063         {
00064                 // Make sure x and y are in the space
00065                 x = MIN(x, spaceW_ + spaceX_ - 1);
00066                 x = MAX(x, spaceX_);
00067                 y = MIN(y, spaceH_ + spaceY_ - 1);
00068                 y = MAX(y, spaceY_);
00069 
00070                 // Find the square pos
00071                 x -= spaceX_;
00072                 y -= spaceY_;
00073                 x /= spaceSq_;
00074                 y /= spaceSq_;
00075         }
00076 
00077         void getSquares(Target *target, std::vector<Square*> &squares);
00078         void removeTarget(Target *target);
00079 
00080 private:
00081         TargetSpace(TargetSpace &other);
00082         TargetSpace &operator=(TargetSpace &other);
00083 };
00084 
00085 #endif // __INCLUDE_TargetSpaceh_INCLUDE__

Generated on Mon Feb 16 15:14:52 2009 for Scorched3D by  doxygen 1.5.3