Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOEntityWithDrawable.m
Go to the documentation of this file.
1/*
2
3OOEntityWithDrawable.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
25
27#import "OODrawable.h"
28#import "Universe.h"
29#import "ShipEntity.h"
31
32@implementation OOEntityWithDrawable
33
34- (void)dealloc
35{
36 [drawable release];
37 drawable = nil;
38
39 [super dealloc];
40}
41
42
44{
45 return drawable;
46}
47
48
49- (void)setDrawable:(OODrawable *)inDrawable
50{
51 if (inDrawable != drawable)
52 {
53 [drawable autorelease];
54 drawable = [inDrawable retain];
55 [drawable setBindingTarget:self];
56
57 collision_radius = [drawable collisionRadius];
58 no_draw_distance = [drawable maxDrawDistance];
59 boundingBox = [drawable boundingBox];
60 }
61}
62
63
64- (double)findCollisionRadius
65{
66 return [drawable collisionRadius];
67}
68
69
70- (void) drawImmediate:(bool)immediate translucent:(bool)translucent
71{
73 {
74 // Don't draw.
75 return;
76 }
77
78 if (no_draw_distance != INFINITY && ![self isImmuneToBreakPatternHide])
79 {
80 // (always draw sky, always draw break patterns)
81 if (![self isSubEntity])
82 {
83 GLfloat clipradius = collision_radius;
84 if ([self isShip])
85 {
86 ShipEntity* shipself = (ShipEntity*)self;
87 clipradius = [shipself frustumRadius];
88 }
89 else if ([self isVisualEffect])
90 {
92 clipradius = [veself frustumRadius];
93 }
94 // don't bother with frustum culling within/near collision radius, as
95 // potential for problems with floating point inaccuracy causing
96 // unwanted disappearance maybe fix
97 // http://aegidian.org/bb/viewtopic.php?f=3&t=13619 - CIM
98 if (cam_zero_distance > (clipradius+1000)*(clipradius+1000))
99 {
100 if (![UNIVERSE viewFrustumIntersectsSphereAt:cameraRelativePosition withRadius:clipradius])
101 {
102 return;
103 }
104 }
105 }
106 else // is subentity
107 {
108 // don't bother with frustum culling within 1km, as above - CIM
110 {
111 // check correct sub-entity position
112 if (![UNIVERSE viewFrustumIntersectsSphereAt:cameraRelativePosition withRadius:[self collisionRadius]])
113 {
114 return;
115 }
116 }
117 }
118 }
119
120 if ([UNIVERSE wireframeGraphics]) OOGLWireframeModeOn();
121
122 if (translucent) [drawable renderTranslucentParts];
123 else [drawable renderOpaqueParts];
124
125 if ([UNIVERSE wireframeGraphics]) OOGLWireframeModeOff();
126}
127
128
129#ifndef NDEBUG
130- (NSSet *) allTextures
131{
132 return [[self drawable] allTextures];
133}
134#endif
135
136@end
void OOGLWireframeModeOn(void)
Definition OOOpenGL.m:87
void OOGLWireframeModeOff(void)
Definition OOOpenGL.m:103
return nil
#define UNIVERSE
Definition Universe.h:833
unsigned isImmuneToBreakPatternHide
Definition Entity.h:102
GLfloat collision_radius
Definition Entity.h:111
unsigned isVisualEffect
Definition Entity.h:104
unsigned isSubEntity
Definition Entity.h:95
unsigned isShip
Definition Entity.h:91
GLfloat collisionRadius()
Definition Entity.m:905
Vector cameraRelativePosition
Definition Entity.h:113
GLfloat cam_zero_distance
Definition Entity.h:109
BoundingBox boundingBox
Definition Entity.h:145
GLfloat no_draw_distance
Definition Entity.h:110
void dealloc()
Definition Entity.m:101
GLfloat frustumRadius()
Definition ShipEntity.m:890