-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCamera.m
228 lines (172 loc) · 6.26 KB
/
Camera.m
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
226
227
228
//
// Camera.m
// EG-TD
//
// Created by Gurcan Yavuz on 10/8/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "Camera.h"
#import "GameScene.h"
#import "ball.h"
#import "RaceBall.h"
#import "EG_TDAppDelegate.h"
@implementation Camera
@synthesize collideCube;
@synthesize readyCheck;
@synthesize cameraZ;
@synthesize lookUpX;
@synthesize lookUpY;
@synthesize lookUpZ;
@synthesize xDifference;
@synthesize yDifference;
@synthesize oldPosition;
@synthesize raceBall;
- (void)dealloc {
[super dealloc];
}
#pragma mark -
#pragma mark Init
- (id)initWithTileLocation:(EGVertex3D)startLocation {
self = [super init];
if (self != nil) {
_sharedDirector = [Director sharedDirector];
position.x = startLocation.x;
position.y = startLocation.y;
position.z = startLocation.z;
otherBall.x = startLocation.x;
otherBall.y = startLocation.y;
otherBall.z = startLocation.z;
raceBall = [[RaceBall alloc] initWithTileLocation:Vector3fMake(0, 0, 0)];
oldPosition = position.x;
// Set up the spritesheets that will give us out player animation
// Speed at which the player moves
_cameraSpeed = 0.04f;
// Set the players state to alive
entityState = kEntity_Alive;
lookUpX = 0;
lookUpZ = 0;
}
return self;
}
#pragma mark -
#pragma mark Update
- (void)update:(GLfloat)aDelta {
_scene = (GameScene*)[_sharedDirector currentScene];
xDifference = [(GameScene*)[_sharedDirector currentScene] xDifference];
yDifference = [(GameScene*)[_sharedDirector currentScene] yDifference];
collideCube = [(GameScene*)[_sharedDirector currentScene] collideCube];
readyCheck = [(GameScene*)[_sharedDirector currentScene] readyCheck];
// position.x -= xDifference*kMapAcceloremeter;
// position.z -= yDifference*kMapAcceloremeter;
// lookUpZ -= yDifference*kMapAcceloremeter;
// lookUpX -= xDifference*kMapAcceloremeter;
//
//NSLog(@"%f",collideCube);
if (readyCheck != 1)
{
// NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"20",@"x",@"20",@"y",@"20",@"z", nil];
// [[(EG_TDAppDelegate*)[[UIApplication sharedApplication] delegate] mClient] sendXtMessage:@"bb" cmd:@"upd" paramObj:dic type:@"xml" roomId:41];
static float velocityOfBall = 0;
if (collideCube == 0)
{
velocityOfBall += 0.005;
if (velocityOfBall > MAX_Acceleration)
{
velocityOfBall = MAX_Acceleration;
}
position.z += velocityOfBall;
lookUpZ +=velocityOfBall;
}
else
{
//NSLog(@"VELOCITY %f",velocityOfBall);
if (velocityOfBall-0.5<0)
{
velocityOfBall = 0 ;
}
else
{
// NSLog(@"GIRDINMI");
velocityOfBall-=0.5;
}
}
/// position.z += 0.1;
// lookUpZ +=0.1;
oldPosition = position.x;
position.x += xDifference*1.5;
lookUpX += xDifference*1.5;
// GLfloat x = position.x*0.6/0.55;
// NSString * x = [NSString stringWithFormat:@"%f",position.x*0.6/0.55];
// NSString * y = [NSString stringWithFormat:@"%f",position.y];
// NSString * z = [NSString stringWithFormat:@"%f",position.z+20];
}
//[raceBall update:aDelta xPos:xDifference*1.1 yPos:position.y zPos:position.z oldPos:oldPosition];
}
- (void)updateX:(NSString *)xPos updateY:(NSString *)yPos updateZ:(NSString *)zPos
{
otherBall.x = [xPos floatValue];
otherBall.y = [yPos floatValue];
otherBall.z = [zPos floatValue];
}
#pragma mark -
#pragma mark Render
- (void)render {
// [raceBall render];
/* glPushMatrix();
glLoadIdentity();
glScalef(0.6, 0.6, 0.6);
// glScalef(0.6, 0.2, 0.6);
glColor4f(1, 0, 0, 1);
glTranslatef(position.x-oldPosition, -5, -15);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(vertexData), &MeshVertexData[0].vertex);
glNormalPointer(GL_FLOAT, sizeof(vertexData), &MeshVertexData[0].normal);
glDrawArrays(GL_TRIANGLES, 0, 2880);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glPopMatrix();
*/
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(position.x, position.y, position.z, lookUpX,0 , lookUpZ, 0, 1, 0);
glPushMatrix();
//glLoadIdentity();
// glScalef(0.6, 0.2, 0.6);
glColor4f(1, 0, 0, 1);
// glTranslatef(-oldPosition.x, -1, -oldPosition.z);
// NSLog(@"%f %f",position.x*1/0.55,position.z*1/0.6+20);
// NSLog(@"GAME X %f GAME Z %f",position.x,position.z);
glTranslatef(position.x*0.6/0.55, 0, position.z+20);
glScalef(0.6, 0.6, 0.6);
// glTranslatef(position.x, 0, position.z+20);
// glP
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(vertexData), &MeshVertexData[0].vertex);
glNormalPointer(GL_FLOAT, sizeof(vertexData), &MeshVertexData[0].normal);
glDrawArrays(GL_TRIANGLES, 0, 2880);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glPopMatrix();
glPushMatrix();
//glLoadIdentity();
// glScalef(0.6, 0.2, 0.6);
glColor4f(0, 1, 0, 1);
// glTranslatef(-oldPosition.x, -1, -oldPosition.z);
// NSLog(@"%f %f",position.x*1/0.55,position.z*1/0.6+20);
// NSLog(@"GAME X %f GAME Z %f",position.x,position.z);
glTranslatef(otherBall.x, 0, otherBall.z);
glScalef(0.6, 0.6, 0.6);
// glTranslatef(position.x, 0, position.z+20);
// glP
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(vertexData), &MeshVertexData[0].vertex);
glNormalPointer(GL_FLOAT, sizeof(vertexData), &MeshVertexData[0].normal);
glDrawArrays(GL_TRIANGLES, 0, 2880);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glPopMatrix();
}
@end