FileDocCategorySizeDatePackage
MatrixStack.javaAPI DocAndroid 1.5 API5538Wed May 06 22:41:08 BST 2009com.example.android.apis.graphics.spritetext

MatrixStack

public class MatrixStack extends Object
A matrix stack, similar to OpenGL ES's internal matrix stack.

Fields Summary
private static final int
DEFAULT_MAX_DEPTH
private static final int
MATRIX_SIZE
private float[]
mMatrix
private int
mTop
private float[]
mTemp
Constructors Summary
public MatrixStack()

        commonInit(DEFAULT_MAX_DEPTH);
    
public MatrixStack(int maxDepth)

        commonInit(maxDepth);
    
Methods Summary
private voidadjust(int dir)

        mTop += dir * MATRIX_SIZE;
    
private voidcommonInit(int maxDepth)

        mMatrix = new float[maxDepth * MATRIX_SIZE];
        mTemp = new float[MATRIX_SIZE * 2];
        glLoadIdentity();
    
private floatfixedToFloat(int x)

        return x * (1.0f / 65536.0f);
    
public voidgetMatrix(float[] dest, int offset)

        System.arraycopy(mMatrix, mTop, dest, offset, MATRIX_SIZE);
    
public voidglFrustumf(float left, float right, float bottom, float top, float near, float far)

        Matrix.frustumM(mMatrix, mTop, left, right, bottom, top, near, far);
    
public voidglFrustumx(int left, int right, int bottom, int top, int near, int far)

        glFrustumf(fixedToFloat(left),fixedToFloat(right),
                fixedToFloat(bottom), fixedToFloat(top),
                fixedToFloat(near), fixedToFloat(far));
    
public voidglLoadIdentity()

        Matrix.setIdentityM(mMatrix, mTop);
    
public voidglLoadMatrixf(float[] m, int offset)

        System.arraycopy(m, offset, mMatrix, mTop, MATRIX_SIZE);
    
public voidglLoadMatrixf(java.nio.FloatBuffer m)

        m.get(mMatrix, mTop, MATRIX_SIZE);
    
public voidglLoadMatrixx(java.nio.IntBuffer m)

        for(int i = 0; i < MATRIX_SIZE; i++) {
            mMatrix[mTop + i] = fixedToFloat(m.get());
        }
    
public voidglLoadMatrixx(int[] m, int offset)

        for(int i = 0; i < MATRIX_SIZE; i++) {
            mMatrix[mTop + i] = fixedToFloat(m[offset + i]);
        }
    
public voidglMultMatrixf(float[] m, int offset)

        System.arraycopy(mMatrix, mTop, mTemp, 0, MATRIX_SIZE);
        Matrix.multiplyMM(mMatrix, mTop, mTemp, 0, m, offset);
    
public voidglMultMatrixf(java.nio.FloatBuffer m)

        m.get(mTemp, MATRIX_SIZE, MATRIX_SIZE);
        glMultMatrixf(mTemp, MATRIX_SIZE);
    
public voidglMultMatrixx(int[] m, int offset)

        for(int i = 0; i < MATRIX_SIZE; i++) {
            mTemp[MATRIX_SIZE + i] = fixedToFloat(m[offset + i]);
        }
        glMultMatrixf(mTemp, MATRIX_SIZE);
    
public voidglMultMatrixx(java.nio.IntBuffer m)

        for(int i = 0; i < MATRIX_SIZE; i++) {
            mTemp[MATRIX_SIZE + i] = fixedToFloat(m.get());
        }
        glMultMatrixf(mTemp, MATRIX_SIZE);
    
public voidglOrthof(float left, float right, float bottom, float top, float near, float far)

        Matrix.orthoM(mMatrix, mTop, left, right, bottom, top, near, far);
    
public voidglOrthox(int left, int right, int bottom, int top, int near, int far)

        glOrthof(fixedToFloat(left), fixedToFloat(right),
                fixedToFloat(bottom), fixedToFloat(top),
                fixedToFloat(near), fixedToFloat(far));
    
public voidglPopMatrix()

        preflight_adjust(-1);
        adjust(-1);
    
public voidglPushMatrix()

        preflight_adjust(1);
        System.arraycopy(mMatrix, mTop, mMatrix, mTop + MATRIX_SIZE,
                MATRIX_SIZE);
        adjust(1);
    
public voidglRotatef(float angle, float x, float y, float z)

        Matrix.setRotateM(mTemp, 0, angle, x, y, z);
        System.arraycopy(mMatrix, mTop, mTemp, MATRIX_SIZE, MATRIX_SIZE);
        Matrix.multiplyMM(mMatrix, mTop, mTemp, MATRIX_SIZE, mTemp, 0);
    
public voidglRotatex(int angle, int x, int y, int z)

        glRotatef(angle, fixedToFloat(x), fixedToFloat(y), fixedToFloat(z));
    
public voidglScalef(float x, float y, float z)

        Matrix.scaleM(mMatrix, mTop, x, y, z);
    
public voidglScalex(int x, int y, int z)

        glScalef(fixedToFloat(x), fixedToFloat(y), fixedToFloat(z));
    
public voidglTranslatef(float x, float y, float z)

        Matrix.translateM(mMatrix, mTop, x, y, z);
    
public voidglTranslatex(int x, int y, int z)

        glTranslatef(fixedToFloat(x), fixedToFloat(y), fixedToFloat(z));
    
private voidpreflight_adjust(int dir)

        int newTop = mTop + dir * MATRIX_SIZE;
        if (newTop < 0) {
            throw new IllegalArgumentException("stack underflow");
        }
        if (newTop + MATRIX_SIZE > mMatrix.length) {
            throw new IllegalArgumentException("stack overflow");
        }