Flatland

Documentation

SourceForge.net Logo

terrain-all.cpp

Go to the documentation of this file.
00001 // Summary: Test for terrain-all intersection and generate contacts.
00002 // Copyright: 2007  Philip Rideout.  All rights reserved.
00003 // License: see bsd-license.txt
00004 
00005 #include <flatland/shapes.hpp>
00006 #include <flatland/intersection.hpp>
00007 
00008 // define an anonymous namespace as a place for storing off
00009 // computed information shared by Test and Find
00010 namespace
00011 {
00012     int lower, upper;
00013 }
00014 
00015 using namespace Flatland;
00016 
00017 bool TestTerrainGeometry(const Geometry &g1, const Geometry &g2)
00018 {
00019     assert(g1.GetShape() == Shape::Terrain);
00020     const Terrain &t = static_cast<const Terrain&>(g1);
00021     const Geometry &g = g2;
00022 
00023     if (!t.GetIndexRange(g.GetBounds().left, g.GetBounds().right, lower, upper))
00024         return false;
00025 
00026     for (int index = lower; index <= upper; ++index)
00027     {
00028         assert(index >= 0 && index < (int) t.size());
00029         const Line &line = t[index];
00030         if (Intersection::Test(line, g))
00031             return true;
00032     }
00033 
00034     return false;
00035 }
00036 
00037 void FindTerrainGeometry(const Geometry &g1, const Geometry &g2, ContactList &contacts)
00038 {
00039     assert(g1.GetShape() == Shape::Terrain);
00040     const Terrain &t = static_cast<const Terrain&>(g1);
00041     const Geometry &g = g2;
00042 
00043     for (int index = lower; index <= upper; ++index)
00044     {
00045         const Line &line = t[index];
00046         if (Intersection::Test(line, g)) // TODO inefficient because it's already been called
00047             Intersection::Find(line, g, contacts);
00048     }
00049 }
00050 
00051 void Intersection::FindTerrainQuad(const Geometry &g1, const Geometry &g2, ContactList &contacts)
00052 {
00053     FindTerrainGeometry(g1, g2, contacts);
00054 }
00055 
00056 void Intersection::FindTerrainCircle(const Geometry &g1, const Geometry &g2, ContactList &contacts)
00057 {
00058     FindTerrainGeometry(g1, g2, contacts);
00059 }
00060 
00061 void Intersection::FindTerrainTerrain(const Geometry &g1, const Geometry &g2, ContactList &contacts)
00062 {
00063     FindTerrainGeometry(g1, g2, contacts);
00064 }
00065 
00066 void Intersection::FindQuadTerrain(const Geometry &g1, const Geometry &g2, ContactList &contacts)
00067 {
00068     contacts.ToggleNormalInversion();
00069     FindTerrainGeometry(g2, g1, contacts);
00070     contacts.ToggleNormalInversion();
00071 }
00072 
00073 void Intersection::FindCircleTerrain(const Geometry &g1, const Geometry &g2, ContactList &contacts)
00074 {
00075     contacts.ToggleNormalInversion();
00076     FindTerrainGeometry(g2, g1, contacts);
00077     contacts.ToggleNormalInversion();
00078 }
00079 
00080 bool Intersection::TestTerrainQuad(const Geometry &g1, const Geometry &g2)
00081 {
00082     return TestTerrainGeometry(g1, g2);
00083 }
00084 
00085 bool Intersection::TestTerrainCircle(const Geometry &g1, const Geometry &g2)
00086 {
00087     return TestTerrainGeometry(g1, g2);
00088 }
00089 
00090 bool Intersection::TestTerrainTerrain(const Geometry &g1, const Geometry &g2)
00091 {
00092     return TestTerrainGeometry(g1, g2);
00093 }
00094 
00095 bool Intersection::TestQuadTerrain(const Geometry &g1, const Geometry &g2)
00096 {
00097     return TestTerrainGeometry(g2, g1);
00098 }
00099 
00100 bool Intersection::TestCircleTerrain(const Geometry &g1, const Geometry &g2)
00101 {
00102     return TestTerrainGeometry(g2, g1);
00103 }

Generated on Sat Jan 13 17:20:21 2007 for Flatland by doxygen 1.5.1