Oolite
Loading...
Searching...
No Matches
CollisionRegion.h
Go to the documentation of this file.
1/*
2
3CollisionRegion.h
4
5Collision regions are used to group entities which may potentially collide, to
6reduce the number of collision checks required.
7
8Oolite
9Copyright (C) 2004-2013 Giles C Williams and contributors
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; either version 2
14of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24MA 02110-1301, USA.
25
26*/
27
28#import "OOFoundation.h"
29#import "OOMaths.h"
30
31#define COLLISION_REGION_BORDER_RADIUS 32000.0f
32#define COLLISION_MAX_ENTITIES 128
33#define MINIMUM_SHADOWING_ENTITY_RADIUS 75.0
34
35@class Entity, OOSunEntity;
36
37@interface CollisionRegion : NSObject {
38@private
39 BOOL isUniverse; // if YES location is origin and radius is 0.0f
40
41 int crid; // identifier
42 HPVector location; // center of the region
43 GLfloat radius; // inner radius of the region
44 GLfloat border_radius; // additiønal, border radius of the region (typically 32km or some value > the scanner range)
45
48
49 NSMutableArray* subregions;
50
52
53 Entity** entity_array; // entities within the region
54 unsigned n_entities; // number of entities
55 unsigned max_entities; // so storage can be expanded
56
58}
59
60- (id)initAsUniverse;
61- (id)initAtLocation:(HPVector)locn withRadius:(GLfloat)rad withinRegion:(CollisionRegion*)otherRegion;
62
63- (void)clearSubregions;
64- (void)addSubregionAtPosition:(HPVector)pos withRadius:(GLfloat)rad;
65
66// collision checking
67- (void)clearEntityList;
68- (void)addEntity:(Entity*)ent;
69- (BOOL)checkEntity:(Entity*)ent;
70
71- (void)findCollisions;
72- (void)findShadowedEntities;
73
74// Description for FPS HUD
75- (NSString*)collisionDescription;
76
77- (NSString*)debugOut;
78
79@end
80
81/* Given a region centred at e1pos with a radius of e1rad, the depth
82 * of shadowing cast by e2 from the_sun is recorded in outValue, with
83 * >1 = no shadow, <1 = shadow */
84BOOL shadowAtPointOcclusionToValue(HPVector e1pos, GLfloat e1rad, Entity* e2, OOSunEntity* the_sun, float* outValue);
BOOL shadowAtPointOcclusionToValue(HPVector e1pos, GLfloat e1rad, Entity *e2, OOSunEntity *the_sun, float *outValue)
NSMutableArray * subregions
CollisionRegion * parentRegion
Entity ** entity_array
unsigned checks_this_tick
unsigned checks_within_range