Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOOpenGLMatrixManager Class Reference

#include <OOOpenGLMatrixManager.h>

+ Inheritance diagram for OOOpenGLMatrixManager:
+ Collaboration diagram for OOOpenGLMatrixManager:

Instance Methods

(id) - init
 
(void) - dealloc
 
(void) - loadModelView:
 
(void) - resetModelView
 
(void) - multModelView:
 
(void) - translateModelView:
 
(void) - rotateModelView:axis:
 
(void) - scaleModelView:
 
(void) - lookAtWithEye:center:up:
 
(void) - pushModelView
 
(OOMatrix) - popModelView
 
(OOMatrix) - getModelView
 
(NSUInteger) - countModelView
 
(void) - syncModelView
 
(void) - loadProjection:
 
(void) - multProjection:
 
(void) - translateProjection:
 
(void) - rotateProjection:axis:
 
(void) - scaleProjection:
 
(void) - frustumLeft:right:bottom:top:near:far:
 
(void) - orthoLeft:right:bottom:top:near:far:
 
(void) - perspectiveFovy:aspect:zNear:zFar:
 
(void) - resetProjection
 
(void) - pushProjection
 
(OOMatrix) - popProjection
 
(OOMatrix) - getProjection
 
(void) - syncProjection
 
(OOMatrix) - getMatrix:
 
(NSArray *) - standardMatrixUniformLocations:
 
(void) - updateModelView [implementation]
 
(void) - updateProjection [implementation]
 

Private Attributes

OOMatrix matrices [OOLITE_GL_MATRIX_END]
 
BOOL valid [OOLITE_GL_MATRIX_END]
 
OOOpenGLMatrixStackmodelViewStack
 
OOOpenGLMatrixStackprojectionStack
 

Detailed Description

Definition at line 63 of file OOOpenGLMatrixManager.h.

Method Documentation

◆ countModelView

- (NSUInteger) countModelView

Definition at line 605 of file OOOpenGLMatrixManager.m.

237{
238 return [modelViewStack stackCount];
239}

References getMatrix:.

+ Here is the call graph for this function:

◆ dealloc

- (void) dealloc

Definition at line 605 of file OOOpenGLMatrixManager.m.

158{
159 [modelViewStack release];
160 [projectionStack release];
161 [super dealloc];
162}

◆ frustumLeft:right:bottom:top:near:far:

- (void) frustumLeft: (double) l
right: (double) r
bottom: (double) b
top: (double) t
near: (double) n
far: (double) f 

Definition at line 605 of file OOOpenGLMatrixManager.m.

281 : (double) l right: (double) r bottom: (double) b top: (double) t near: (double) n far: (double) f
282{
283 if (l == r || t == b || n == f || n <= 0 || f <= 0) return;
284 [self multProjection: OOMatrixConstruct
285 (
286 2*n/(r-l), 0.0, 0.0, 0.0,
287 0.0, 2*n/(t-b), 0.0, 0.0,
288 (r+l)/(r-l), (t+b)/(t-b), -(f+n)/(f-n), -1.0,
289 0.0, 0.0, -2*f*n/(f-n), 0.0
290 )];
291}

Referenced by OOGLFrustum().

+ Here is the caller graph for this function:

◆ getMatrix:

- (OOMatrix) getMatrix: (int) which

Definition at line 605 of file OOOpenGLMatrixManager.m.

