Oolite
Loading...
Searching...
No Matches
Octree Class Reference

#include <Octree.h>

Inheritance diagram for Octree:
Collaboration diagram for Octree:

Instance Methods

(id) - initWithDictionary:
(Octree *) - octreeScaledBy:
(GLfloat) - isHitByLine:v1:
(BOOL) - isHitByOctree:withOrigin:andIJK:
(BOOL) - isHitByOctree:withOrigin:andIJK:s1:s2:
(NSDictionary *) - dictionaryRepresentation
(GLfloat) - volume
(Vector) - randomPoint
(id) - init [implementation]
(id) - initWithData:radius: [implementation]
(void) - dealloc [implementation]
(BOOL) - hasCollision [implementation]
(void) - setHasCollision: [implementation]
(Octree_details) - octreeDetails [implementation]

Class Methods

(static Vector) + offsetForOctant [implementation]
(static BOOL) + isHitByLineSub [implementation]
(static BOOL) + isHitByLine [implementation]
(static BOOL) + isHitByOctree [implementation]
(static GLfloat) + volumeOfOctree [implementation]
(static Vector) + randomFullNodeFrom [implementation]

Private Attributes

GLfloat _radius
uint32_t _nodeCount
const int * _octree
BOOL _hasCollision
unsigned char * _collisionOctree
NSData * _data

Detailed Description

Definition at line 37 of file Octree.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 124 of file Octree.m.

125{
126 DESTROY(_data);
127 free(_collisionOctree);
128
129 [super dealloc];
130}
#define DESTROY(x)
unsigned char * _collisionOctree
Definition Octree.h:44
NSData * _data
Definition Octree.h:46

References _collisionOctree, _data, dealloc, and DESTROY.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dictionaryRepresentation

- (NSDictionary *) dictionaryRepresentation

Definition at line 626 of file Octree.m.

627{
628 return [NSDictionary dictionaryWithObjectsAndKeys:
629 _data, @"octree",
630 [NSNumber numberWithFloat:_radius], @"radius",
631 nil];
632}

References dictionaryRepresentation.

Referenced by dictionaryRepresentation, and OOCacheManager(Octree)::setOctree:forModel:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasCollision

- (BOOL) hasCollision
implementation

Definition at line 132 of file Octree.m.

133{
134 return _hasCollision;
135}
BOOL _hasCollision
Definition Octree.h:42

References _hasCollision, and hasCollision.

Referenced by hasCollision, isHitByOctree:withOrigin:andIJK:, and isHitByOctree:withOrigin:andIJK:s1:s2:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init

- (id) init
implementation

Definition at line 80 of file Octree.m.

81{
82 // -init makes no sense, since octrees are immutable.
83 [self release];
84 [NSException raise:NSInternalInconsistencyException format:@"Call of invalid initializer %s", __FUNCTION__];
85 return nil;
86}
return nil

References init, and nil.

Referenced by init, and initWithData:radius:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithData:radius:

- (id) initWithData: (NSData*) data
radius: (GLfloat) radius 
implementation

Definition at line 89 of file Octree.m.

89 :(NSData*)data
90 radius:(GLfloat)radius
91{
92 if ((self = [super init])) {
93 _data = [data copy];
94 _radius = radius;
95
96 NSUInteger nodeCount = [_data length] / sizeof *_octree;
97 NSParameterAssert(nodeCount < UINT32_MAX);
98 _nodeCount = (uint32_t)nodeCount;
99
100 _octree = [_data bytes];
101
102 _collisionOctree = calloc(1, _nodeCount);
103 if (_octree == NULL || _collisionOctree == NULL) {
104 [self release];
105 return nil;
106 }
107 }
108
109 return self;
110}
id init()
Definition Octree.m:80
GLfloat _radius
Definition Octree.h:39
const int * _octree
Definition Octree.h:41
uint32_t _nodeCount
Definition Octree.h:40

References _collisionOctree, _data, _nodeCount, _octree, _radius, init, and nil.

Referenced by initWithDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithDictionary:

- (id) initWithDictionary: (NSDictionary*) dictionary

Definition at line 112 of file Octree.m.

