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