1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.apis.graphics.spritetext; 18 19 import javax.microedition.khronos.opengles.GL10; 20 21 class MatrixGrabber { MatrixGrabber()22 public MatrixGrabber() { 23 mModelView = new float[16]; 24 mProjection = new float[16]; 25 } 26 27 /** 28 * Record the current modelView and projection matrix state. 29 * Has the side effect of setting the current matrix state to GL_MODELVIEW 30 * @param gl 31 */ getCurrentState(GL10 gl)32 public void getCurrentState(GL10 gl) { 33 getCurrentProjection(gl); 34 getCurrentModelView(gl); 35 } 36 37 /** 38 * Record the current modelView matrix state. Has the side effect of 39 * setting the current matrix state to GL_MODELVIEW 40 * @param gl 41 */ getCurrentModelView(GL10 gl)42 public void getCurrentModelView(GL10 gl) { 43 getMatrix(gl, GL10.GL_MODELVIEW, mModelView); 44 } 45 46 /** 47 * Record the current projection matrix state. Has the side effect of 48 * setting the current matrix state to GL_PROJECTION 49 * @param gl 50 */ getCurrentProjection(GL10 gl)51 public void getCurrentProjection(GL10 gl) { 52 getMatrix(gl, GL10.GL_PROJECTION, mProjection); 53 } 54 getMatrix(GL10 gl, int mode, float[] mat)55 private void getMatrix(GL10 gl, int mode, float[] mat) { 56 MatrixTrackingGL gl2 = (MatrixTrackingGL) gl; 57 gl2.glMatrixMode(mode); 58 gl2.getMatrix(mat, 0); 59 } 60 61 public float[] mModelView; 62 public float[] mProjection; 63 } 64