112 :(NSDictionary*)dict
113{
114 NSData* data = [dict objectForKey:@"octree"];
115 if (![data isKindOfClass:[NSData class]] || ([data length] % sizeof(int)) != 0) {
116 // Invalid representation.
117 [self release];
118 return nil;
119 }
120
121 return [self initWithData:data radius:[dict oo_floatForKey:@"radius"]];
122}

References initWithData:radius:, and nil.

Here is the call graph for this function:

◆ isHitByLine

+ (BOOL) isHitByLine (const int *) octbuffer
(unsigned char *) collbuffer
(int) level
(GLfloat) rad
(Vector) v0
(Vector) v1
(Vector) off
(int) face_hit 
implementation

Definition at line 347 of file Octree.m.

348{
349 // displace the line by the offset
350 Vector u0 = make_vector(v0.x + off.x, v0.y + off.y, v0.z + off.z);
351 Vector u1 = make_vector(v1.x + off.x, v1.y + off.y, v1.z + off.z);
352
353 OctreeDebugLog(@"DEBUG octant: [%d] radius: %.2f vs. line: (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f)",
354 level, rad, u0.x, u0.y, u0.z, u1.x, u1.y, u1.z);
355
356 if (octbuffer[level] == 0) {
357 OctreeDebugLog(@"DEBUG Hit an empty octant: [%d]", level);
358 return NO;
359 }
360
361 if (octbuffer[level] == -1) {
362 OctreeDebugLog(@"DEBUG Hit a solid octant: [%d]", level);
363 collbuffer[level] = 2; // green
364 hit_dist = sqrt(u0.x * u0.x + u0.y * u0.y + u0.z * u0.z);
365 return YES;
366 }
367
368 int faces = face_hit;
369 if (faces == 0)
370 faces = lineCubeIntersection(u0, u1, rad);
371
372 if (faces == 0) {
373 OctreeDebugLog(@"----> Line misses octant: [%d].", level);
374 return NO;
375 }
376
377 int octantIntersected = 0;
378
379 if (faces > 0) {
380 Vector vi = lineIntersectionWithFace(u0, u1, faces, rad);
381
382 if (CUBE_FACE_FRONT & faces)
383 octantIntersected = ((vi.x < 0.0) ? 1 : 5) + ((vi.y < 0.0) ? 0 : 2);
384 if (CUBE_FACE_BACK & faces)
385 octantIntersected = ((vi.x < 0.0) ? 0 : 4) + ((vi.y < 0.0) ? 0 : 2);
386
387 if (CUBE_FACE_RIGHT & faces)
388 octantIntersected = ((vi.y < 0.0) ? 4 : 6) + ((vi.z < 0.0) ? 0 : 1);
389 if (CUBE_FACE_LEFT & faces)
390 octantIntersected = ((vi.y < 0.0) ? 0 : 2) + ((vi.z < 0.0) ? 0 : 1);
391
392 if (CUBE_FACE_TOP & faces)
393 octantIntersected = ((vi.x < 0.0) ? 2 : 6) + ((vi.z < 0.0) ? 0 : 1);
394 if (CUBE_FACE_BOTTOM & faces)
395 octantIntersected = ((vi.x < 0.0) ? 0 : 4) + ((vi.z < 0.0) ? 0 : 1);
396
397 OctreeDebugLog(@"----> found intersection with face 0x%2x of cube of radius %.2f at (%.2f, %.2f, %.2f) octant:%d",
398 faces, rad, vi.x, vi.y, vi.z, octantIntersected);
399 } else {
400 OctreeDebugLog(@"----> inside cube of radius %.2f octant:%d", rad, octantIntersected);
401 }
402
403 hasCollided = YES;
404
405 collbuffer[level] = 1; // red
406
407 OctreeDebugLog(@"%@", @"----> testing octants...");
408
409 int nextLevel = level + octbuffer[level];
410
411 GLfloat rd2 = 0.5f * rad;
412
413 // first test the intersected octant, then the three adjacent, then the next three adjacent, the finally the diagonal octant
414 int oct0, oct1, oct2, oct3; // test oct0 then oct1, oct2, oct3 then (7 - oct1), (7 - oct2), (7 - oct3) then (7 - oct0)
415 oct0 = octantIntersected;
416 oct1 = oct0 ^ 0x01; // adjacent x
417 oct2 = oct0 ^ 0x02; // adjacent y
418 oct3 = oct0 ^ 0x04; // adjacent z
419
420 OctreeDebugLog(@"----> testing first octant hit [+%d]", oct0);
421 if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct0))
422 return YES; // first octant
423
424 // test the three adjacent octants
425
426 OctreeDebugLog(@"----> testing next three octants [+%d] [+%d] [+%d]", oct1, oct2, oct3);
427 if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct1))
428 return YES; // second octant
429 if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct2))
430 return YES; // third octant
431 if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct3))
432 return YES; // fourth octant
433
434 // go to the next four octants
435
436 oct0 ^= 0x07;
437 oct1 ^= 0x07;
438 oct2 ^= 0x07;
439 oct3 ^= 0x07;
440
441 OctreeDebugLog(@"----> testing back three octants [+%d] [+%d] [+%d]", oct1, oct2, oct3);
442 if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct1))
443 return YES; // fifth octant
444 if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct2))
445 return YES; // sixth octant
446 if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct3))
447 return YES; // seventh octant
448
449 // and check the last octant
450 OctreeDebugLog(@"----> testing final octant [+%d]", oct0);
451 if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct0))
452 return YES; // last octant
453
454 return NO;
455}
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
struct Vector Vector
Vector lineIntersectionWithFace(Vector p1, Vector p2, long mask, GLfloat rd) CONST_FUNC
Definition OOVoxel.m:101
#define CUBE_FACE_FRONT
Definition OOVoxel.h:33
#define CUBE_FACE_LEFT
Definition OOVoxel.h:30
#define CUBE_FACE_RIGHT
Definition OOVoxel.h:29
#define CUBE_FACE_TOP
Definition OOVoxel.h:31
int lineCubeIntersection(Vector v0, Vector v1, GLfloat rd) CONST_FUNC
Definition OOVoxel.m:164
#define CUBE_FACE_BOTTOM
Definition OOVoxel.h:32
#define CUBE_FACE_BACK
Definition OOVoxel.h:34
static GLfloat hit_dist
Definition Octree.m:346
#define OctreeDebugLog(...)
Definition Octree.m:42
static BOOL hasCollided
Definition Octree.m:345
static BOOL isHitByLineSub(const int *octbuffer, unsigned char *collbuffer, int nextLevel, GLfloat rad, GLfloat rd2, Vector v0, Vector v1, int octantMask)
Definition Octree.m:336
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References CUBE_FACE_BACK, CUBE_FACE_BOTTOM, CUBE_FACE_FRONT, CUBE_FACE_LEFT, CUBE_FACE_RIGHT, CUBE_FACE_TOP, hasCollided, hit_dist, isHitByLineSub, lineCubeIntersection(), lineIntersectionWithFace(), make_vector(), OctreeDebugLog, Vector::x, Vector::y, and Vector::z.