349 : (int) which
350{
351 if (which < 0 || which >= OOLITE_GL_MATRIX_END) return kIdentityMatrix;
352 if (valid[which]) return matrices[which];
353 OOScalar d;
354 switch(which)
355 {
358 break;
360 matrices[which] = matrices[OOLITE_GL_MATRIX_MODELVIEW];
361 matrices[which].m[3][0] = 0.0;
362 matrices[which].m[3][1] = 0.0;
363 matrices[which].m[3][2] = 0.0;
364 matrices[which].m[0][3] = 0.0;
365 matrices[which].m[1][3] = 0.0;
366 matrices[which].m[2][3] = 0.0;
367 matrices[which].m[3][3] = 1.0;
368 matrices[which] = OOMatrixTranspose(OOMatrixInverseWithDeterminant(matrices[which], &d));
369 if (d != 0.0)
370 {
371 d = powf(fabsf(d), 1.0/3);
372 for (int i = 0; i < 3; i++)
373 {
374 for (int j = 0; j < 3; j++)
375 {
376 matrices[which].m[i][j] /= d;
377 }
378 }
379 }
380 break;
383 break;
386 break;
389 break;
391 matrices[which] = OOMatrixTranspose(matrices[OOLITE_GL_MATRIX_MODELVIEW]);
392 break;
394 matrices[which] = OOMatrixTranspose(matrices[OOLITE_GL_MATRIX_PROJECTION]);
395 break;
397 matrices[which] = OOMatrixTranspose([self getMatrix: OOLITE_GL_MATRIX_MODELVIEW_PROJECTION]);
398 break;
400 matrices[which] = OOMatrixTranspose([self getMatrix: OOLITE_GL_MATRIX_MODELVIEW_INVERSE]);
401 break;
403 matrices[which] = OOMatrixTranspose([self getMatrix: OOLITE_GL_MATRIX_PROJECTION_INVERSE]);
404 break;
406 matrices[which] = OOMatrixTranspose([self getMatrix: OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE]);
407 break;
408 }
409 valid[which] = YES;
410 return matrices[which];
411}
GLfloat OOScalar
Definition OOMaths.h:64
OOMatrix OOMatrixMultiply(OOMatrix a, OOMatrix b)
Definition OOMatrix.m:111
OOMatrix OOMatrixInverseWithDeterminant(OOMatrix M, OOScalar *d)
Definition OOMatrix.m:398
const OOMatrix kIdentityMatrix
Definition OOMatrix.m:31
OOMatrix OOMatrixInverse(OOMatrix M)
Definition OOMatrix.m:393
@ OOLITE_GL_MATRIX_MODELVIEW
@ OOLITE_GL_MATRIX_MODELVIEW_PROJECTION
@ OOLITE_GL_MATRIX_MODELVIEW_INVERSE
@ OOLITE_GL_MATRIX_MODELVIEW_INVERSE_TRANSPOSE
@ OOLITE_GL_MATRIX_PROJECTION
@ OOLITE_GL_MATRIX_PROJECTION_TRANSPOSE
@ OOLITE_GL_MATRIX_PROJECTION_INVERSE
@ OOLITE_GL_MATRIX_PROJECTION_INVERSE_TRANSPOSE
@ OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE_TRANSPOSE
@ OOLITE_GL_MATRIX_NORMAL
@ OOLITE_GL_MATRIX_END
@ OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_TRANSPOSE
@ OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE
@ OOLITE_GL_MATRIX_MODELVIEW_TRANSPOSE
OOMatrix matrices[OOLITE_GL_MATRIX_END]
BOOL valid[OOLITE_GL_MATRIX_END]
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

Referenced by countModelView.

+ Here is the caller graph for this function:

◆ getModelView

- (OOMatrix) getModelView

Definition at line 605 of file OOOpenGLMatrixManager.m.

232{
233 return matrices[OOLITE_GL_MATRIX_MODELVIEW];
234}

Referenced by OOGLGetModelView().

+ Here is the caller graph for this function:

◆ getProjection

- (OOMatrix) getProjection

Definition at line 605 of file OOOpenGLMatrixManager.m.

337{
338 return matrices[OOLITE_GL_MATRIX_PROJECTION];
339}

Referenced by OOGLGetProjection().

+ Here is the caller graph for this function:

◆ init

- (id) init

Definition at line 605 of file OOOpenGLMatrixManager.m.

132{
133 if ((self = [super init]))
134 {
135 int i;
136 for (i = 0; i < OOLITE_GL_MATRIX_END; i++)
137 {
138 switch(i)
139 {
143 valid[i] = YES;
144 break;
145
146 default:
147 valid[i] = NO;
148 break;
149 }
150 }
151 modelViewStack = [[OOOpenGLMatrixStack alloc] init];
152 projectionStack = [[OOOpenGLMatrixStack alloc] init];
153 }
154 return self;
155}
OOOpenGLMatrixStack * projectionStack
OOOpenGLMatrixStack * modelViewStack

◆ loadModelView:

- (void) loadModelView: (OOMatrix) matrix

Definition at line 605 of file OOOpenGLMatrixManager.m.

164 : (OOMatrix) matrix
165{
166 matrices[OOLITE_GL_MATRIX_MODELVIEW] = matrix;
167 [self updateModelView];
168 return;
169}

Referenced by OOGLLoadModelView().

+ Here is the caller graph for this function:

◆ loadProjection:

- (void) loadProjection: (OOMatrix) matrix

Definition at line 605 of file OOOpenGLMatrixManager.m.

249 : (OOMatrix) matrix
250{
251 matrices[OOLITE_GL_MATRIX_PROJECTION] = matrix;
252 [self updateProjection];
253 return;
254}

