Oolite
Loading...
Searching...
No Matches
OORingEffectEntity.m
Go to the documentation of this file.
1/*
2
3OORingEffectEntity.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
27#import "OOMacroOpenGL.h"
28#import "Universe.h"
29
30#define kRingDuration (2.0f) // seconds
31#define kRingAttack (0.4f) // fade-up time
32
33// Dimensions and growth rates per second in terms of base size.
34#define kInnerRingInitialSizeFactor (0.5f)
35#define kOuterRingInitialSizeFactor (1.25f * kInnerRingInitialSizeFactor)
36#define kInnerRingGrowthRateFactor (1.1f * kInnerRingInitialSizeFactor)
37#define kOuterRingGrowthRateFactor (1.25f * kInnerRingInitialSizeFactor)
38
39// These factors produce a ring that shrinks to nothing, then expands to the size of a "normal" ring.
40#define kShrinkingRingInnerGrowthFactor (-2.5)
41#define kShrinkingRingOuterGrowthFactor (-2.0)
42
43enum {
45};
46static struct {
47 float x, y;
48} sCircleVerts[kCircleSegments]; // holds vector coordinates for a unit circle
49
50@implementation OORingEffectEntity
51
53{
54 unsigned i;
55 for (i = 0; i < kCircleSegments; i++) {
56 sCircleVerts[i].x = sinf(i * 2 * M_PI / (kCircleSegments - 1));
57 sCircleVerts[i].y = cosf(i * 2 * M_PI / (kCircleSegments - 1));
58 }
59}
60
61- (id)initRingFromEntity:(Entity*)sourceEntity
62{
63 if (sourceEntity == nil) {
64 [self release];
65 return nil;
66 }
67
68 if ((self = [super init])) {
69 GLfloat baseSize = [sourceEntity collisionRadius];
74
78
79 [self setStatus:STATUS_EFFECT];
80 [self setScanClass:CLASS_NO_DRAW];
81
82 [self setOwner:sourceEntity];
83 }
84
85 return self;
86}
87
88+ (instancetype)ringFromEntity:(Entity*)sourceEntity
89{
90 return [[[self alloc] initRingFromEntity:sourceEntity] autorelease];
91}
92
93+ (instancetype)shrinkingRingFromEntity:(Entity*)sourceEntity
94{
95 OORingEffectEntity* result = [self ringFromEntity:sourceEntity];
96 if (result != nil) {
99 }
100 return result;
101}
102
104{
105 return [NSString stringWithFormat:@"%f seconds passed of %f", _timePassed, kRingDuration];
106}
107
108- (void)update:(OOTimeDelta)delta_t
109{
110 [super update:delta_t];
111 _timePassed += delta_t;
112
113 _innerRadius += delta_t * _innerGrowthRate;
114 _outerRadius += delta_t * _outerGrowthRate;
115
117 [UNIVERSE removeEntity:self];
118 }
119}
120
121- (void)drawImmediate:(bool)immediate translucent:(bool)translucent
122{
123 if (!translucent || [UNIVERSE breakPatternHide])
124 return;
125
128
129 GLfloat alpha = OOClamp_0_1_f((kRingDuration - _timePassed) / kRingAttack);
130
131 GLfloat ex_em_hi[4] = { 0.6, 0.8, 1.0, alpha }; // pale blue
132 GLfloat ex_em_lo[4] = { 0.2, 0.0, 1.0, 0.0 }; // purplish-blue-black
133
134 OOGLBEGIN(GL_TRIANGLE_STRIP);
135 for (unsigned i = 0; i < kCircleSegments; i++) {
136 glColor4fv(ex_em_lo);
137 glVertex3f(_innerRadius * sCircleVerts[i].x, _innerRadius * sCircleVerts[i].y, 0.0f);
138 glColor4fv(ex_em_hi);
139 glVertex3f(_outerRadius * sCircleVerts[i].x, _outerRadius * sCircleVerts[i].y, 0.0f);
140 }
141 OOGLEND();
142
144 OOCheckOpenGLErrors(@"OOQuiriumCascadeEntity after drawing %@", self);
145}
146
147- (BOOL)isEffect
148{
149 return YES;
150}
151
153{
154 return NO;
155}
156
157@end
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
#define OO_ENTER_OPENGL()
#define M_PI
Definition OOMaths.h:54
#define OOGLBEGIN
Definition OOOpenGL.h:269
@ OPENGL_STATE_ADDITIVE_BLENDING
Definition OOOpenGL.h:123
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:38
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGLEND
Definition OOOpenGL.h:270
return nil
static struct @114234231373144364274312201276352366175106111125 sCircleVerts[kCircleSegments]
#define kRingDuration
#define kOuterRingGrowthRateFactor
#define kRingAttack
#define kInnerRingGrowthRateFactor
@ kCircleSegments
float y
#define kShrinkingRingInnerGrowthFactor
#define kOuterRingInitialSizeFactor
float x
#define kInnerRingInitialSizeFactor
#define kShrinkingRingOuterGrowthFactor
double OOTimeDelta
Definition OOTypes.h:193
#define UNIVERSE
Definition Universe.h:827
void setVelocity:(Vector vel)
Definition Entity.m:703
Quaternion orientation
Definition Entity.m:682
void setOrientation:(Quaternion quat)
Definition Entity.m:676
void update:(OOTimeDelta delta_t)
Definition Entity.m:850
GLfloat collisionRadius()
Definition Entity.m:830
void setOwner:(Entity *ent)
Definition Entity.m:542
void setScanClass:(OOScanClass sClass)
Definition Entity.m:738
HPVector position
Definition Entity.m:576
Vector velocity
Definition Entity.m:708
id init()
Definition Entity.m:64
void setStatus:(OOEntityStatus stat)
Definition Entity.m:728
void setPosition:(HPVector posn)
Definition Entity.m:608
instancetype ringFromEntity:(Entity *sourceEntity)
NSString * descriptionComponents()