Home | History | Annotate | Download | only in rs
      1 /*
      2  * Copyright (C) 2009 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 #ifndef ANDROID_RS_MATRIX_H
     18 #define ANDROID_RS_MATRIX_H
     19 
     20 
     21 
     22 // ---------------------------------------------------------------------------
     23 namespace android {
     24 namespace renderscript {
     25 
     26 struct Matrix
     27 {
     28     float m[16];
     29 
     30     inline float get(int i, int j) const {
     31         return m[i*4 + j];
     32     }
     33 
     34     inline void set(int i, int j, float v) {
     35         m[i*4 + j] = v;
     36     }
     37 
     38     void loadIdentity();
     39     void load(const float *);
     40     void load(const Matrix *);
     41 
     42     void loadRotate(float rot, float x, float y, float z);
     43     void loadScale(float x, float y, float z);
     44     void loadTranslate(float x, float y, float z);
     45     void loadMultiply(const Matrix *lhs, const Matrix *rhs);
     46 
     47     void loadOrtho(float l, float r, float b, float t, float n, float f);
     48     void loadFrustum(float l, float r, float b, float t, float n, float f);
     49 
     50     void vectorMultiply(float *v4out, const float *v3in) const;
     51 
     52     void multiply(const Matrix *rhs) {
     53         Matrix tmp;
     54         tmp.loadMultiply(this, rhs);
     55         load(&tmp);
     56     }
     57     void rotate(float rot, float x, float y, float z) {
     58         Matrix tmp;
     59         tmp.loadRotate(rot, x, y, z);
     60         multiply(&tmp);
     61     }
     62     void scale(float x, float y, float z) {
     63         Matrix tmp;
     64         tmp.loadScale(x, y, z);
     65         multiply(&tmp);
     66     }
     67     void translate(float x, float y, float z) {
     68         Matrix tmp;
     69         tmp.loadTranslate(x, y, z);
     70         multiply(&tmp);
     71     }
     72 
     73 
     74 
     75 };
     76 
     77 
     78 
     79 }
     80 }
     81 
     82 
     83 
     84 
     85 #endif
     86 
     87 
     88 
     89 
     90