2 * OPCODE - Optimized Collision Detection
3 * http://www.codercorner.com/Opcode.htm
5 * Copyright (c) 2001-2008 Pierre Terdiman, pierre@codercorner.com
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:
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.
18 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29 #ifndef __OPC_SWEEPANDPRUNE_H__
30 #define __OPC_SWEEPANDPRUNE_H__
32 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
40 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41 typedef BOOL (*PairCallback) (udword id0, udword id1, void* user_data);
47 class OPCODE_API SAP_PairData
53 bool Init(udword nb_objects);
55 void AddPair(udword id1, udword id2);
56 void RemovePair(udword id1, udword id2);
58 void DumpPairs(Pairs& pairs) const;
59 void DumpPairs(PairCallback callback, void* user_data) const;
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
66 udword mNbObjects; //!< Max number of objects we can handle
67 SAP_Element** mArray; //!< Pointers to pool
69 SAP_Element* GetFreeElem(udword id, SAP_Element* next, udword* remap=null);
70 inline_ void FreeElem(SAP_Element* elem);
74 class OPCODE_API SweepAndPrune
80 bool Init(udword nb_objects, const AABB** boxes);
81 bool UpdateObject(udword i, const AABB& box);
83 void GetPairs(Pairs& pairs) const;
84 void GetPairs(PairCallback callback, void* user_data) const;
90 SAP_EndPoint* mList[3];
92 bool CheckListsIntegrity();
95 #endif //__OPC_SWEEPANDPRUNE_H__