Side.h

00001 // ----------------------------------------------------------------------------
00002 //
00003 // tagGame - Example code from the book:
00004 //
00005 //           Artficial Intelligence for Computer Games: An Introduction
00006 //           by John David Funge
00007 //
00008 //           www.ai4games.org
00009 //
00010 // Source code distributed under the Copyright (c) 2003-2007, John David Funge
00011 // Original author: John David Funge (www.jfunge.com)
00012 //
00013 // Licensed under the Academic Free License version 3.0 
00014 // (for details see LICENSE.txt in this directory).
00015 //
00016 // ----------------------------------------------------------------------------
00017 
00018 #ifndef TG_SIDE_H
00019 #define TG_SIDE_H
00020 
00021 #include "Shape.h"
00022 
00023 namespace tagGame
00024 {
00026    class Side : public Shape
00027    {
00028    public:
00029       // TODO: more arguments in constructor, ditto for circle obstacles
00030       Side();
00031       virtual ~Side();
00032 
00033       virtual std::ostream& output(std::ostream& out) const;
00034 
00035       inline void setNormal(RealVec const& normal);
00036 
00037       inline void setDistance(Real const distance);
00038 
00039       inline RealVec const& getNormal() const;
00040 
00041       inline Real getDistance() const;
00042 
00043       inline RealVec const& getBegin() const;
00044       inline RealVec const& getEnd() const;
00045 
00046       inline void setBegin(RealVec const& begin);
00047       inline void setEnd(RealVec const& end);
00048 
00049       virtual RealVec nearestIntersection(RealVec const& p, RealVec const& v) const;
00050 
00051       virtual RealVec normalTo(Shape const& o) const;
00052       virtual RealVec normalTo(Circle const& c) const;
00053 
00054       virtual Real distanceTo(Shape const& o) const;
00055       virtual Real distanceTo(Circle const& c) const;
00056       virtual Real distanceTo(Side const& s) const;
00057 
00058    protected:
00059    private:
00060       RealVec normal;
00061       Real distance;
00062       RealVec begin;
00063       RealVec end;
00064    };
00065 
00066    RealVec const& Side::getNormal() const
00067    {
00068       return normal;
00069    }
00070 
00071    Real Side::getDistance() const
00072    {
00073       return distance;
00074    }
00075 
00076    RealVec const& Side::getBegin() const
00077    {
00078       return begin;
00079    }
00080 
00081    RealVec const& Side::getEnd() const
00082    {
00083       return end;
00084    }
00085 
00086    void Side::setNormal(RealVec const& normal)
00087    {
00088       // TG_ASSERT_MSG(1 == normal.length() && 2 == normal.size() && (normal[0] = 0 || normal[2] = 0),
00089       //              string("Only 2D axis aligned side obstacles are currently supported"));
00090       this->normal = normal;
00091    }
00092 
00093    void Side::setDistance(Real const distance)
00094    {
00095       this->distance = distance;
00096    }
00097 
00098    void Side::setBegin(RealVec const& begin)
00099    {
00100       this->begin = begin;
00101    }
00102 
00103    void Side::setEnd(RealVec const& end)
00104    {
00105       this->end = end;
00106    }
00107 }
00108 
00109 #endif

Generated on Sat Mar 31 22:30:54 2007 for tagGame by  doxygen 1.5.1