59 |
_init = NO; |
_init = NO; |
60 |
_initModel = NO; |
_initModel = NO; |
61 |
_cam = [Camera alloc]; |
_cam = [Camera alloc]; |
62 |
|
_tabModel = [NSMutableArray new]; |
63 |
[_cam initWithFovy: 60 |
|
64 |
|
|
65 |
|
[_cam initWithFovy: 60 |
66 |
aspect: 1.0 |
aspect: 1.0 |
67 |
zNear: 0.01 |
zNear: 0.01 |
68 |
zFar: 10000.0 |
zFar: 10000.0 |
69 |
eye: MakeCoord (0.0,0.0,100.0) |
eye: MakeCoord (0.0,0.0,100.0) |
70 |
center: MakeCoord (0.0,0.0,0.0) |
center: MakeCoord (0.0,0.0,0.0) |
71 |
up: MakeCoord (0.0,1.0,0.0) ]; |
up: MakeCoord (0.0,1.0,0.0) ]; |
|
|
|
|
// gluLookAt((GLdouble)[_cam eye].x, |
|
|
// (GLdouble)[_cam eye].y, |
|
|
// (GLdouble)[_cam eye].z,// +distance, |
|
|
// (GLdouble)[_cam center].x, |
|
|
// (GLdouble)[_cam center].y, |
|
|
// (GLdouble)[_cam center].z, |
|
|
// (GLdouble)[_cam up].x, |
|
|
// (GLdouble)[_cam up].y, |
|
|
// (GLdouble)[_cam up].z); |
|
|
|
|
72 |
|
|
73 |
// [_cam initWithFovy: 360 |
// gluLookAt((GLdouble)[_cam eye].x, |
74 |
// aspect: 1.0 |
// (GLdouble)[_cam eye].y, |
75 |
// zNear: 1.0 |
// (GLdouble)[_cam eye].z,// +distance, |
76 |
// zFar: 10000.0 |
// (GLdouble)[_cam center].x, |
77 |
// eye: MakeCoord (0.0,0.0,-100.0) |
// (GLdouble)[_cam center].y, |
78 |
// center: MakeCoord (0.0,0.0,0.0) |
// (GLdouble)[_cam center].z, |
79 |
// up: MakeCoord (0.0,1.0,0.0) ]; |
// (GLdouble)[_cam up].x, |
80 |
|
// (GLdouble)[_cam up].y, |
81 |
|
// (GLdouble)[_cam up].z); |
82 |
|
|
83 |
|
|
84 |
|
// [_cam initWithFovy: 360 |
85 |
|
// aspect: 1.0 |
86 |
|
// zNear: 1.0 |
87 |
|
// zFar: 10000.0 |
88 |
|
// eye: MakeCoord (0.0,0.0,-100.0) |
89 |
|
// center: MakeCoord (0.0,0.0,0.0) |
90 |
|
// up: MakeCoord (0.0,1.0,0.0) ]; |
91 |
} |
} |
92 |
|
|
93 |
return self; |
return self; |
96 |
- (void) dealloc |
- (void) dealloc |
97 |
{ |
{ |
98 |
RELEASE(_cam); |
RELEASE(_cam); |
99 |
|
RELEASE(_tabModel); |
100 |
[super dealloc]; |
[super dealloc]; |
101 |
} |
} |
102 |
|
|
103 |
- (BOOL) initGL |
- (BOOL) initGL |
104 |
{ |
{ |
105 |
|
glEnable (GL_TEXTURE_2D); |
106 |
glShadeModel (GL_SMOOTH); |
glShadeModel (GL_SMOOTH); |
107 |
glClearColor (0.8f, 0.8f, 0.8f, 0.0f); |
glClearColor (0.5f, 0.5f, 0.5f, 0.0f); |
108 |
glEnable (GL_DEPTH_TEST); |
glEnable (GL_DEPTH_TEST); |
109 |
glEnable (GL_TEXTURE_2D); |
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |
110 |
|
// glDepthFunc(GL_LEQUAL); |
111 |
|
|
112 |
|
|
113 |
[NSTimer scheduledTimerWithTimeInterval: 0.0 |
|
114 |
|
[NSTimer scheduledTimerWithTimeInterval: 0.01 |
115 |
target: self |
target: self |
116 |
selector: @selector(display) |
selector: @selector(display) |
117 |
userInfo: nil |
userInfo: nil |
118 |
repeats: YES]; |
repeats: YES]; |
119 |
|
|
120 |
gluLookAt((GLdouble)[_cam eye].x, |
gluLookAt((GLdouble)[_cam eye].x, |
135 |
NSRect sceneBounds; |
NSRect sceneBounds; |
136 |
|
|
137 |
sceneBounds = [self bounds]; |
sceneBounds = [self bounds]; |
138 |
glViewport (0, 0, sceneBounds.size.width, sceneBounds.size.height); |
// glViewport (0, 0, sceneBounds.size.width, sceneBounds.size.height); |
139 |
|
|
140 |
glMatrixMode (GL_PROJECTION); |
glMatrixMode (GL_PROJECTION); |
141 |
glLoadIdentity (); |
glLoadIdentity (); |
158 |
|
|
159 |
if (!_initModel) |
if (!_initModel) |
160 |
{ |
{ |
161 |
|
_tabModel = [_fileControl modelBase]; |
162 |
_initModel = YES; |
if(_tabModel && [_tabModel count] > 0) |
163 |
|
_affiche = YES; |
164 |
} |
} |
165 |
|
|
|
|
|
166 |
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
167 |
glPolygonMode(GL_FRONT_AND_BACK,polyMode); |
glPolygonMode(GL_FRONT_AND_BACK,polyMode); |
|
|
|
168 |
glLoadIdentity(); |
glLoadIdentity(); |
169 |
|
|
170 |
gluLookAt((GLdouble)[_cam eye].x, |
gluLookAt((GLdouble)[_cam eye].x, |
178 |
(GLdouble)[_cam up].z); |
(GLdouble)[_cam up].z); |
179 |
glRotatef(-90,1.0,0.0,0.0); |
glRotatef(-90,1.0,0.0,0.0); |
180 |
|
|
181 |
if (_affiche) |
if (_affiche) |
182 |
{ |
{ |
183 |
// [_model displayWithFrustum: nil]; |
int i= 0; |
184 |
glBegin(GL_POLYGON); |
for(i = 0; i< [_tabModel count]; i++) |
185 |
glVertex3f(10.0,0.0,0.0); |
{ |
186 |
glVertex3f(0.0,10.0,0.0); |
NSString* tag = [_fileControl tagNameForModelNumber: i]; |
187 |
glVertex3f(0.0,0.0,10.0); |
[[_tabModel objectAtIndex: i] displayWithFrustum: nil]; |
188 |
glEnd(); |
|
189 |
|
if (tag && [tag length] > 0) |
190 |
|
[[_tabModel objectAtIndex: i] link: tag]; |
191 |
|
} |
192 |
} |
} |
193 |
|
|
194 |
[self update]; |
[self update]; |
195 |
[[self openGLContext] flushBuffer]; |
[[self openGLContext] flushBuffer]; |
196 |
} |
} |
198 |
- (void)mouseDragged: (NSEvent *) theEvent |
- (void)mouseDragged: (NSEvent *) theEvent |
199 |
{ |
{ |
200 |
coord_t rep = [_control mouseMove: theEvent]; |
coord_t rep = [_control mouseMove: theEvent]; |
|
|
|
|
[self rotatePitch2: rep.y]; |
|
|
|
|
|
if (ScalarProduct([_cam up],[_cam dir]) != 0) |
|
|
printf("bad,bad,bad,bad dir or up %g \n", |
|
|
ScalarProduct([_cam up],[_cam dir]) ); |
|
|
|
|
|
if (ScalarProduct([_cam up],[_cam ortho]) != 0) |
|
|
printf("bad,bad,bad,bad ortho or up %g\n", |
|
|
ScalarProduct([_cam up],[_cam ortho]) ); |
|
|
|
|
|
if (ScalarProduct([_cam dir],[_cam ortho]) != 0) |
|
|
printf("bad,bad,bad,bad ortho or dir %g\n", |
|
|
ScalarProduct([_cam ortho],[_cam dir]) ); |
|
|
|
|
201 |
|
|
202 |
printf("eye x = %g \n", [_cam eye].x); |
[_cam rotateAroundViewHeading: rep.x]; |
203 |
printf("eye y = %g \n", [_cam eye].y); |
[_cam rotateAroundViewPitch: rep.y]; |
204 |
printf("eye z = %g \n", [_cam eye].z); |
[_fileControl update]; |
205 |
|
|
206 |
printf("center x = %g \n", [_cam center].x); |
// [_cam rotatePitch: rep.y]; |
|
printf("center y = %g \n", [_cam center].y); |
|
|
printf("center z = %g \n", [_cam center].z); |
|
|
|
|
|
printf("up x = %g \n", [_cam up].x); |
|
|
printf("up y = %g \n", [_cam up].y); |
|
|
printf("up z = %g \n", [_cam up].z); |
|
|
|
|
|
printf("dir x = %g \n", [_cam dir].x); |
|
|
printf("dir y = %g \n", [_cam dir].y); |
|
|
printf("dir z = %g \n\n", [_cam dir].z); |
|
207 |
|
|
208 |
}; |
}; |
209 |
|
|
234 |
[_cam move: rep]; |
[_cam move: rep]; |
235 |
break; |
break; |
236 |
} |
} |
237 |
|
[_fileControl update]; |
238 |
return YES; |
return YES; |
239 |
|
|
240 |
} |
} |
241 |
|
|
242 |
- (void) scrollWheel: (NSEvent *) theEvent |
- (void) scrollWheel: (NSEvent *) theEvent |
243 |
{ |
{ |
244 |
|
coord_t pos = [_control scrollWheelControl: theEvent |
245 |
|
withDir: [_cam dir]]; |
246 |
|
[_cam move: pos]; |
247 |
|
[_fileControl update]; |
248 |
|
// [_cam initWithFovy: [_cam fovy] |
249 |
|
// aspect: [_cam aspect] |
250 |
|
// zNear: [_cam zNear] |
251 |
|
// zFar: [_cam zFar] |
252 |
|
// eye: AddCoord([_cam eye],pos) |
253 |
|
// center: [_cam center] |
254 |
|
// up: [_cam up]]; |
255 |
|
|
|
coord_t pos = [_cam eye]; |
|
|
pos = [_control scrollWheelControl: theEvent |
|
|
withDir: [_cam dir]]; |
|
|
[_cam move: pos]; |
|
|
|
|
|
printf("eye x = %g \n", [_cam eye].x); |
|
|
printf("eye y = %g \n", [_cam eye].y); |
|
|
printf("eye z = %g \n", [_cam eye].z); |
|
|
|
|
|
printf("center x = %g \n", [_cam center].x); |
|
|
printf("center y = %g \n", [_cam center].y); |
|
|
printf("center z = %g \n", [_cam center].z); |
|
|
|
|
|
printf("up x = %g \n", [_cam up].x); |
|
|
printf("up y = %g \n", [_cam up].y); |
|
|
printf("up z = %g \n\n", [_cam up].z); |
|
|
} |
|
|
|
|
|
- (void) rotateHeading2: (double)heading |
|
|
{ |
|
|
coord_t newDir; |
|
|
coord_t newCenter; |
|
|
|
|
|
newCenter = [_cam rotateByAngle: heading |
|
|
vector: NormalizeVector ([_cam up]) |
|
|
point: [_cam center]]; |
|
|
|
|
|
[_cam move: MultCoord([_cam center],-1.0)]; |
|
|
|
|
|
newDir = [_cam rotateByAngle: heading |
|
|
vector: NormalizeVector ([_cam up]) |
|
|
point: [_cam eye]]; |
|
|
|
|
|
// [_cam setEye: AddCoord([_cam center], newDir)]; |
|
|
|
|
|
[_cam setEye: AddCoord([_cam center], newDir)]; |
|
|
[_cam move: newCenter]; |
|
256 |
} |
} |
257 |
|
|
258 |
|
// - (void) afficheOff |
259 |
|
// { |
260 |
|
// _affiche = NO; |
261 |
|
// } |
262 |
|
|
263 |
- (void) rotatePitch2: (double)pitch |
// - (void) afficheOn |
264 |
{ |
// { |
265 |
|
// _affiche = YES; |
266 |
coord_t newDir, newUp; |
// _initModel = NO; |
267 |
coord_t newCenter; |
// } |
|
|
|
|
newCenter = [_cam rotateByAngle: pitch |
|
|
vector: NormalizeVector ([_cam ortho]) |
|
|
point: [_cam center]]; |
|
|
|
|
|
[_cam move: MultCoord([_cam center],-1.0)]; |
|
|
|
|
|
|
|
|
newDir = [_cam rotateByAngle: pitch |
|
|
vector: NormalizeVector([_cam ortho]) |
|
|
point: [_cam dir]]; |
|
|
|
|
|
[_cam setEye: AddCoord([_cam center], newDir)]; |
|
|
|
|
|
newUp = [_cam rotateByAngle: pitch |
|
|
vector: [_cam ortho] |
|
|
point: [_cam up]]; |
|
|
|
|
|
[_cam setUp: newUp]; |
|
|
[_cam move: newCenter]; |
|
|
} |
|
|
|
|
|
- (void) rotateAll: (double)heading |
|
|
withPitch: (double)pitch |
|
|
{ |
|
|
coord_t newDir, newUp; |
|
|
coord_t newCenter; |
|
|
|
|
|
newCenter = [_cam rotateByAngle: heading |
|
|
vector: NormalizeVector ([_cam up]) |
|
|
point: [_cam center]]; |
|
|
|
|
|
newCenter = AddCoord(newCenter,[_cam rotateByAngle: pitch |
|
|
vector: NormalizeVector ([_cam ortho]) |
|
|
point: [_cam center]]); |
|
|
|
|
|
[_cam move: MultCoord([_cam center],-1.0)]; |
|
|
|
|
|
newDir = [_cam rotateByAngle: heading |
|
|
vector: NormalizeVector ([_cam up]) |
|
|
point: [_cam eye]]; |
|
|
|
|
|
newDir = AddCoord(newDir,[_cam rotateByAngle: pitch |
|
|
vector: [_cam ortho] |
|
|
point: [_cam eye]]); |
|
|
|
|
|
// newUp = [_cam rotateByAngle: heading |
|
|
// vector: [_cam dir] |
|
|
// point: [_cam up]]; |
|
|
|
|
|
newUp = AddCoord(newUp,[_cam rotateByAngle: pitch |
|
|
vector: [_cam ortho] |
|
|
point: [_cam up]]); |
|
|
|
|
|
[_cam setEye: AddCoord([_cam center], newDir)]; |
|
|
[_cam setUp: newUp]; |
|
|
[_cam move: newCenter]; |
|
|
} |
|
|
|
|
|
|
|
|
- (void) afficheOff |
|
|
{ |
|
|
_affiche = NO; |
|
|
} |
|
|
|
|
|
- (void) afficheOn |
|
|
{ |
|
|
_affiche = YES; |
|
|
_initModel = NO; |
|
|
|
|
|
} |
|
268 |
|
|
269 |
- (NSMutableArray*) animeNames |
- (NSMutableArray*) animeNames |
270 |
{ |
{ |
283 |
_mode = mode; |
_mode = mode; |
284 |
} |
} |
285 |
|
|
286 |
|
- (Camera*) cam |
287 |
|
{ |
288 |
|
return _cam; |
289 |
|
} |
290 |
|
|
291 |
|
- (void) setCam: (Camera*)cam |
292 |
|
{ |
293 |
|
// printf("merde\n"); |
294 |
|
// [_cam setEye: [cam eye]]; |
295 |
|
// _cam = cam; |
296 |
|
// printf("eye _x = %g\n", [_cam eye].x); |
297 |
|
// printf("eye sans _x = %g\n", [cam eye].x); |
298 |
|
// RELEASE(_cam); |
299 |
|
// _cam = [_cam initWithFovy: [cam fovy] |
300 |
|
// aspect: [cam aspect] |
301 |
|
// zNear: [cam zNear] |
302 |
|
// zFar: [cam zFar] |
303 |
|
// eye: [cam eye] |
304 |
|
// center: [cam center] |
305 |
|
// up: [cam up]]; |
306 |
|
|
307 |
|
gluLookAt((GLdouble)[_cam eye].x, |
308 |
|
(GLdouble)[_cam eye].y, |
309 |
|
(GLdouble)[_cam eye].z,// +distance, |
310 |
|
(GLdouble)[_cam center].x, |
311 |
|
(GLdouble)[_cam center].y, |
312 |
|
(GLdouble)[_cam center].z, |
313 |
|
(GLdouble)[_cam up].x, |
314 |
|
(GLdouble)[_cam up].y, |
315 |
|
(GLdouble)[_cam up].z); |
316 |
|
|
317 |
|
printf("eye x = %g\n", [cam eye].x); |
318 |
|
printf("eye y = %g\n", [cam eye].y); |
319 |
|
printf("eye z = %g\n", [cam eye].z); |
320 |
|
} |
321 |
@end |
@end |