rsMatrix.h revision 9c54bdbf458e3c9433d237ae71cf47c4ec47d852
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// --------------------------------------------------------------------------- 23namespace android { 24namespace renderscript { 25 26struct 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 multiply(const Matrix *rhs) { 51 Matrix tmp; 52 tmp.loadMultiply(this, rhs); 53 load(&tmp); 54 } 55 void rotate(float rot, float x, float y, float z) { 56 Matrix tmp; 57 tmp.loadRotate(rot, x, y, z); 58 multiply(&tmp); 59 } 60 void scale(float x, float y, float z) { 61 Matrix tmp; 62 tmp.loadScale(x, y, z); 63 multiply(&tmp); 64 } 65 void translate(float x, float y, float z) { 66 Matrix tmp; 67 tmp.loadTranslate(x, y, z); 68 multiply(&tmp); 69 } 70 71 72 73}; 74 75 76 77} 78} 79 80 81 82 83#endif 84 85 86 87 88