Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ode/ode-0.9/OPCODE/OPC_SweepAndPrune.h @ 216

Last change on this file since 216 was 216, checked in by mathiask, 16 years ago

[Physik] add ode-0.9

File size: 3.5 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2/*
3 *      OPCODE - Optimized Collision Detection
4 *      Copyright (C) 2001 Pierre Terdiman
5 *      Homepage: http://www.codercorner.com/Opcode.htm
6 */
7///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8
9///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10/**
11 *      Contains an implementation of the sweep-and-prune algorithm (moved from Z-Collide)
12 *      \file           OPC_SweepAndPrune.h
13 *      \author         Pierre Terdiman
14 *      \date           January, 29, 2000
15 */
16///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
17
18///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19// Include Guard
20#ifndef __OPC_SWEEPANDPRUNE_H__
21#define __OPC_SWEEPANDPRUNE_H__
22
23        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24        /**
25         *      User-callback, called by OPCODE for each colliding pairs.
26         *      \param          id0                     [in] id of colliding object
27         *      \param          id1                     [in] id of colliding object
28         *      \param          user_data       [in] user-defined data
29         *      \return         TRUE to continue enumeration
30         */
31        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32        typedef BOOL    (*PairCallback) (udword id0, udword id1, void* user_data);
33
34        class SAP_Element;
35        class SAP_EndPoint;
36        class SAP_Box;
37
38        class OPCODE_API SAP_PairData
39        {
40                public:
41                                                                SAP_PairData();
42                                                                ~SAP_PairData();
43
44                                bool                    Init(udword nb_objects);
45
46                                void                    AddPair(udword id1, udword id2);
47                                void                    RemovePair(udword id1, udword id2);
48
49                                void                    DumpPairs(Pairs& pairs)                                                         const;
50                                void                    DumpPairs(PairCallback callback, void* user_data)       const;
51                private:
52                                udword                  mNbElements;            //!< Total number of elements in the pool
53                                udword                  mNbUsedElements;        //!< Number of used elements
54                                SAP_Element*    mElementPool;           //!< Array of mNbElements elements
55                                SAP_Element*    mFirstFree;                     //!< First free element in the pool
56
57                                udword                  mNbObjects;                     //!< Max number of objects we can handle
58                                SAP_Element**   mArray;                         //!< Pointers to pool
59                // Internal methods
60                                SAP_Element*    GetFreeElem(udword id, SAP_Element* next, udword* remap=null);
61                inline_ void                    FreeElem(SAP_Element* elem);
62                                void                    Release();
63        };
64
65        class OPCODE_API SweepAndPrune
66        {
67                public:
68                                                                SweepAndPrune();
69                                                                ~SweepAndPrune();
70
71                                bool                    Init(udword nb_objects, const AABB** boxes);
72                                bool                    UpdateObject(udword i, const AABB& box);
73
74                                void                    GetPairs(Pairs& pairs)                                                          const;
75                                void                    GetPairs(PairCallback callback, void* user_data)        const;
76                private:
77                                SAP_PairData    mPairs;
78
79                                udword                  mNbObjects;
80                                SAP_Box*                mBoxes;
81                                SAP_EndPoint*   mList[3];
82                // Internal methods
83                                bool                    CheckListsIntegrity();
84        };
85
86#endif //__OPC_SWEEPANDPRUNE_H__
Note: See TracBrowser for help on using the repository browser.