Referenced by isHitByLine:v1:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isHitByLine:v1:

- (GLfloat) isHitByLine: (Vector) v0
v1: (Vector) v1 

Definition at line 457 of file Octree.m.

457 :(Vector)v0 v1:(Vector)v1
458{
459 memset(_collisionOctree, 0, _nodeCount * sizeof *_collisionOctree);
460 hasCollided = NO;
461
463 OctreeDebugLog(@"DEBUG Hit at distance %.2f", hit_dist);
465 return hit_dist;
466 } else {
467 OctreeDebugLog(@"%@", @"DEBUG Missed!");
469 return 0.0f;
470 }
471}
const Vector kZeroVector
Definition OOVector.m:27
static BOOL isHitByLine(const int *octbuffer, unsigned char *collbuffer, int level, GLfloat rad, Vector v0, Vector v1, Vector off, int face_hit)
Definition Octree.m:347

References _collisionOctree, _hasCollision, _nodeCount, _octree, _radius, hasCollided, hit_dist, isHitByLine, isHitByLine(), kZeroVector, and OctreeDebugLog.

Referenced by ShipEntity::doesHitLine:v1:, PlayerEntity::doesHitLine:v1:hitEntity:, ShipEntity::doesHitLine:v1:hitEntity:, and ShipEntity::doesHitLine:v1:withPosition:i:j:k:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isHitByLineSub

