Box.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2005 The Pentagram Team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef BOX_H_INCLUDED
00020 #define BOX_H_INCLUDED
00021 
00022 namespace Pentagram {
00023 
00024 struct Box {
00025         sint32          x, y, z;
00026         sint32          xd, yd, zd;
00027 
00028         Box() : x(0), y(0), z(0), xd(0), yd(0), zd(0) {}
00029         Box(int nx, int ny, int nz, int nxd, int nyd, int nzd)
00030                 : x(nx), y(ny), z(nz), xd(nxd), yd(nyd), zd(nzd) {}
00031         Box(const Box& o) : x(o.x), y(o.y), z(o.z), xd(o.xd), yd(o.yd), zd(o.zd) {}
00032         
00033         void    Set(int nx, int ny, int nz, int nxd, int nyd, int nzd)
00034                 { x=nx; y=ny; z=nz; xd=nxd; yd=nyd; zd=nzd; }
00035         void    Set(Box &o) { *this = o; }
00036         
00037         // Check to see if a Box is 'valid'
00038         bool    IsValid() const
00039                 { return xd > 0 && yd > 0 && zd > 0; }
00040 
00041         // Check to see if a point is within the Box
00042         bool    InBox(int px, int py, int pz) const
00043                 { return (px >= (x-xd) && py >= (y-yd) && pz >= z &&
00044                                   px < x && py < y && pz < (z+zd)); }
00045 
00046         // Move the Box (Relative)
00047         void    MoveRel(sint32 dx, sint32 dy, sint32 dz) { x+=dx; y+=dy; z+=dz; }
00048 
00049         // Move the Box (Absolute)
00050         void    MoveAbs(sint32 nx, sint32 ny, sint32 nz) { x=nx; y=ny; z=nz; }
00051 
00052         // Resize the Box (Relative)
00053         void    ResizeRel(sint32 dxd, sint32 dyd, sint32 dzd)
00054                 { xd+=dxd; yd+=dyd; zd+=dzd; }
00055 
00056         // Resize the Box (Absolute)
00057         void    ResizeAbs(sint32 nxd, sint32 nyd, sint32 nzd)
00058                 { xd=nxd; yd=nyd; zd=nzd; }
00059 
00060         bool    Overlaps(const Box& o) const
00061         {
00062                 if (x <= o.x-o.xd || o.x <= x-xd) return false;
00063                 if (y <= o.y-o.yd || o.y <= y-yd) return false;
00064                 if (z+zd <= o.z || o.z+o.zd <= z) return false;
00065                 return true;
00066         }
00067 
00068         bool operator == (const Box& o) const
00069         {
00070                 return (x == o.x && y == o.y && z == o.z &&
00071                                 xd == o.xd && yd == o.yd && zd == o.zd);
00072         }
00073 
00074 };
00075 
00076 }
00077 
00078 #endif

Generated on Fri Jul 27 22:27:10 2007 for pentagram by  doxygen 1.4.7