1 /* 2 * Copyright (C) 2009-2012 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_4x4_H 18 #define ANDROID_RS_MATRIX_4x4_H 19 20 #include "rsType.h" 21 22 23 // --------------------------------------------------------------------------- 24 namespace android { 25 namespace renderscript { 26 27 struct Matrix4x4 : public rs_matrix4x4 { getMatrix4x428 float get(uint32_t col, uint32_t row) const { 29 return m[col*4 + row]; 30 } 31 setMatrix4x432 void set(uint32_t col, uint32_t row, float v) { 33 m[col*4 + row] = v; 34 } 35 36 void loadIdentity(); 37 void load(const float *); 38 void load(const rs_matrix4x4 *); 39 void load(const rs_matrix3x3 *); 40 void load(const rs_matrix2x2 *); 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 rs_matrix4x4 *lhs, const rs_matrix4x4 *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 void loadPerspective(float fovy, float aspect, float near, float far); 50 51 // Note: This assumes that the input vector (in) is of length 3. 52 void vectorMultiply(float *v4out, const float *v3in) const; 53 54 bool inverse(); 55 bool inverseTranspose(); 56 void transpose(); 57 58 void logv(const char *s) const; 59 60 multiplyMatrix4x461 void multiply(const rs_matrix4x4 *rhs) { 62 loadMultiply(this, rhs); 63 } rotateMatrix4x464 void rotate(float rot, float x, float y, float z) { 65 Matrix4x4 tmp; 66 tmp.loadRotate(rot, x, y, z); 67 multiply(&tmp); 68 } scaleMatrix4x469 void scale(float x, float y, float z) { 70 Matrix4x4 tmp; 71 tmp.loadScale(x, y, z); 72 multiply(&tmp); 73 } translateMatrix4x474 void translate(float x, float y, float z) { 75 Matrix4x4 tmp; 76 tmp.loadTranslate(x, y, z); 77 multiply(&tmp); 78 } 79 }; 80 81 } // namespace renderscript 82 } // namespace android 83 84 #endif // ANDROID_RS_MATRIX_4x4_H 85