Tizen 2.1 base
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / OPC_SweepAndPrune.h
1 /*
2  *      OPCODE - Optimized Collision Detection
3  * http://www.codercorner.com/Opcode.htm
4  * 
5  * Copyright (c) 2001-2008 Pierre Terdiman,  pierre@codercorner.com
6
7 This software is provided 'as-is', without any express or implied warranty.
8 In no event will the authors be held liable for any damages arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose, 
10 including commercial applications, and to alter it and redistribute it freely, 
11 subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
14 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
15 3. This notice may not be removed or altered from any source distribution.
16 */
17
18 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19 /**
20  *      Contains an implementation of the sweep-and-prune algorithm (moved from Z-Collide)
21  *      \file           OPC_SweepAndPrune.h
22  *      \author         Pierre Terdiman
23  *      \date           January, 29, 2000
24  */
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
26
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
28 // Include Guard
29 #ifndef __OPC_SWEEPANDPRUNE_H__
30 #define __OPC_SWEEPANDPRUNE_H__
31
32         ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
33         /**
34          *      User-callback, called by OPCODE for each colliding pairs.
35          *      \param          id0                     [in] id of colliding object
36          *      \param          id1                     [in] id of colliding object
37          *      \param          user_data       [in] user-defined data
38          *      \return         TRUE to continue enumeration
39          */
40         ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41         typedef BOOL    (*PairCallback) (udword id0, udword id1, void* user_data);
42
43         class SAP_Element;
44         class SAP_EndPoint;
45         class SAP_Box;
46
47         class OPCODE_API SAP_PairData
48         {
49                 public:
50                                                                 SAP_PairData();
51                                                                 ~SAP_PairData();
52
53                                 bool                    Init(udword nb_objects);
54
55                                 void                    AddPair(udword id1, udword id2);
56                                 void                    RemovePair(udword id1, udword id2);
57
58                                 void                    DumpPairs(Pairs& pairs)                                                         const;
59                                 void                    DumpPairs(PairCallback callback, void* user_data)       const;
60                 private:
61                                 udword                  mNbElements;            //!< Total number of elements in the pool
62                                 udword                  mNbUsedElements;        //!< Number of used elements
63                                 SAP_Element*    mElementPool;           //!< Array of mNbElements elements
64                                 SAP_Element*    mFirstFree;                     //!< First free element in the pool
65
66                                 udword                  mNbObjects;                     //!< Max number of objects we can handle
67                                 SAP_Element**   mArray;                         //!< Pointers to pool
68                 // Internal methods
69                                 SAP_Element*    GetFreeElem(udword id, SAP_Element* next, udword* remap=null);
70                 inline_ void                    FreeElem(SAP_Element* elem);
71                                 void                    Release();
72         };
73
74         class OPCODE_API SweepAndPrune
75         {
76                 public:
77                                                                 SweepAndPrune();
78                                                                 ~SweepAndPrune();
79
80                                 bool                    Init(udword nb_objects, const AABB** boxes);
81                                 bool                    UpdateObject(udword i, const AABB& box);
82
83                                 void                    GetPairs(Pairs& pairs)                                                          const;
84                                 void                    GetPairs(PairCallback callback, void* user_data)        const;
85                 private:
86                                 SAP_PairData    mPairs;
87
88                                 udword                  mNbObjects;
89                                 SAP_Box*                mBoxes;
90                                 SAP_EndPoint*   mList[3];
91                 // Internal methods
92                                 bool                    CheckListsIntegrity();
93         };
94
95 #endif //__OPC_SWEEPANDPRUNE_H__