1*b7c941bbSAndroid Build Coastguard Worker /* 2*b7c941bbSAndroid Build Coastguard Worker * Copyright (C) 2013 The Android Open Source Project 3*b7c941bbSAndroid Build Coastguard Worker * 4*b7c941bbSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5*b7c941bbSAndroid Build Coastguard Worker * in compliance with the License. You may obtain a copy of the License at 6*b7c941bbSAndroid Build Coastguard Worker * 7*b7c941bbSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 8*b7c941bbSAndroid Build Coastguard Worker * 9*b7c941bbSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software distributed under the License 10*b7c941bbSAndroid Build Coastguard Worker * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11*b7c941bbSAndroid Build Coastguard Worker * or implied. See the License for the specific language governing permissions and limitations under 12*b7c941bbSAndroid Build Coastguard Worker * the License. 13*b7c941bbSAndroid Build Coastguard Worker */ 14*b7c941bbSAndroid Build Coastguard Worker #ifndef MATRIX_H 15*b7c941bbSAndroid Build Coastguard Worker #define MATRIX_H 16*b7c941bbSAndroid Build Coastguard Worker 17*b7c941bbSAndroid Build Coastguard Worker class Matrix { 18*b7c941bbSAndroid Build Coastguard Worker public: 19*b7c941bbSAndroid Build Coastguard Worker static const int MATRIX_SIZE = 16; 20*b7c941bbSAndroid Build Coastguard Worker float mData[MATRIX_SIZE]; 21*b7c941bbSAndroid Build Coastguard Worker Matrix(); 22*b7c941bbSAndroid Build Coastguard Worker Matrix(const Matrix& src); 23*b7c941bbSAndroid Build Coastguard Worker // Returns true if the two matrices have the same values. 24*b7c941bbSAndroid Build Coastguard Worker bool equals(const Matrix& src); 25*b7c941bbSAndroid Build Coastguard Worker // Loads this matrix with the identity matrix. 26*b7c941bbSAndroid Build Coastguard Worker void identity(); 27*b7c941bbSAndroid Build Coastguard Worker // Loads this matrix with the data from src. 28*b7c941bbSAndroid Build Coastguard Worker void loadWith(const Matrix& src); 29*b7c941bbSAndroid Build Coastguard Worker // Translates this matrix by the given amounts. 30*b7c941bbSAndroid Build Coastguard Worker void translate(float x, float y, float z); 31*b7c941bbSAndroid Build Coastguard Worker // Scales this matrix by the given amounts. 32*b7c941bbSAndroid Build Coastguard Worker void scale(float x, float y, float z); 33*b7c941bbSAndroid Build Coastguard Worker // Rotates this matrix the given angle. 34*b7c941bbSAndroid Build Coastguard Worker void rotate(float radians, float x, float y, float z); 35*b7c941bbSAndroid Build Coastguard Worker // Sets this matrix to be the result of multiplying the given matrices. 36*b7c941bbSAndroid Build Coastguard Worker void multiply(const Matrix& l, const Matrix& r); 37*b7c941bbSAndroid Build Coastguard Worker 38*b7c941bbSAndroid Build Coastguard Worker void print(const char* label); 39*b7c941bbSAndroid Build Coastguard Worker 40*b7c941bbSAndroid Build Coastguard Worker // Returns a new matrix representing the camera. 41*b7c941bbSAndroid Build Coastguard Worker static Matrix* newLookAt(float eyeX, float eyeY, float eyeZ, float centerX, 42*b7c941bbSAndroid Build Coastguard Worker float centerY, float centerZ, float upX, float upY, float upZ); 43*b7c941bbSAndroid Build Coastguard Worker // Returns a new matrix representing the perspective matrix. 44*b7c941bbSAndroid Build Coastguard Worker static Matrix* newFrustum(float left, float right, float bottom, float top, 45*b7c941bbSAndroid Build Coastguard Worker float near, float far); 46*b7c941bbSAndroid Build Coastguard Worker // Returns a new matrix representing the translation. 47*b7c941bbSAndroid Build Coastguard Worker static Matrix* newTranslate(float x, float y, float z); 48*b7c941bbSAndroid Build Coastguard Worker // Returns a new matrix representing the scaling. 49*b7c941bbSAndroid Build Coastguard Worker static Matrix* newScale(float x, float y, float z); 50*b7c941bbSAndroid Build Coastguard Worker // Returns a new matrix representing the rotation. 51*b7c941bbSAndroid Build Coastguard Worker static Matrix* newRotate(float radians, float x, float y, float z); 52*b7c941bbSAndroid Build Coastguard Worker 53*b7c941bbSAndroid Build Coastguard Worker // Sets the given matrix to be the result of multiplying the given matrix by the given vector. 54*b7c941bbSAndroid Build Coastguard Worker static void multiplyVector(float* result, const Matrix& lhs, 55*b7c941bbSAndroid Build Coastguard Worker const float* rhs); 56*b7c941bbSAndroid Build Coastguard Worker }; 57*b7c941bbSAndroid Build Coastguard Worker 58*b7c941bbSAndroid Build Coastguard Worker #endif 59