Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 1 | /* |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 2 | * Copyright (C) 2015 The Android Open Source Project |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 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 | |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 17 | // Don't edit this file! It is auto-generated by frameworks/rs/api/generate.sh. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 18 | |
| 19 | /* |
Jean-Luc Brouillet | 20b27d6 | 2015-04-03 14:39:53 -0700 | [diff] [blame^] | 20 | * rs_matrix.rsh: Matrix Functions |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 21 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 22 | * These functions let you manipulate square matrices of rank 2x2, 3x3, and 4x4. |
| 23 | * They are particularly useful for graphical transformations and are |
| 24 | * compatible with OpenGL. |
| 25 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 26 | * We use a zero-based index for rows and columns. E.g. the last element of |
| 27 | * a rs_matrix4x4 is found at (3, 3). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 28 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 29 | * RenderScript uses column-major matrices and column-based vectors. |
| 30 | * Transforming a vector is done by postmultiplying the vector, |
| 31 | * e.g. (matrix * vector), as provided by rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 32 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 33 | * To create a transformation matrix that performs two transformations at |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 34 | * once, multiply the two source matrices, with the first transformation as the |
| 35 | * right argument. E.g. to create a transformation matrix that applies the |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 36 | * transformation s1 followed by s2, call rsMatrixLoadMultiply(&combined, &s2, &s1). |
| 37 | * This derives from s2 * (s1 * v), which is (s2 * s1) * v. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 38 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 39 | * We have two style of functions to create transformation matrices: |
| 40 | * rsMatrixLoadTransformation and rsMatrixTransformation. The |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 41 | * former style simply stores the transformation matrix in the first argument. |
| 42 | * The latter modifies a pre-existing transformation matrix so that the new |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 43 | * transformation happens first. E.g. if you call rsMatrixTranslate() |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 44 | * on a matrix that already does a scaling, the resulting matrix when applied |
| 45 | * to a vector will first do the translation then the scaling. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 46 | */ |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 47 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 48 | #ifndef RENDERSCRIPT_RS_MATRIX_RSH |
| 49 | #define RENDERSCRIPT_RS_MATRIX_RSH |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 50 | |
Jean-Luc Brouillet | be21638 | 2015-03-22 12:44:27 -0700 | [diff] [blame] | 51 | #include "rs_vector_math.rsh" |
| 52 | |
| 53 | /* |
Jean-Luc Brouillet | 20b27d6 | 2015-04-03 14:39:53 -0700 | [diff] [blame^] | 54 | * rsExtractFrustumPlanes: Compute frustum planes |
| 55 | * |
Jean-Luc Brouillet | be21638 | 2015-03-22 12:44:27 -0700 | [diff] [blame] | 56 | * Computes 6 frustum planes from the view projection matrix |
| 57 | * |
| 58 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 59 | * viewProj: matrix to extract planes from |
| 60 | * left: left plane |
| 61 | * right: right plane |
| 62 | * top: top plane |
| 63 | * bottom: bottom plane |
| 64 | * near: near plane |
| 65 | * far: far plane |
Jean-Luc Brouillet | be21638 | 2015-03-22 12:44:27 -0700 | [diff] [blame] | 66 | */ |
| 67 | static inline void __attribute__((always_inline, overloadable)) |
| 68 | rsExtractFrustumPlanes(const rs_matrix4x4* viewProj, float4* left, float4* right, float4* top, |
| 69 | float4* bottom, float4* near, float4* far) { |
| 70 | // x y z w = a b c d in the plane equation |
| 71 | left->x = viewProj->m[3] + viewProj->m[0]; |
| 72 | left->y = viewProj->m[7] + viewProj->m[4]; |
| 73 | left->z = viewProj->m[11] + viewProj->m[8]; |
| 74 | left->w = viewProj->m[15] + viewProj->m[12]; |
| 75 | |
| 76 | right->x = viewProj->m[3] - viewProj->m[0]; |
| 77 | right->y = viewProj->m[7] - viewProj->m[4]; |
| 78 | right->z = viewProj->m[11] - viewProj->m[8]; |
| 79 | right->w = viewProj->m[15] - viewProj->m[12]; |
| 80 | |
| 81 | top->x = viewProj->m[3] - viewProj->m[1]; |
| 82 | top->y = viewProj->m[7] - viewProj->m[5]; |
| 83 | top->z = viewProj->m[11] - viewProj->m[9]; |
| 84 | top->w = viewProj->m[15] - viewProj->m[13]; |
| 85 | |
| 86 | bottom->x = viewProj->m[3] + viewProj->m[1]; |
| 87 | bottom->y = viewProj->m[7] + viewProj->m[5]; |
| 88 | bottom->z = viewProj->m[11] + viewProj->m[9]; |
| 89 | bottom->w = viewProj->m[15] + viewProj->m[13]; |
| 90 | |
| 91 | near->x = viewProj->m[3] + viewProj->m[2]; |
| 92 | near->y = viewProj->m[7] + viewProj->m[6]; |
| 93 | near->z = viewProj->m[11] + viewProj->m[10]; |
| 94 | near->w = viewProj->m[15] + viewProj->m[14]; |
| 95 | |
| 96 | far->x = viewProj->m[3] - viewProj->m[2]; |
| 97 | far->y = viewProj->m[7] - viewProj->m[6]; |
| 98 | far->z = viewProj->m[11] - viewProj->m[10]; |
| 99 | far->w = viewProj->m[15] - viewProj->m[14]; |
| 100 | |
| 101 | float len = length(left->xyz); |
| 102 | *left /= len; |
| 103 | len = length(right->xyz); |
| 104 | *right /= len; |
| 105 | len = length(top->xyz); |
| 106 | *top /= len; |
| 107 | len = length(bottom->xyz); |
| 108 | *bottom /= len; |
| 109 | len = length(near->xyz); |
| 110 | *near /= len; |
| 111 | len = length(far->xyz); |
| 112 | *far /= len; |
| 113 | } |
| 114 | |
| 115 | /* |
Jean-Luc Brouillet | 20b27d6 | 2015-04-03 14:39:53 -0700 | [diff] [blame^] | 116 | * rsIsSphereInFrustum: Checks if a sphere is within the frustum planes |
| 117 | * |
| 118 | * Returns true if the sphere is within the 6 frustum planes. |
Jean-Luc Brouillet | be21638 | 2015-03-22 12:44:27 -0700 | [diff] [blame] | 119 | * |
| 120 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 121 | * sphere: float4 representing the sphere |
| 122 | * left: left plane |
| 123 | * right: right plane |
| 124 | * top: top plane |
| 125 | * bottom: bottom plane |
| 126 | * near: near plane |
| 127 | * far: far plane |
Jean-Luc Brouillet | be21638 | 2015-03-22 12:44:27 -0700 | [diff] [blame] | 128 | */ |
| 129 | static inline bool __attribute__((always_inline, overloadable)) |
| 130 | rsIsSphereInFrustum(float4* sphere, float4* left, float4* right, float4* top, float4* bottom, |
| 131 | float4* near, float4* far) { |
| 132 | float distToCenter = dot(left->xyz, sphere->xyz) + left->w; |
| 133 | if (distToCenter < -sphere->w) { |
| 134 | return false; |
| 135 | } |
| 136 | distToCenter = dot(right->xyz, sphere->xyz) + right->w; |
| 137 | if (distToCenter < -sphere->w) { |
| 138 | return false; |
| 139 | } |
| 140 | distToCenter = dot(top->xyz, sphere->xyz) + top->w; |
| 141 | if (distToCenter < -sphere->w) { |
| 142 | return false; |
| 143 | } |
| 144 | distToCenter = dot(bottom->xyz, sphere->xyz) + bottom->w; |
| 145 | if (distToCenter < -sphere->w) { |
| 146 | return false; |
| 147 | } |
| 148 | distToCenter = dot(near->xyz, sphere->xyz) + near->w; |
| 149 | if (distToCenter < -sphere->w) { |
| 150 | return false; |
| 151 | } |
| 152 | distToCenter = dot(far->xyz, sphere->xyz) + far->w; |
| 153 | if (distToCenter < -sphere->w) { |
| 154 | return false; |
| 155 | } |
| 156 | return true; |
| 157 | } |
| 158 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 159 | /* |
| 160 | * rsMatrixGet: Get one element |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 161 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 162 | * Returns one element of a matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 163 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 164 | * Warning: The order of the column and row parameters may be unexpected. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 165 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 166 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 167 | * m: The matrix to extract the element from. |
| 168 | * col: The zero-based column of the element to be extracted. |
| 169 | * row: The zero-based row of the element to extracted. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 170 | */ |
Jean-Luc Brouillet | 129c147 | 2015-03-02 15:37:07 -0800 | [diff] [blame] | 171 | extern float __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 172 | rsMatrixGet(const rs_matrix4x4* m, uint32_t col, uint32_t row); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 173 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 174 | extern float __attribute__((overloadable)) |
| 175 | rsMatrixGet(const rs_matrix3x3* m, uint32_t col, uint32_t row); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 176 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 177 | extern float __attribute__((overloadable)) |
| 178 | rsMatrixGet(const rs_matrix2x2* m, uint32_t col, uint32_t row); |
| 179 | |
| 180 | /* |
| 181 | * rsMatrixInverse: Inverts a matrix in place |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 182 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 183 | * Returns true if the matrix was successfully inverted. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 184 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 185 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 186 | * m: The matrix to invert. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 187 | */ |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 188 | extern bool __attribute__((overloadable)) |
| 189 | rsMatrixInverse(rs_matrix4x4* m); |
| 190 | |
| 191 | /* |
| 192 | * rsMatrixInverseTranspose: Inverts and transpose a matrix in place |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 193 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 194 | * The matrix is first inverted then transposed. |
| 195 | * Returns true if the matrix was successfully inverted. |
| 196 | * |
| 197 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 198 | * m: The matrix to modify. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 199 | */ |
| 200 | extern bool __attribute__((overloadable)) |
| 201 | rsMatrixInverseTranspose(rs_matrix4x4* m); |
| 202 | |
| 203 | /* |
| 204 | * rsMatrixLoad: Load or copy a matrix |
| 205 | * |
| 206 | * Set the elements of a matrix from an array of floats or from another matrix. |
| 207 | * |
| 208 | * If loading from an array, the floats should be in row-major order, i.e. the element a |
| 209 | * row 0, column 0 should be first, followed by the element at |
| 210 | * row 0, column 1, etc. |
| 211 | * |
| 212 | * If loading from a matrix and the source is smaller than the destination, the rest of the |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 213 | * destination is filled with elements of the identity matrix. E.g. |
| 214 | * loading a rs_matrix2x2 into a rs_matrix4x4 will give: |
| 215 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 216 | * m00 m01 0.0 0.0 |
| 217 | * m10 m11 0.0 0.0 |
| 218 | * 0.0 0.0 1.0 0.0 |
| 219 | * 0.0 0.0 0.0 1.0 |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 220 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 221 | * |
| 222 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 223 | * destination: The matrix to set. |
| 224 | * array: The array of values to set the matrix to. These arrays should be 4, 9, or 16 floats long, depending on the matrix size. |
| 225 | * source: The source matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 226 | */ |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 227 | extern void __attribute__((overloadable)) |
| 228 | rsMatrixLoad(rs_matrix4x4* destination, const float* array); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 229 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 230 | extern void __attribute__((overloadable)) |
| 231 | rsMatrixLoad(rs_matrix3x3* destination, const float* array); |
| 232 | |
| 233 | extern void __attribute__((overloadable)) |
| 234 | rsMatrixLoad(rs_matrix2x2* destination, const float* array); |
| 235 | |
| 236 | extern void __attribute__((overloadable)) |
| 237 | rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix4x4* source); |
| 238 | |
| 239 | extern void __attribute__((overloadable)) |
| 240 | rsMatrixLoad(rs_matrix3x3* destination, const rs_matrix3x3* source); |
| 241 | |
| 242 | extern void __attribute__((overloadable)) |
| 243 | rsMatrixLoad(rs_matrix2x2* destination, const rs_matrix2x2* source); |
| 244 | |
| 245 | extern void __attribute__((overloadable)) |
| 246 | rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix3x3* source); |
| 247 | |
| 248 | extern void __attribute__((overloadable)) |
| 249 | rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix2x2* source); |
| 250 | |
| 251 | /* |
| 252 | * rsMatrixLoadFrustum: Load a frustum projection matrix |
| 253 | * |
| 254 | * Constructs a frustum projection matrix, transforming the box |
| 255 | * identified by the six clipping planes left, right, bottom, top, |
| 256 | * near, far. |
| 257 | * |
| 258 | * To apply this projection to a vector, multiply the vector by the |
| 259 | * created matrix using rsMatrixMultiply(). |
| 260 | * |
| 261 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 262 | * m: The matrix to set. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 263 | */ |
| 264 | extern void __attribute__((overloadable)) |
| 265 | rsMatrixLoadFrustum(rs_matrix4x4* m, float left, float right, float bottom, float top, |
| 266 | float near, float far); |
| 267 | |
| 268 | /* |
| 269 | * rsMatrixLoadIdentity: Load identity matrix |
| 270 | * |
| 271 | * Set the elements of a matrix to the identity matrix. |
| 272 | * |
| 273 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 274 | * m: The matrix to set. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 275 | */ |
| 276 | extern void __attribute__((overloadable)) |
| 277 | rsMatrixLoadIdentity(rs_matrix4x4* m); |
| 278 | |
| 279 | extern void __attribute__((overloadable)) |
| 280 | rsMatrixLoadIdentity(rs_matrix3x3* m); |
| 281 | |
| 282 | extern void __attribute__((overloadable)) |
| 283 | rsMatrixLoadIdentity(rs_matrix2x2* m); |
| 284 | |
| 285 | /* |
| 286 | * rsMatrixLoadMultiply: Multiply two matrices |
| 287 | * |
| 288 | * Sets m to the matrix product of lhs * rhs. |
| 289 | * |
| 290 | * To combine two 4x4 transformaton matrices, multiply the second transformation matrix |
| 291 | * by the first transformation matrix. E.g. to create a transformation matrix that applies |
| 292 | * the transformation s1 followed by s2, call |
| 293 | * rsMatrixLoadMultiply(&combined, &s2, &s1). |
| 294 | * |
| 295 | * Warning: Prior to version 21, storing the result back into right matrix is not supported and |
| 296 | * will result in undefined behavior. Use rsMatrixMulitply instead. E.g. instead of doing |
| 297 | * rsMatrixLoadMultiply (&m2r, &m2r, &m2l), use rsMatrixMultiply (&m2r, &m2l). |
| 298 | * rsMatrixLoadMultiply (&m2l, &m2r, &m2l) works as expected. |
| 299 | * |
| 300 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 301 | * m: The matrix to set. |
| 302 | * lhs: The left matrix of the product. |
| 303 | * rhs: The right matrix of the product. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 304 | */ |
| 305 | extern void __attribute__((overloadable)) |
| 306 | rsMatrixLoadMultiply(rs_matrix4x4* m, const rs_matrix4x4* lhs, const rs_matrix4x4* rhs); |
| 307 | |
| 308 | extern void __attribute__((overloadable)) |
| 309 | rsMatrixLoadMultiply(rs_matrix3x3* m, const rs_matrix3x3* lhs, const rs_matrix3x3* rhs); |
| 310 | |
| 311 | extern void __attribute__((overloadable)) |
| 312 | rsMatrixLoadMultiply(rs_matrix2x2* m, const rs_matrix2x2* lhs, const rs_matrix2x2* rhs); |
| 313 | |
| 314 | /* |
| 315 | * rsMatrixLoadOrtho: Load an orthographic projection matrix |
| 316 | * |
| 317 | * Constructs an orthographic projection matrix, transforming the box |
| 318 | * identified by the six clipping planes left, right, bottom, top, |
| 319 | * near, far into a unit cube with a corner at |
| 320 | * (-1, -1, -1) and the opposite at (1, 1, 1). |
| 321 | * |
| 322 | * To apply this projection to a vector, multiply the vector by the |
| 323 | * created matrix using rsMatrixMultiply(). |
| 324 | * |
| 325 | * See https://en.wikipedia.org/wiki/Orthographic_projection . |
| 326 | * |
| 327 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 328 | * m: The matrix to set. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 329 | */ |
| 330 | extern void __attribute__((overloadable)) |
| 331 | rsMatrixLoadOrtho(rs_matrix4x4* m, float left, float right, float bottom, float top, float near, |
| 332 | float far); |
| 333 | |
| 334 | /* |
| 335 | * rsMatrixLoadPerspective: Load a perspective projection matrix |
| 336 | * |
| 337 | * Constructs a perspective projection matrix, assuming a symmetrical field of view. |
| 338 | * |
| 339 | * To apply this projection to a vector, multiply the vector by the |
| 340 | * created matrix using rsMatrixMultiply(). |
| 341 | * |
| 342 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 343 | * m: The matrix to set. |
| 344 | * fovy: Field of view, in degrees along the Y axis. |
| 345 | * aspect: Ratio of x / y. |
| 346 | * near: The near clipping plane. |
| 347 | * far: The far clipping plane. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 348 | */ |
| 349 | extern void __attribute__((overloadable)) |
| 350 | rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far); |
| 351 | |
| 352 | /* |
| 353 | * rsMatrixLoadRotate: Load a rotation matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 354 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 355 | * This function creates a rotation matrix. The axis of rotation is the |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 356 | * (x, y, z) vector. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 357 | * |
| 358 | * To rotate a vector, multiply the vector by the created matrix |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 359 | * using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 360 | * |
| 361 | * See http://en.wikipedia.org/wiki/Rotation_matrix . |
| 362 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 363 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 364 | * m: The matrix to set. |
| 365 | * rot: How much rotation to do, in degrees. |
| 366 | * x: The x component of the vector that is the axis of rotation. |
| 367 | * y: The y component of the vector that is the axis of rotation. |
| 368 | * z: The z component of the vector that is the axis of rotation. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 369 | */ |
| 370 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 371 | rsMatrixLoadRotate(rs_matrix4x4* m, float rot, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 372 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 373 | /* |
| 374 | * rsMatrixLoadScale: Load a scaling matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 375 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 376 | * This function creates a scaling matrix, where each component of a |
| 377 | * vector is multiplied by a number. This number can be negative. |
| 378 | * |
| 379 | * To scale a vector, multiply the vector by the created matrix |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 380 | * using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 381 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 382 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 383 | * m: The matrix to set. |
| 384 | * x: The multiple to scale the x components by. |
| 385 | * y: The multiple to scale the y components by. |
| 386 | * z: The multiple to scale the z components by. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 387 | */ |
| 388 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 389 | rsMatrixLoadScale(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 390 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 391 | /* |
| 392 | * rsMatrixLoadTranslate: Load a translation matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 393 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 394 | * This function creates a translation matrix, where a |
| 395 | * number is added to each element of a vector. |
| 396 | * |
| 397 | * To translate a vector, multiply the vector by the created matrix |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 398 | * using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 399 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 400 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 401 | * m: The matrix to set. |
| 402 | * x: The number to add to each x component. |
| 403 | * y: The number to add to each y component. |
| 404 | * z: The number to add to each z component. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 405 | */ |
| 406 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 407 | rsMatrixLoadTranslate(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 408 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 409 | /* |
| 410 | * rsMatrixMultiply: Multiply a matrix by a vector or another matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 411 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 412 | * For the matrix by matrix variant, sets m to the matrix product m * rhs. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 413 | * |
| 414 | * When combining two 4x4 transformation matrices using this function, the resulting |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 415 | * matrix will correspond to performing the rhs transformation first followed by |
| 416 | * the original m transformation. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 417 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 418 | * For the matrix by vector variant, returns the post-multiplication of the vector |
| 419 | * by the matrix, ie. m * in. |
| 420 | * |
| 421 | * When multiplying a float3 to a rs_matrix4x4, the vector is expanded with (1). |
| 422 | * |
| 423 | * When multiplying a float2 to a rs_matrix4x4, the vector is expanded with (0, 1). |
| 424 | * |
| 425 | * When multiplying a float2 to a rs_matrix3x3, the vector is expanded with (0). |
| 426 | * |
| 427 | * Starting with API 14, this function takes a const matrix as the first argument. |
| 428 | * |
| 429 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 430 | * m: The left matrix of the product and the matrix to be set. |
| 431 | * rhs: The right matrix of the product. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 432 | */ |
| 433 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 434 | rsMatrixMultiply(rs_matrix4x4* m, const rs_matrix4x4* rhs); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 435 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 436 | extern void __attribute__((overloadable)) |
| 437 | rsMatrixMultiply(rs_matrix3x3* m, const rs_matrix3x3* rhs); |
| 438 | |
| 439 | extern void __attribute__((overloadable)) |
| 440 | rsMatrixMultiply(rs_matrix2x2* m, const rs_matrix2x2* rhs); |
| 441 | |
| 442 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 443 | extern float4 __attribute__((overloadable)) |
| 444 | rsMatrixMultiply(rs_matrix4x4* m, float4 in); |
| 445 | #endif |
| 446 | |
| 447 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 448 | extern float4 __attribute__((overloadable)) |
| 449 | rsMatrixMultiply(rs_matrix4x4* m, float3 in); |
| 450 | #endif |
| 451 | |
| 452 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 453 | extern float4 __attribute__((overloadable)) |
| 454 | rsMatrixMultiply(rs_matrix4x4* m, float2 in); |
| 455 | #endif |
| 456 | |
| 457 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 458 | extern float3 __attribute__((overloadable)) |
| 459 | rsMatrixMultiply(rs_matrix3x3* m, float3 in); |
| 460 | #endif |
| 461 | |
| 462 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 463 | extern float3 __attribute__((overloadable)) |
| 464 | rsMatrixMultiply(rs_matrix3x3* m, float2 in); |
| 465 | #endif |
| 466 | |
| 467 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 468 | extern float2 __attribute__((overloadable)) |
| 469 | rsMatrixMultiply(rs_matrix2x2* m, float2 in); |
| 470 | #endif |
| 471 | |
| 472 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 473 | extern float4 __attribute__((overloadable)) |
| 474 | rsMatrixMultiply(const rs_matrix4x4* m, float4 in); |
| 475 | #endif |
| 476 | |
| 477 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 478 | extern float4 __attribute__((overloadable)) |
| 479 | rsMatrixMultiply(const rs_matrix4x4* m, float3 in); |
| 480 | #endif |
| 481 | |
| 482 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 483 | extern float4 __attribute__((overloadable)) |
| 484 | rsMatrixMultiply(const rs_matrix4x4* m, float2 in); |
| 485 | #endif |
| 486 | |
| 487 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 488 | extern float3 __attribute__((overloadable)) |
| 489 | rsMatrixMultiply(const rs_matrix3x3* m, float3 in); |
| 490 | #endif |
| 491 | |
| 492 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 493 | extern float3 __attribute__((overloadable)) |
| 494 | rsMatrixMultiply(const rs_matrix3x3* m, float2 in); |
| 495 | #endif |
| 496 | |
| 497 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 498 | extern float2 __attribute__((overloadable)) |
| 499 | rsMatrixMultiply(const rs_matrix2x2* m, float2 in); |
| 500 | #endif |
| 501 | |
| 502 | /* |
| 503 | * rsMatrixRotate: Apply a rotation to a transformation matrix |
| 504 | * |
| 505 | * Multiply the matrix m with a rotation matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 506 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 507 | * This function modifies a transformation matrix to first do a rotation. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 508 | * The axis of rotation is the (x, y, z) vector. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 509 | * |
| 510 | * To apply this combined transformation to a vector, multiply |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 511 | * the vector by the created matrix using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 512 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 513 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 514 | * m: The matrix to modify. |
| 515 | * rot: How much rotation to do, in degrees. |
| 516 | * x: The x component of the vector that is the axis of rotation. |
| 517 | * y: The y component of the vector that is the axis of rotation. |
| 518 | * z: The z component of the vector that is the axis of rotation. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 519 | */ |
| 520 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 521 | rsMatrixRotate(rs_matrix4x4* m, float rot, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 522 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 523 | /* |
| 524 | * rsMatrixScale: Apply a scaling to a transformation matrix |
| 525 | * |
| 526 | * Multiply the matrix m with a scaling matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 527 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 528 | * This function modifies a transformation matrix to first do a scaling. |
| 529 | * When scaling, each component of a vector is multiplied by a number. |
| 530 | * This number can be negative. |
| 531 | * |
| 532 | * To apply this combined transformation to a vector, multiply |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 533 | * the vector by the created matrix using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 534 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 535 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 536 | * m: The matrix to modify. |
| 537 | * x: The multiple to scale the x components by. |
| 538 | * y: The multiple to scale the y components by. |
| 539 | * z: The multiple to scale the z components by. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 540 | */ |
| 541 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 542 | rsMatrixScale(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 543 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 544 | /* |
| 545 | * rsMatrixSet: Set one element |
| 546 | * |
| 547 | * Set an element of a matrix. |
| 548 | * |
| 549 | * Warning: The order of the column and row parameters may be unexpected. |
| 550 | * |
| 551 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 552 | * m: The matrix that will be modified. |
| 553 | * col: The zero-based column of the element to be set. |
| 554 | * row: The zero-based row of the element to be set. |
| 555 | * v: The value to set. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 556 | */ |
| 557 | extern void __attribute__((overloadable)) |
| 558 | rsMatrixSet(rs_matrix4x4* m, uint32_t col, uint32_t row, float v); |
| 559 | |
| 560 | extern void __attribute__((overloadable)) |
| 561 | rsMatrixSet(rs_matrix3x3* m, uint32_t col, uint32_t row, float v); |
| 562 | |
| 563 | extern void __attribute__((overloadable)) |
| 564 | rsMatrixSet(rs_matrix2x2* m, uint32_t col, uint32_t row, float v); |
| 565 | |
| 566 | /* |
| 567 | * rsMatrixTranslate: Apply a translation to a transformation matrix |
| 568 | * |
| 569 | * Multiply the matrix m with a translation matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 570 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 571 | * This function modifies a transformation matrix to first |
| 572 | * do a translation. When translating, a number is added |
| 573 | * to each component of a vector. |
| 574 | * |
| 575 | * To apply this combined transformation to a vector, multiply |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 576 | * the vector by the created matrix using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 577 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 578 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 579 | * m: The matrix to modify. |
| 580 | * x: The number to add to each x component. |
| 581 | * y: The number to add to each y component. |
| 582 | * z: The number to add to each z component. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 583 | */ |
| 584 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 585 | rsMatrixTranslate(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 586 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 587 | /* |
| 588 | * rsMatrixTranspose: Transpose a matrix place |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 589 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 590 | * Transpose the matrix m in place. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 591 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 592 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame] | 593 | * m: The matrix to transpose. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 594 | */ |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 595 | extern void __attribute__((overloadable)) |
| 596 | rsMatrixTranspose(rs_matrix4x4* m); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 597 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 598 | extern void __attribute__((overloadable)) |
| 599 | rsMatrixTranspose(rs_matrix3x3* m); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 600 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 601 | extern void __attribute__((overloadable)) |
| 602 | rsMatrixTranspose(rs_matrix2x2* m); |
| 603 | |
| 604 | #endif // RENDERSCRIPT_RS_MATRIX_RSH |