-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestScenario.m
More file actions
225 lines (150 loc) · 5.62 KB
/
Copy pathTestScenario.m
File metadata and controls
225 lines (150 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//
// TestScenario.m
// VisualFeedback
//
// Created by Nicole Lehrer on 5/16/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "TestScenario.h"
#import "VisualFeedback.h"
#import "Texture2d.h"
#import "TravelController.h"
@implementation TestScenario
@synthesize gVisualFeedback;
@synthesize gWaterScape;
@synthesize timer;
@synthesize displacement;
@synthesize resetDisplacementAnimation;
@synthesize testControl;
@synthesize scenarioDrawer;
+ (id) createWithName:(NSString *)aName parent:(Node *)aParent
{
ReturnNilIfObjectIsNil( aName );
ReturnNilIfObjectIsNil( aParent );
logDebug( @"TestScenario.createWithName( %@ ) parent( %@ )", aName, aParent.name );
TestScenario * node = [[TestScenario alloc] initWithName:aName parent:aParent];
ReturnNilIfObjectIsNil( node );
return node;
}
#pragma mark ---- initializers ----
- (id) initWithName:(NSString *)aName parent:(Node *)aParent
{
self = [super initWithName:aName parent:aParent];
if (self) {
self.testControl = [[TravelController alloc] initWithStartValue:0 andEndValue:1000 andDurationInSec:3];
timer = [TimeController timekeeper]; //create timer
NSString * resourcesPath = [[NSBundle bundleForClass:[self class]] resourcePath];
waterTexture = [[TextureController textureController] createTexture2dWithImage:[resourcesPath stringByAppendingPathComponent: @"/textures/waterWood/base2.png"] target:GL_TEXTURE_2D];
waterTextureUp = [[TextureController textureController] createTexture2dWithImage:[resourcesPath stringByAppendingPathComponent: @"/textures/waterWood/base2Up.png"] target:GL_TEXTURE_2D];
// [self setUpWater];
displacementAnimation = [[DAnimateFloat alloc] initWithObject:self path:@"displacement" from:0.0 to:100.0 duration:3];
displacementAnimation.mode = DANIMATE_INTERP_EASE_IN_EASE_OUT;
// scenarioDrawer = [ScenarioDrawer createWithName:@"ScenarioDrawer" parent:[Dash root]];
}
return self;
}
-(void) setUpWater
{
self.gWaterScape = [WaterScape createWithName:@"WaterScape" parent:[Dash root] withGridDims:500 andShaderID:3];
self.gWaterScape.transX = 0;
self.gWaterScape.transY = 0;
self.gWaterScape.transZ = 0;
self.gWaterScape.rotX = 0;
self.gWaterScape.scaledX = 1;
self.gWaterScape.scaledY = 1;
self.gWaterScape.scaledZ = 1;
self.gWaterScape.ampX = 2.631579;
self.gWaterScape.ampY = 2.631579;
self.gWaterScape.freqX = .2105;
self.gWaterScape.freqY = .2105;
self.gWaterScape.timeFactorX = 10;
self.gWaterScape.timeFactorY = 5;
self.gWaterScape.useHeightCalc = 1;
self.gWaterScape.seg = 0;
}
-(void) drawWater
{
// NSLog(@"time is: %f", [timer time]);
//[self.gWaterScape drawWaterWithTextureType1:waterTexture andTextureType2:waterTexture andOpacity:1];
[self.gWaterScape drawWaterWithTextureType1:waterTextureUp andTextureType2:waterTextureUp andOpacity:1 ];
}
- (void) setVisualFeedback:(VisualFeedback *)f
{
self.gVisualFeedback = f;
}
//from DASH animation
static float smoothstep( float min, float max, float value )
{
if (value <= 0.0) {
return min;
}
else if (value >= 1.0) {
return max;
}
else {
float y = value * value * (3.0 - 2.0 * value);
return (min + ((max - min) * y));
}
}
-(float) easeInFrom:(float)startValue to:(float)endValue
startingAt:(float)startTime until:(float)endTime
withSpeedMultiplier:(float)speedMultiplier
{
float newValue;
// if([timekeeper time]*100 > startTime && [timekeeper time]*100 < endTime)
{
// glPushMatrix();
// glColor4f(1, 1, 1, 1);
newValue = smoothstep(startValue, endValue, ([timer time]*100-startTime)*speedMultiplier); //if == 1, duration = 100 f
// glTranslated(newValue, 0, 0);
// [dotBod bindTexture];
//
// [self glQuadCallWithHeight:500 andWidth:500];
// glPopMatrix();
}
return newValue;
}
-(void) calcDisplacement
{
// if(turnOnAnimation)
{
if(self.displacement == 0)
{
[displacementAnimation resetFrom:self.displacement to:500 duration:3.0]; //for a fixed duration
[DAnimation animate:displacementAnimation];
}
if(self.displacement == 500)
{
[displacementAnimation resetFrom:self.displacement to:501 duration:3.0]; //for a fixed duration
[DAnimation animate:displacementAnimation];
}
if(self.displacement == 501)
{
[displacementAnimation resetFrom:self.displacement to:1000 duration:3.0]; //for a fixed duration
[DAnimation animate:displacementAnimation];
}
}
}
-(void) resetDisplacement
{
// [displacementAnimation resetFrom:self.displacement to:0 duration:1.0]; //for a fixed duration
// [DAnimation animate:displacementAnimation];
[testControl resetDisplacement];
}
-(void) drawShape:(GraphicsState *)state
{
glDisable( GL_DEPTH_TEST );
glEnable( GL_BLEND );
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
// glEnable( GL_TEXTURE_2D );
// glEnable(GL_LIGHTING);
// float shiftX = smoothstep(-1000, 1000, fabs(sin([timer time]))); //if == 1, duration = 100 f
// [self calcDisplacement];
displacement = [testControl calcDisplacement];
// NSLog(@"displacement from testScenario %f", displacement);
glTranslated(displacement, 0, 0);
glColor4f(1, 0, 1, 1);
// drawSolidCube(300);
// [self drawWater];
}
@end