Flatland

Documentation

SourceForge.net Logo

intersection.cpp

Go to the documentation of this file.
00001 // Summary: Calls appropriate Test and Find methods for all shape-shape combinations.
00002 // Copyright: 2007  Philip Rideout.  All rights reserved.
00003 // License: see bsd-license.txt
00004 
00005 #include <flatland/flatland.hpp>
00006 #include <flatland/shapes.hpp>
00007 #include <flatland/intersection.hpp>
00008 
00009 bool Flatland::Intersection::Test(const Geometry &g1, const Geometry &g2)
00010 {
00011     if (!g1.GetBounds().intersects(g2.GetBounds())) // TODO shouldn't be a member func; should go in intersection.h
00012         return false;
00013 
00014     typedef bool TestFunction(const Geometry &g1, const Geometry &g2);
00015     static TestFunction *table[Shape::Count][Shape::Count] =
00016     {
00017         TestQuadQuad, TestQuadQuad, TestQuadCircle, TestQuadTerrain, TestQuadComposite,
00018         TestQuadQuad, TestQuadQuad, TestQuadCircle, TestQuadTerrain, TestQuadComposite,
00019         TestCircleQuad, TestCircleQuad, TestCircleCircle, TestCircleTerrain, TestCircleComposite,
00020         TestTerrainQuad, TestTerrainQuad, TestTerrainCircle, TestTerrainTerrain, TestTerrainComposite,
00021         TestCompositeQuad, TestCompositeQuad, TestCompositeCircle, TestCompositeTerrain, TestCompositeComposite
00022     };
00023 
00024     return table[g1.GetShape()][g2.GetShape()](g1, g2);
00025 }
00026 
00027 void Flatland::Intersection::Find(const Geometry &g1, const Geometry &g2, ContactList &contacts)
00028 {
00029     if (!g1.GetBounds().intersects(g2.GetBounds()))
00030         return;
00031 
00032     typedef void FindFunction(const Geometry &g1, const Geometry &g2, ContactList &contacts);
00033     static FindFunction *table[Shape::Count][Shape::Count] =
00034     {
00035         FindQuadQuad, FindQuadQuad, FindQuadCircle, FindQuadTerrain, FindQuadComposite,
00036         FindQuadQuad, FindQuadQuad, FindQuadCircle, FindQuadTerrain, FindQuadComposite,
00037         FindCircleQuad, FindCircleQuad, FindCircleCircle, FindCircleTerrain, FindCircleComposite,
00038         FindTerrainQuad, FindTerrainQuad, FindTerrainCircle, FindTerrainTerrain, FindTerrainComposite,
00039         FindCompositeQuad, FindCompositeQuad, FindCompositeCircle, FindCompositeTerrain, FindCompositeComposite
00040     };
00041 
00042     table[g1.GetShape()][g2.GetShape()](g1, g2, contacts);
00043 }

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