Oolite
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
26#import "OODrawable.h"
28#import "ShipEntity.h"
29#import "Universe.h"
30
31@implementation OOEntityWithDrawable
32
33- (void)dealloc
34{
35 [drawable release];
36 drawable = nil;
37
38 [super dealloc];
39}
40
42{
43 return drawable;
44}
45
46- (void)setDrawable:(OODrawable*)inDrawable
47{
48 if (inDrawable != drawable) {
49 [drawable autorelease];
50 drawable = [inDrawable retain];
52
56 }
57}
58
60{
62}
63
64- (void)drawImmediate:(bool)immediate translucent:(bool)translucent
65{
67 // Don't draw.
68 return;
69 }
70
71 if (no_draw_distance != INFINITY && ![self isImmuneToBreakPatternHide]) {
72 // (always draw sky, always draw break patterns)
73 if (![self isSubEntity]) {
74 GLfloat clipradius = collision_radius;
75 if ([self isShip]) {
76 ShipEntity* shipself = (ShipEntity*)self;
77 clipradius = [shipself frustumRadius];
78 } else if ([self isVisualEffect]) {
80 clipradius = [veself frustumRadius];
81 }
82 // don't bother with frustum culling within/near collision radius, as
83 // potential for problems with floating point inaccuracy causing
84 // unwanted disappearance maybe fix
85 // http://aegidian.org/bb/viewtopic.php?f=3&t=13619 - CIM
86 if (cam_zero_distance > (clipradius + 1000) * (clipradius + 1000)) {
87 if (![UNIVERSE viewFrustumIntersectsSphereAt:cameraRelativePosition withRadius:clipradius]) {
88 return;
89 }
90 }
91 } else // is subentity
92 {
93 // don't bother with frustum culling within 1km, as above - CIM
94 if (cam_zero_distance > (collision_radius + 1000) * (collision_radius + 1000)) {
95 // check correct sub-entity position
96 if (![UNIVERSE viewFrustumIntersectsSphereAt:cameraRelativePosition withRadius:[self collisionRadius]]) {
97 return;
98 }
99 }
100 }
101 }
102
103 if ([UNIVERSE wireframeGraphics])
105
106 if (translucent)
108 else
110
111 if ([UNIVERSE wireframeGraphics])
113}
114
115#ifdef OO_DEBUG_MONITOR_ENABLED
116- (NSSet*)allTextures
117{
118 return [[self drawable] allTextures];
119}
120#endif
121
122@end
void OOGLWireframeModeOn(void)
Definition OOOpenGL.m:85
void OOGLWireframeModeOff(void)
Definition OOOpenGL.m:100
return nil
#define UNIVERSE
Definition Universe.h:827
unsigned isImmuneToBreakPatternHide
Definition Entity.m:1050
GLfloat collision_radius
Definition Entity.h:107
unsigned isVisualEffect
Definition Entity.m:185
unsigned isSubEntity
Definition Entity.m:140
unsigned isShip
Definition Entity.m:125
GLfloat collisionRadius()
Definition Entity.m:830
Vector cameraRelativePosition
Definition Entity.m:581
GLfloat cam_zero_distance
Definition Entity.h:105
BoundingBox boundingBox
Definition Entity.m:666
GLfloat no_draw_distance
Definition Entity.h:106
void dealloc()
Definition Entity.m:98
void renderTranslucentParts()
Definition OODrawable.m:37
GLfloat collisionRadius()
Definition OODrawable.m:51
void renderOpaqueParts()
Definition OODrawable.m:33
GLfloat maxDrawDistance()
Definition OODrawable.m:56
BoundingBox boundingBox()
Definition OODrawable.m:61
void setBindingTarget:(id< OOWeakReferenceSupport > target)
Definition OODrawable.m:66
GLfloat frustumRadius()
Definition ShipEntity.m:822