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