Line data Source code
1 0 : /* 2 : 3 : OOOpenGLMatrixManager.h 4 : 5 : Manages OpenGL Model, View, etc. matrices. 6 : 7 : Oolite 8 : Copyright (C) 2004-2014 Giles C Williams and contributors 9 : 10 : This program is free software; you can redistribute it and/or 11 : modify it under the terms of the GNU General Public License 12 : as published by the Free Software Foundation; either version 2 13 : of the License, or (at your option) any later version. 14 : 15 : This program is distributed in the hope that it will be useful, 16 : but WITHOUT ANY WARRANTY; without even the implied warranty of 17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 : GNU General Public License for more details. 19 : 20 : You should have received a copy of the GNU General Public License 21 : along with this program; if not, write to the Free Software 22 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 : MA 02110-1301, USA. 24 : 25 : */ 26 : 27 : #import "OOMaths.h" 28 : 29 0 : extern const char* ooliteStandardMatrixUniforms[]; 30 : 31 0 : enum 32 : { 33 : OOLITE_GL_MATRIX_MODELVIEW, 34 : OOLITE_GL_MATRIX_PROJECTION, 35 : OOLITE_GL_MATRIX_MODELVIEW_PROJECTION, 36 : OOLITE_GL_MATRIX_NORMAL, 37 : OOLITE_GL_MATRIX_MODELVIEW_INVERSE, 38 : OOLITE_GL_MATRIX_PROJECTION_INVERSE, 39 : OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE, 40 : OOLITE_GL_MATRIX_MODELVIEW_TRANSPOSE, 41 : OOLITE_GL_MATRIX_PROJECTION_TRANSPOSE, 42 : OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_TRANSPOSE, 43 : OOLITE_GL_MATRIX_MODELVIEW_INVERSE_TRANSPOSE, 44 : OOLITE_GL_MATRIX_PROJECTION_INVERSE_TRANSPOSE, 45 : OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE_TRANSPOSE, 46 : OOLITE_GL_MATRIX_END 47 : }; 48 : 49 0 : @interface OOOpenGLMatrixStack: NSObject 50 : { 51 : @private 52 0 : NSMutableArray *stack; 53 : } 54 : 55 0 : - (id) init; 56 0 : - (void) dealloc; 57 0 : - (void) push: (OOMatrix) matrix; 58 0 : - (OOMatrix) pop; 59 0 : - (NSUInteger) stackCount; 60 : 61 : @end 62 : 63 0 : @interface OOOpenGLMatrixManager: NSObject 64 : { 65 : @private 66 0 : OOMatrix matrices[OOLITE_GL_MATRIX_END]; 67 0 : BOOL valid[OOLITE_GL_MATRIX_END]; 68 0 : OOOpenGLMatrixStack *modelViewStack; 69 0 : OOOpenGLMatrixStack *projectionStack; 70 : } 71 : 72 0 : - (id) init; 73 0 : - (void) dealloc; 74 0 : - (void) loadModelView: (OOMatrix) matrix; 75 0 : - (void) resetModelView; 76 0 : - (void) multModelView: (OOMatrix) matrix; 77 0 : - (void) translateModelView: (Vector) vector; 78 0 : - (void) rotateModelView: (GLfloat) angle axis: (Vector) axis; 79 0 : - (void) scaleModelView: (Vector) scale; 80 0 : - (void) lookAtWithEye: (Vector) eye center: (Vector) center up: (Vector) up; 81 0 : - (void) pushModelView; 82 0 : - (OOMatrix) popModelView; 83 0 : - (OOMatrix) getModelView; 84 0 : - (NSUInteger) countModelView; 85 0 : - (void) syncModelView; 86 0 : - (void) loadProjection: (OOMatrix) matrix; 87 0 : - (void) multProjection: (OOMatrix) matrix; 88 0 : - (void) translateProjection: (Vector) vector; 89 0 : - (void) rotateProjection: (GLfloat) angle axis: (Vector) axis; 90 0 : - (void) scaleProjection: (Vector) scale; 91 0 : - (void) frustumLeft: (double) l right: (double) r bottom: (double) b top: (double) t near: (double) n far: (double) f; 92 0 : - (void) orthoLeft: (double) l right: (double) r bottom: (double) b top: (double) t near: (double) n far: (double) f; 93 0 : - (void) perspectiveFovy: (double) fovy aspect: (double) aspect zNear: (double) zNear zFar: (double) zFar; 94 0 : - (void) resetProjection; 95 0 : - (void) pushProjection; 96 0 : - (OOMatrix) popProjection; 97 0 : - (OOMatrix) getProjection; 98 0 : - (void) syncProjection; 99 0 : - (OOMatrix) getMatrix: (int) which; 100 0 : - (NSArray*) standardMatrixUniformLocations: (GLhandleARB) program; 101 : 102 : @end 103 : 104 0 : void OOGLPushModelView(void); 105 0 : OOMatrix OOGLPopModelView(void); 106 0 : OOMatrix OOGLGetModelView(void); 107 0 : void OOGLResetModelView(void); 108 0 : void OOGLLoadModelView(OOMatrix matrix); 109 0 : void OOGLMultModelView(OOMatrix matrix); 110 0 : void OOGLTranslateModelView(Vector vector); 111 0 : void OOGLRotateModelView(GLfloat angle, Vector axis); 112 0 : void OOGLScaleModelView(Vector scale); 113 0 : void OOGLLookAt(Vector eye, Vector center, Vector up); 114 : 115 0 : void OOGLResetProjection(void); 116 0 : void OOGLPushProjection(void); 117 0 : OOMatrix OOGLPopProjection(void); 118 0 : OOMatrix OOGLGetProjection(void); 119 0 : void OOGLLoadProjection(OOMatrix matrix); 120 0 : void OOGLMultProjection(OOMatrix matrix); 121 0 : void OOGLTranslateProjection(Vector vector); 122 0 : void OOGLRotateProjection(GLfloat angle, Vector axis); 123 0 : void OOGLScaleProjection(Vector scale); 124 0 : void OOGLFrustum(double left, double right, double bottom, double top, double near, double far); 125 0 : void OOGLOrtho(double left, double right, double bottom, double top, double near, double far); 126 0 : void OOGLPerspective(double fovy, double aspect, double zNear, double zFar); 127 : 128 0 : OOMatrix OOGLGetModelViewProjection(void); 129 :