SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GridSectorizer.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
16 #ifndef _GRID_SECTORIZER_H
17 #define _GRID_SECTORIZER_H
18
19 //#define _USE_ORDERED_LIST
20
21 #include "memoryoverride.h"
22
23 #ifdef _USE_ORDERED_LIST
24 #include "DS_OrderedList.h"
25 #else
26 #include "DS_List.h"
27 #endif
28
29 class GridSectorizer
30 {
31 public:
32 GridSectorizer();
33 ~GridSectorizer();
34
35 // _cellWidth, _cellHeight is the width and height of each cell in world units
36 // minX, minY, maxX, maxY are the world dimensions (can be changed to dynamically allocate later if needed)
37 void Init(const float _maxCellWidth, const float _maxCellHeight, const float minX, const float minY, const float maxX, const float maxY);
38
39 // Adds a pointer to the grid with bounding rectangle dimensions
40 void AddEntry(void *entry, const float minX, const float minY, const float maxX, const float maxY);
41
42 #ifdef _USE_ORDERED_LIST
43
44 // Removes a pointer, as above
45 void RemoveEntry(void *entry, const float minX, const float minY, const float maxX, const float maxY);
46
47 // Adds and removes in one pass, more efficient than calling both functions consecutively
48 void MoveEntry(void *entry, const float sourceMinX, const float sourceMinY, const float sourceMaxX, const float sourceMaxY,
49 const float destMinX, const float destMinY, const float destMaxX, const float destMaxY);
50
51 #endif
52
53 // Adds to intersectionList all entries in a certain radius
54 void GetEntries(DataStructures::List<void*>& intersectionList, const float minX, const float minY, const float maxX, const float maxY);
55
56 void Clear(void);
57
58 protected:
59 int WorldToCellX(const float input) const;
60 int WorldToCellY(const float input) const;
61 int WorldToCellXOffsetAndClamped(const float input) const;
62 int WorldToCellYOffsetAndClamped(const float input) const;
63
64 // Returns true or false if a position crosses cells in the grid. If false, you don't need to move entries
65 bool PositionCrossesCells(const float originX, const float originY, const float destinationX, const float destinationY) const;
66
67 float cellOriginX, cellOriginY;
68 float cellWidth, cellHeight;
69 float invCellWidth, invCellHeight;
70 float gridWidth, gridHeight;
71 int gridCellWidthCount, gridCellHeightCount;
72
73
74 // int gridWidth, gridHeight;
75
76 #ifdef _USE_ORDERED_LIST
77 DataStructures::OrderedList<void*, void*>* grid;
78 #else
79 DataStructures::List<void*>* grid;
80 #endif
81 };
82
83 #endif