Referenced by OOGLLoadProjection().

+ Here is the caller graph for this function:

◆ lookAtWithEye:center:up:

- (void) lookAtWithEye: (Vector) eye
center: (Vector) center
up: (Vector) up 

Definition at line 605 of file OOOpenGLMatrixManager.m.

202 : (Vector) eye center: (Vector) center up: (Vector) up
203{
204 Vector k = vector_normal(vector_subtract(eye, center));
205 Vector i = cross_product(up, k);
206 Vector j = cross_product(k, i);
207 OOMatrix m1 = OOMatrixConstruct
208 (
209 i.x, j.x, k.x, 0.0,
210 i.y, j.y, k.y, 0.0,
211 i.z, j.z, k.z, 0.0,
212 -eye.x, -eye.y, -eye.z, 1.0
213 );
214 [self multModelView: m1];
215 return;
216}

Referenced by OOGLLookAt().

+ Here is the caller graph for this function:

◆ multModelView:

- (void) multModelView: (OOMatrix) matrix

Definition at line 605 of file OOOpenGLMatrixManager.m.

177 : (OOMatrix) matrix
178{
179 matrices[OOLITE_GL_MATRIX_MODELVIEW] = OOMatrixMultiply(matrix, matrices[OOLITE_GL_MATRIX_MODELVIEW]);
180 [self updateModelView];
181}

Referenced by OOGLMultModelView().

+ Here is the caller graph for this function:

◆ multProjection:

- (void) multProjection: (OOMatrix) matrix

Definition at line 605 of file OOOpenGLMatrixManager.m.

256 : (OOMatrix) matrix
257{
258 matrices[OOLITE_GL_MATRIX_PROJECTION] = OOMatrixMultiply(matrix, matrices[OOLITE_GL_MATRIX_PROJECTION]);
259 [self updateProjection];
260}

Referenced by OOGLMultProjection().

+ Here is the caller graph for this function:

◆ orthoLeft:right:bottom:top:near:far:

- (void) orthoLeft: (double) l
right: (double) r
bottom: (double) b
top: (double) t
near: (double) n
far: (double) f 

Definition at line 605 of file OOOpenGLMatrixManager.m.

293 : (double) l right: (double) r bottom: (double) b top: (double) t near: (double) n far: (double) f
294{
295 if (l == r || t == b || n == f) return;
296 [self multProjection: OOMatrixConstruct
297 (
298 2/(r-l), 0.0, 0.0, 0.0,
299 0.0, 2/(t-b), 0.0, 0.0,
300 0.0, 0.0, 2/(n-f), 0.0,
301 (l+r)/(l-r), (b+t)/(b-t), (n+f)/(n-f), 1.0
302 )];
303}

Referenced by OOGLOrtho().

+ Here is the caller graph for this function:

◆ perspectiveFovy:aspect:zNear:zFar:

- (void) perspectiveFovy: (double) fovy
aspect: (double) aspect
zNear: (double) zNear
zFar: (double) zFar 

Definition at line 605 of file OOOpenGLMatrixManager.m.

305 : (double) fovy aspect: (double) aspect zNear: (double) zNear zFar: (double) zFar
306{
307 if (aspect == 0.0 || zNear == zFar) return;
308 double f = 1.0/tan(M_PI * fovy / 360);
309 [self multProjection: OOMatrixConstruct
310 (
311 f/aspect, 0.0, 0.0, 0.0,
312 0.0, f, 0.0, 0.0,
313 0.0, 0.0, (zFar + zNear)/(zNear - zFar), -1.0,
314 0.0, 0.0, 2*zFar*zNear/(zNear - zFar), 0.0
315 )];
316}
#define M_PI
Definition OOMaths.h:73

Referenced by OOGLPerspective().

+ Here is the caller graph for this function:

◆ popModelView

- (OOMatrix) popModelView

Definition at line 605 of file OOOpenGLMatrixManager.m.

225{
226 matrices[OOLITE_GL_MATRIX_MODELVIEW] = [modelViewStack pop];
227 [self updateModelView];
228 return matrices[OOLITE_GL_MATRIX_MODELVIEW];
229}

Referenced by OOGLPopModelView().

+ Here is the caller graph for this function:

◆ popProjection

- (OOMatrix) popProjection

Definition at line 605 of file OOOpenGLMatrixManager.m.

