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