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