330{
331 matrices[OOLITE_GL_MATRIX_PROJECTION] = [projectionStack pop];
332 [self updateProjection];
333 return matrices[OOLITE_GL_MATRIX_PROJECTION];
334}

Referenced by OOGLPopProjection().

+ Here is the caller graph for this function:

◆ pushModelView

- (void) pushModelView

Definition at line 605 of file OOOpenGLMatrixManager.m.

220{
221 [modelViewStack push: matrices[OOLITE_GL_MATRIX_MODELVIEW]];
222}

Referenced by OOGLPushModelView().

+ Here is the caller graph for this function:

◆ pushProjection

- (void) pushProjection

Definition at line 605 of file OOOpenGLMatrixManager.m.

325{
326 [projectionStack push: matrices[OOLITE_GL_MATRIX_PROJECTION]];
327}

Referenced by OOGLPushProjection().

+ Here is the caller graph for this function:

◆ resetModelView

- (void) resetModelView

Definition at line 605 of file OOOpenGLMatrixManager.m.

172{
173 matrices[OOLITE_GL_MATRIX_MODELVIEW] = kIdentityMatrix;
174 [self updateModelView];
175}

Referenced by OOGLResetModelView().

+ Here is the caller graph for this function:

◆ resetProjection

- (void) resetProjection

Definition at line 605 of file OOOpenGLMatrixManager.m.

319{
320 matrices[OOLITE_GL_MATRIX_PROJECTION] = kIdentityMatrix;
321 [self updateProjection];
322}

Referenced by OOGLResetProjection().

+ Here is the caller graph for this function:

◆ rotateModelView:axis:

- (void) rotateModelView: (GLfloat) angle
axis: (Vector) axis 

Definition at line 605 of file OOOpenGLMatrixManager.m.

192 : (GLfloat) angle axis: (Vector) axis
193{
194 [self multModelView: OOMatrixForRotation(axis, angle)];
195}

Referenced by OOGLRotateModelView().

+ Here is the caller graph for this function:

◆ rotateProjection:axis:

- (void) rotateProjection: (GLfloat) angle
axis: (Vector) axis 

Definition at line 605 of file OOOpenGLMatrixManager.m.

271 : (GLfloat) angle axis: (Vector) axis
272{
273 [self multProjection: OOMatrixForRotation(axis, angle)];
274}

Referenced by OOGLRotateProjection().

+ Here is the caller graph for this function:

◆ scaleModelView:

- (void) scaleModelView: (Vector) scale

Definition at line 605 of file OOOpenGLMatrixManager.m.

197 : (Vector) scale
198{
199 [self multModelView: OOMatrixForScale(scale.x, scale.y, scale.z)];
200}

Referenced by OOGLScaleModelView().

+ Here is the caller graph for this function:

◆ scaleProjection:

- (void) scaleProjection: (Vector) scale

Definition at line 605 of file OOOpenGLMatrixManager.m.

276 : (Vector) scale
277{
278 [self multProjection: OOMatrixForScale(scale.x, scale.y, scale.z)];
279}

Referenced by OOGLScaleProjection().

+ Here is the caller graph for this function:

◆ standardMatrixUniformLocations:

- (NSArray *) standardMatrixUniformLocations: (GLhandleARB) program

Definition at line 605 of file OOOpenGLMatrixManager.m.

413 : (GLhandleARB) program
414{
415 GLint location;
416 NSUInteger i;
417 NSMutableArray *locationSet = [[[NSMutableArray alloc] init] autorelease];
418
420
421 for (i = 0; i < OOLITE_GL_MATRIX_END; i++) {
422 location = glGetUniformLocationARB(program, ooliteStandardMatrixUniforms[i]);
423 if (location >= 0) {
425 {
426 [locationSet addObject:
427 [NSArray arrayWithObjects:
428 [NSNumber numberWithInt: location],
429 [NSNumber numberWithInteger: i],
430 @"mat3",
431 nil]];
432 }
433 else
434 {
435 [locationSet addObject:
436 [NSArray arrayWithObjects:
437 [NSNumber numberWithInt: location],
438 [NSNumber numberWithInteger: i],
439 @"mat4",
440 nil]];
441 }
442 }
443 }
444 return [[NSArray arrayWithArray: locationSet] retain];
445}
#define OO_ENTER_OPENGL()
const char * ooliteStandardMatrixUniforms[]

◆ syncModelView

- (void) syncModelView

Definition at line 605 of file OOOpenGLMatrixManager.m.