+ (BOOL) isHitByLineSub (const int *) octbuffer
(unsigned char *) collbuffer
(int) nextLevel
(GLfloat) rad
(GLfloat) rd2
(Vector) v0
(Vector) v1
(int) octantMask 
implementation

Definition at line 336 of file Octree.m.

337{
338 if (octbuffer[nextLevel + octantMask]) {
339 Vector moveLine = offsetForOctant(octantMask, rad);
340 return isHitByLine(octbuffer, collbuffer, nextLevel + octantMask, rd2, v0, v1, moveLine, 0);
341 } else
342 return NO;
343}
static Vector offsetForOctant(int oct, GLfloat r)
Definition Octree.m:158

References isHitByLine(), and offsetForOctant.

Referenced by isHitByLine.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isHitByOctree

+ (BOOL) isHitByOctree (Octree_details) axialDetails
(Octree_details) otherDetails
(Vector) otherPosition
(Triangle) other_ijk 
implementation

Definition at line 473 of file Octree.m.

475{
476 const int* axialBuffer = axialDetails.octree;
477 const int* otherBuffer = otherDetails.octree;
478
479 if (axialBuffer[0] == 0) {
480 OctreeDebugLog(@"%@", @"DEBUG Axial octree is empty.");
481 return NO;
482 }
483
484 if (!otherBuffer) {
485 OctreeDebugLog(@"%@", @"DEBUG Other octree is undefined.");
486 return NO;
487 }
488
489 if (otherBuffer[0] == 0) {
490 OctreeDebugLog(@"%@", @"DEBUG Other octree is empty.");
491 return NO;
492 }
493
494 GLfloat axialRadius = axialDetails.radius;
495 GLfloat otherRadius = otherDetails.radius;
496
497 if (otherRadius < axialRadius) // test axial cube against other sphere
498 {
499 // 'crude and simple' - test sphere against cube...
500 if ((otherPosition.x + otherRadius < -axialRadius) || (otherPosition.x - otherRadius > axialRadius) || (otherPosition.y + otherRadius < -axialRadius) || (otherPosition.y - otherRadius > axialRadius) || (otherPosition.z + otherRadius < -axialRadius) || (otherPosition.z - otherRadius > axialRadius)) {
501 OctreeDebugLog(@"%@", @"----> Other sphere does not intersect axial cube");
502 return NO;
503 }
504 } else // test axial sphere against other cube
505 {
506 Vector d2 = vector_flip(otherPosition);
507 Vector axialPosition = resolveVectorInIJK(d2, other_ijk);
508 if ((axialPosition.x + axialRadius < -otherRadius) || (axialPosition.x - axialRadius > otherRadius) || (axialPosition.y + axialRadius < -otherRadius) || (axialPosition.y - axialRadius > otherRadius) || (axialPosition.z + axialRadius < -otherRadius) || (axialPosition.z - axialRadius > otherRadius)) {
509 OctreeDebugLog(@"%@", @"----> Axial sphere does not intersect other cube");
510 return NO;
511 }
512 }
513
514 // from here on, this Octree and the other Octree are considered to be intersecting
515 unsigned char* axialCollisionBuffer = axialDetails.octree_collision;
516 unsigned char* otherCollisionBuffer = otherDetails.octree_collision;
517 if (axialBuffer[0] == -1) {
518 // we are SOLID - is the other octree?
519 if (otherBuffer[0] == -1) {
520 // YES so octrees collide
521 axialCollisionBuffer[0] = (unsigned char)255; // mark
522 otherCollisionBuffer[0] = (unsigned char)255; // mark
523
524 OctreeDebugLog(@"%@", @"DEBUG Octrees collide!");
525 return YES;
526 }
527 // the other octree must be decomposed
528 // and each of its octants tested against the axial octree
529 // if any of them collides with this octant
530 // then we have a solid collision
531
532 OctreeDebugLog(@"%@", @"----> testing other octants...");
533
534 // work out the nearest octant to the axial octree
535 int nearest_oct = ((otherPosition.x > 0.0) ? 0 : 4) | ((otherPosition.y > 0.0) ? 0 : 2) | ((otherPosition.z > 0.0) ? 0 : 1);
536
537 int nextLevel = otherBuffer[0];
538 const int* nextBuffer = &otherBuffer[nextLevel];
539 unsigned char* nextCollisionBuffer = &otherCollisionBuffer[nextLevel];
540 Octree_details nextDetails;
541 Vector voff, nextPosition;
542 unsigned i, oct;
543
544 nextDetails.radius = 0.5f * otherRadius;
545 for (i = 0; i < 8; i++) {
546 oct = nearest_oct ^ change_oct[i]; // work from nearest to furthest
547 if (nextBuffer[oct]) // don't test empty octants
548 {
549 nextDetails.octree = &nextBuffer[oct];
550 nextDetails.octree_collision = &nextCollisionBuffer[oct];
551
552 voff = resolveVectorInIJK(offsetForOctant(oct, otherRadius), other_ijk);
553 nextPosition = vector_subtract(otherPosition, voff);
554 if (isHitByOctree(axialDetails, nextDetails, nextPosition, other_ijk)) // test octant
555 return YES;
556 }
557 }
558
559 // otherwise
560 return NO;
561 }
562 // we are not solid
563 // we must test each of our octants against
564 // the other octree, if any of them collide
565 // we have a solid collision
566
567 OctreeDebugLog(@"%@", @"----> testing axial octants...");
568
569 // work out the nearest octant to the other octree
570 int nearest_oct = ((otherPosition.x > 0.0) ? 4 : 0) | ((otherPosition.y > 0.0) ? 2 : 0) | ((otherPosition.z > 0.0) ? 1 : 0);
571
572 int nextLevel = axialBuffer[0];
573 const int* nextBuffer = &axialBuffer[nextLevel];
574 unsigned char* nextCollisionBuffer = &axialCollisionBuffer[nextLevel];
575 Vector nextPosition;
576 Octree_details nextDetails;
577 unsigned i, oct;
578
579 nextDetails.radius = 0.5f * axialRadius;
580 for (i = 0; i < 8; i++) {
581 oct = nearest_oct ^ change_oct[i]; // work from nearest to furthest
582 if (nextBuffer[oct]) // don't test empty octants
583 {
584 nextDetails.octree = &nextBuffer[oct];
585 nextDetails.octree_collision = &nextCollisionBuffer[oct];
586
587 nextPosition = vector_add(otherPosition, offsetForOctant(oct, axialRadius));
588 if (isHitByOctree(nextDetails, otherDetails, nextPosition, other_ijk)) {
589 return YES; // test octant
590 }
591 }
592 }
593 // otherwise we're done!
594 return NO;
595}
OOINLINE Vector resolveVectorInIJK(Vector v0, Triangle ijk)
Definition OOTriangle.h:58
OOINLINE Vector vector_flip(Vector v) INLINE_CONST_FUNC
Definition OOVector.h:227
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
OOINLINE Vector vector_subtract(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:218
static const int change_oct[]
Definition Octree.m:70
static BOOL isHitByOctree(Octree_details axialDetails, Octree_details otherDetails, Vector otherPosition, Triangle other_ijk)
Definition Octree.m:473
unsigned char * octree_collision
Definition Octree.m:51
GLfloat radius
Definition Octree.m:49
const int * octree
Definition Octree.m:50

References change_oct, isHitByOctree(), Octree_details::octree, Octree_details::octree_collision, OctreeDebugLog, offsetForOctant, Octree_details::radius, resolveVectorInIJK(), vector_add(), vector_flip(), vector_subtract(), Vector::x, Vector::y, and Vector::z.

Referenced by isHitByOctree:withOrigin:andIJK:, and isHitByOctree:withOrigin:andIJK:s1:s2:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isHitByOctree:withOrigin:andIJK:

- (BOOL) isHitByOctree: (Octree*) other
withOrigin: (Vector) origin
andIJK: (Triangle) ijk 

Definition at line 597 of file Octree.m.

597 :(Octree*)other withOrigin:(Vector)v0 andIJK:(Triangle)ijk
598{
599 if (other == nil)
600 return NO;
601
602 BOOL hit = isHitByOctree([self octreeDetails], [other octreeDetails], v0, ijk);
603
605 [other setHasCollision:[other hasCollision] || hit];
606
607 return hit;
608}
Octree_details octreeDetails()
Definition Octree.m:142
void setHasCollision:(BOOL value)
Definition Octree.m:137
BOOL hasCollision()
Definition Octree.m:132

References _hasCollision, hasCollision, isHitByOctree, isHitByOctree(), nil, octreeDetails, and setHasCollision:.

Here is the call graph for this function:

◆ isHitByOctree:withOrigin:andIJK:s1:s2:

- (BOOL) isHitByOctree: (Octree*) other
withOrigin: (Vector) origin
andIJK: (Triangle) ijk
s1: (GLfloat) s1
s2: (GLfloat) s2 

Definition at line 610 of file Octree.m.

610 :(Octree*)other withOrigin:(Vector)v0 andIJK:(Triangle)ijk s1:(GLfloat)s1 s2:(GLfloat)s2
611{
612 Octree_details details1 = [self octreeDetails];
613 Octree_details details2 = [other octreeDetails];
614
615 details1.radius *= s1;
616 details2.radius *= s2;
617
618 BOOL hit = isHitByOctree(details1, details2, v0, ijk);
619
621 [other setHasCollision:[other hasCollision] || hit];
622
623 return hit;
624}

References _hasCollision, hasCollision, isHitByOctree, isHitByOctree(), octreeDetails, Octree_details::radius, and setHasCollision:.

Here is the call graph for this function:

◆ octreeDetails

- (Octree_details) octreeDetails
implementation

Provided by category Octree(Private).

Definition at line 142 of file Octree.m.

143{
144 Octree_details details = {
145 .octree = _octree,
146 .radius = _radius,
147 .octree_collision = _collisionOctree
148 };
149 return details;
150}

References Octree(Private)::octreeDetails.

Referenced by isHitByOctree:withOrigin:andIJK:, isHitByOctree:withOrigin:andIJK:s1:s2:, Octree(Private)::octreeDetails, randomPoint, and volume.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ octreeScaledBy:

- (Octree *) octreeScaledBy: (GLfloat) factor

Definition at line 152 of file Octree.m.

152 :(GLfloat)factor
153{
154 // Since octree data is immutable, we can share.
155 return [[[Octree alloc] initWithData:_data radius:_radius * factor] autorelease];
156}

◆ offsetForOctant

+ (Vector) offsetForOctant (int) oct
(GLfloat) r 
implementation

Definition at line 158 of file Octree.m.

159{
160 return make_vector((0.5f - (GLfloat)((oct >> 2) & 1)) * r, (0.5f - (GLfloat)((oct >> 1) & 1)) * r, (0.5f - (GLfloat)(oct & 1)) * r);
161}

References make_vector().

Referenced by isHitByLineSub, isHitByOctree, and randomFullNodeFrom.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ randomFullNodeFrom

+ (Vector) randomFullNodeFrom (Octree_details) details
(Vector) offset 
implementation

Definition at line 683 of file Octree.m.

684{
685 const int* octBuffer = details.octree;
686 GLfloat octRadius = details.radius;
687
688 if (octBuffer[0] == 0)
689 return offset;
690 if (octBuffer[0] == -1)
691 return offset;
692
693 // We are not empty or solid.
694 // Pick a location from a random octant.
695 Octree_details nextDetails;
696 int nextLevel = octBuffer[0];
697 const int* nextBuffer = &octBuffer[nextLevel];
698 unsigned i, oct;
699
700 nextDetails.radius = 0.5f * octRadius;
701 nextDetails.octree_collision = NULL;
702 oct = Ranrot() & 7;
703
704 for (i = 0; i < 8; i++) {
705 int octant = oct ^ i;
706 if (nextBuffer[octant]) // don't test empty octants
707 {
708 nextDetails.octree = &nextBuffer[octant];
709 Vector voff = vector_add(offset, offsetForOctant(octant, octRadius));
710 return randomFullNodeFrom(nextDetails, voff);
711 }
712 }
713 return offset;
714}
static Vector randomFullNodeFrom(Octree_details details, Vector offset)
Definition Octree.m:683
voidpf uLong offset
Definition ioapi.h:132
unsigned Ranrot(void)

References Octree_details::octree, Octree_details::octree_collision, offsetForOctant, Octree_details::radius, randomFullNodeFrom(), Ranrot(), and vector_add().

Here is the call graph for this function:

◆ randomPoint

- (Vector) randomPoint

Definition at line 716 of file Octree.m.

717{
719}

References kZeroVector, octreeDetails, randomFullNodeFrom(), and randomPoint.

Referenced by ShipEntity::becomeExplosion, and randomPoint.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHasCollision:

- (void) setHasCollision: (BOOL) value
implementation

Definition at line 137 of file Octree.m.

137 :(BOOL)value
138{
139 _hasCollision = !!value;
140}

References _hasCollision.

Referenced by isHitByOctree:withOrigin:andIJK:, and isHitByOctree:withOrigin:andIJK:s1:s2:.

Here is the caller graph for this function:

◆ volume

- (GLfloat) volume

Definition at line 669 of file Octree.m.

670{
671 /* For backwards compatibility, limit octree iteration for volume
672 calculation to five levels. Raising the limit means lower calculated
673 volumes for large ships.
674
675 EMMSTRAN: consider raising the limit but fudging mass lock calculations
676 to compensate. See http://aegidian.org/bb/viewtopic.php?f=3&t=9176 .
677 Then again, five levels of iteration might be fine.
678 -- Ahruman 2011-03-10
679 */
680 return volumeOfOctree([self octreeDetails], 5);
681}
static GLfloat volumeOfOctree(Octree_details octree_details, unsigned depthLimit)
Definition Octree.m:634

References octreeDetails, volume, and volumeOfOctree().

Referenced by volume, and ShipEntity::volume.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ volumeOfOctree

+ (GLfloat) volumeOfOctree (Octree_details) octree_details
(unsigned) depthLimit 
implementation

Definition at line 634 of file Octree.m.

635{
636 const int* octBuffer = octree_details.octree;
637 GLfloat octRadius = octree_details.radius;
638
639 if (octBuffer[0] == 0) {
640 return 0.0f;
641 }
642
643 if (octBuffer[0] == -1 || depthLimit == 0) {
644 return octRadius * octRadius * octRadius;
645 }
646 depthLimit--;
647
648 // We are not empty or solid.
649 // We sum the volume of each of our octants.
650 GLfloat sumVolume = 0.0f;
651 Octree_details nextDetails;
652 int nextLevel = octBuffer[0];
653 const int* nextBuffer = &octBuffer[nextLevel];
654 unsigned i;
655
656 nextDetails.radius = 0.5f * octRadius;
657 nextDetails.octree_collision = NULL; // Placate static analyzer
658
659 for (i = 0; i < 8; i++) {
660 if (nextBuffer[i]) // don't test empty octants
661 {
662 nextDetails.octree = &nextBuffer[i];
663 sumVolume += volumeOfOctree(nextDetails, depthLimit);
664 }
665 }
666 return sumVolume;
667}

References Octree_details::octree, Octree_details::octree_collision, Octree_details::radius, and volumeOfOctree().

Here is the call graph for this function:

Member Data Documentation

◆ _collisionOctree

- (unsigned char*) _collisionOctree
private

Definition at line 44 of file Octree.h.

Referenced by dealloc, initWithData:radius:, and isHitByLine:v1:.

◆ _data

- (NSData*) _data
private

Definition at line 46 of file Octree.h.

Referenced by dealloc, and initWithData:radius:.

◆ _hasCollision

- (BOOL) _hasCollision
private

◆ _nodeCount

- (uint32_t) _nodeCount
private

Definition at line 40 of file Octree.h.

Referenced by initWithData:radius:, and isHitByLine:v1:.

◆ _octree

- (const int*) _octree
private

Definition at line 41 of file Octree.h.

Referenced by initWithData:radius:, and isHitByLine:v1:.

◆ _radius

- (GLfloat) _radius
private

Definition at line 39 of file Octree.h.

Referenced by initWithData:radius:, and isHitByLine:v1:.


The documentation for this class was generated from the following files: