| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 |  | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_RS_MATRIX_4x4_H | 
 | 18 | #define ANDROID_RS_MATRIX_4x4_H | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 19 |  | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 20 | #include "rsType.h" | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 21 |  | 
 | 22 |  | 
 | 23 | // --------------------------------------------------------------------------- | 
 | 24 | namespace android { | 
 | 25 | namespace renderscript { | 
 | 26 |  | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 27 | struct Matrix4x4 : public rs_matrix4x4 { | 
 | 28 |     float get(uint32_t row, uint32_t col) const { | 
 | 29 |         return m[row*4 + col]; | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 30 |     } | 
 | 31 |  | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 32 |     void set(uint32_t row, uint32_t col, float v) { | 
 | 33 |         m[row*4 + col] = v; | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 34 |     } | 
 | 35 |  | 
 | 36 |     void loadIdentity(); | 
 | 37 |     void load(const float *); | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 38 |     void load(const rs_matrix4x4 *); | 
 | 39 |     void load(const rs_matrix3x3 *); | 
 | 40 |     void load(const rs_matrix2x2 *); | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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); | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 45 |     void loadMultiply(const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs); | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 |  | 
| Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 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); | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 49 |     void loadPerspective(float fovy, float aspect, float near, float far); | 
| Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 50 |  | 
| Jason Sams | 3a97c59 | 2009-09-30 17:36:20 -0700 | [diff] [blame] | 51 |     void vectorMultiply(float *v4out, const float *v3in) const; | 
 | 52 |  | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 53 |     bool inverse(); | 
 | 54 |     bool inverseTranspose(); | 
 | 55 |     void transpose(); | 
 | 56 |  | 
| Jason Sams | f47fb9b | 2011-04-22 14:24:17 -0700 | [diff] [blame] | 57 |     void logv(const char *s) const; | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 58 |  | 
 | 59 |  | 
 | 60 |     void multiply(const rs_matrix4x4 *rhs) { | 
 | 61 |         Matrix4x4 tmp; | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 62 |         tmp.loadMultiply(this, rhs); | 
 | 63 |         load(&tmp); | 
 | 64 |     } | 
 | 65 |     void rotate(float rot, float x, float y, float z) { | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 66 |         Matrix4x4 tmp; | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 67 |         tmp.loadRotate(rot, x, y, z); | 
 | 68 |         multiply(&tmp); | 
 | 69 |     } | 
 | 70 |     void scale(float x, float y, float z) { | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 71 |         Matrix4x4 tmp; | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 72 |         tmp.loadScale(x, y, z); | 
 | 73 |         multiply(&tmp); | 
 | 74 |     } | 
 | 75 |     void translate(float x, float y, float z) { | 
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 76 |         Matrix4x4 tmp; | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 77 |         tmp.loadTranslate(x, y, z); | 
 | 78 |         multiply(&tmp); | 
 | 79 |     } | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 80 | }; | 
| Jason Sams | 3a97c59 | 2009-09-30 17:36:20 -0700 | [diff] [blame] | 81 |  | 
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 82 | } | 
 | 83 | } | 
 | 84 |  | 
 | 85 |  | 
 | 86 |  | 
 | 87 |  | 
 | 88 | #endif | 
 | 89 |  | 
 | 90 |  | 
 | 91 |  | 
 | 92 |  |