242{
244 OOGL(glMatrixMode(GL_MODELVIEW));
245 GLLoadOOMatrix([self getModelView]);
246 return;
247}
#define OOGL(statement)
Definition OOOpenGL.h:251

Referenced by OOGLLoadModelView(), OOGLLookAt(), OOGLMultModelView(), OOGLPopModelView(), OOGLPushModelView(), OOGLResetModelView(), OOGLRotateModelView(), OOGLScaleModelView(), and OOGLTranslateModelView().

+ Here is the caller graph for this function:

◆ syncProjection

- (void) syncProjection

Definition at line 605 of file OOOpenGLMatrixManager.m.

342{
344 OOGL(glMatrixMode(GL_PROJECTION));
345 GLLoadOOMatrix([self getProjection]);
346 return;
347}

Referenced by OOGLFrustum(), OOGLLoadProjection(), OOGLMultProjection(), OOGLOrtho(), OOGLPerspective(), OOGLPopProjection(), OOGLPushProjection(), OOGLResetProjection(), OOGLRotateProjection(), OOGLScaleProjection(), and OOGLTranslateProjection().

+ Here is the caller graph for this function:

◆ translateModelView:

- (void) translateModelView: (Vector) vector

Definition at line 605 of file OOOpenGLMatrixManager.m.

183 : (Vector) vector
184{
185 OOMatrix matrix = kIdentityMatrix;
186 matrix.m[3][0] = vector.x;
187 matrix.m[3][1] = vector.y;
188 matrix.m[3][2] = vector.z;
189 [self multModelView: matrix];
190}

Referenced by OOGLTranslateModelView().

+ Here is the caller graph for this function:

◆ translateProjection:

- (void) translateProjection: (Vector) vector

Definition at line 605 of file OOOpenGLMatrixManager.m.

262 : (Vector) vector
263{
264 OOMatrix matrix = kIdentityMatrix;
265 matrix.m[0][3] = vector.x;
266 matrix.m[1][3] = vector.y;
267 matrix.m[2][3] = vector.z;
268 [self multProjection: matrix];
269}

Referenced by OOGLTranslateProjection().

+ Here is the caller graph for this function:

◆ updateModelView

- (void) updateModelView
implementation

Provided by category OOOpenGLMatrixManager(Private).

Definition at line 605 of file OOOpenGLMatrixManager.m.

102{
103 valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION] = NO;
104 valid[OOLITE_GL_MATRIX_NORMAL] = NO;
105 valid[OOLITE_GL_MATRIX_MODELVIEW_INVERSE] = NO;
106 valid[OOLITE_GL_MATRIX_PROJECTION_INVERSE] = NO;
107 valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE] = NO;
108 valid[OOLITE_GL_MATRIX_MODELVIEW_TRANSPOSE] = NO;
109 valid[OOLITE_GL_MATRIX_PROJECTION_TRANSPOSE] = NO;
110 valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_TRANSPOSE] = NO;
111 valid[OOLITE_GL_MATRIX_MODELVIEW_INVERSE_TRANSPOSE] = NO;
112 valid[OOLITE_GL_MATRIX_PROJECTION_INVERSE_TRANSPOSE] = NO;
113 valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE_TRANSPOSE] = NO;
114}

◆ updateProjection

- (void) updateProjection
implementation

Provided by category OOOpenGLMatrixManager(Private).

Definition at line 605 of file OOOpenGLMatrixManager.m.

117{
118 valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION] = NO;
119 valid[OOLITE_GL_MATRIX_PROJECTION_INVERSE] = NO;
120 valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE] = NO;
121 valid[OOLITE_GL_MATRIX_PROJECTION_TRANSPOSE] = NO;
122 valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_TRANSPOSE] = NO;
123 valid[OOLITE_GL_MATRIX_PROJECTION_INVERSE_TRANSPOSE] = NO;
124 valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE_TRANSPOSE] = NO;
125}

Member Data Documentation

◆ matrices

- (OOMatrix matrices[OOLITE_GL_MATRIX_END])
private

Definition at line 66 of file OOOpenGLMatrixManager.h.

◆ modelViewStack

- (OOOpenGLMatrixStack*) modelViewStack
private

Definition at line 68 of file OOOpenGLMatrixManager.h.

◆ projectionStack

- (OOOpenGLMatrixStack*) projectionStack
private

Definition at line 69 of file OOOpenGLMatrixManager.h.

◆ valid

- (BOOL valid[OOLITE_GL_MATRIX_END])
private

Definition at line 67 of file OOOpenGLMatrixManager.h.


The documentation for this class was generated from the following files: