1044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/*
2044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Copyright (C) 2011 The Android Open Source Project
3044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
4044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * you may not use this file except in compliance with the License.
6044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * You may obtain a copy of the License at
7044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
8044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
10044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Unless required by applicable law or agreed to in writing, software
11044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * See the License for the specific language governing permissions and
14044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * limitations under the License.
15044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
16044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
17044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/** @file rs_matrix.rsh
181bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *  \brief Matrix functions.
19044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
201bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * These functions let you manipulate square matrices of rank 2x2, 3x3, and 4x4.
211bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * They are particularly useful for graphical transformations and are
221bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * compatible with OpenGL.
231bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
241bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * A few general notes:
251bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
261bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * \li We use a zero-based index for rows and columns.  E.g. the last element of
271bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * a \ref rs_matrix4x4 is found at (3, 3).
281bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
291bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * \li RenderScript uses column-based vectors.  Transforming a vector is done by
301bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * postmultiplying the vector, e.g. <em>(matrix * vector)</em>, as provided by
311bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * \ref rsMatrixMultiply.
321bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
331bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * \li To create a transformation matrix that performs two transformations at
341bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * once, multiply the two source matrices, with the first transformation as the
351bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * right argument.  E.g. to create a transformation matrix that applies the
361bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * transformation \e s1 followed by \e s2, call
371bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * </c>rsMatrixLoadMultiply(&combined, &s2, &s1)</c>.
381bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * This derives from <em>s2 * (s1 * v)</em>, which is <em>(s2 * s1) * v</em>.
391bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
401bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * \li We have two style of functions to create transformation matrices:
411bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * rsMatrixLoad<em>Transformation</em> and rsMatrix<em>Transformation</em>.  The
421bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * former style simply stores the transformation matrix in the first argument.
431bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * The latter modifies a pre-existing transformation matrix so that the new
441bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * transformation happens first.  E.g. if you call \ref rsMatrixTranslate
451bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * on a matrix that already does a scaling, the resulting matrix when applied
461bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * to a vector will first do the translation then the scaling.
47044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
48044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
49044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
50044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams#ifndef __RS_MATRIX_RSH__
51044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams#define __RS_MATRIX_RSH__
52044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
53044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
541bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Set an element of a matrix.
551bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
561bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix that will be modified.
571bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param col The zero-based column of the element to be set.
581bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param row The zero-based row of the element to be set.
591bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param v The value to set.
60044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
611bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * \warning The order of the column and row parameters may be
621bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * unexpected.
63044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
64044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @return void
65044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
66044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME void __attribute__((overloadable))
671bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixSet(rs_matrix4x4 *m, uint32_t col, uint32_t row, float v);
68044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
69044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
70044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
71044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME void __attribute__((overloadable))
721bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixSet(rs_matrix3x3 *m, uint32_t col, uint32_t row, float v);
73044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
74044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
75044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
76044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME void __attribute__((overloadable))
771bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixSet(rs_matrix2x2 *m, uint32_t col, uint32_t row, float v);
78044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
79044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
801bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Returns one element of a matrix.
811bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
821bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to extract the element from.
831bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param col The zero-based column of the element to be extracted.
841bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param row The zero-based row of the element to extracted.
85044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
861bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * \warning The order of the column and row parameters may be
871bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * unexpected.
88044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
89044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @return float
90044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
91044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float __attribute__((overloadable))
921bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixGet(const rs_matrix4x4 *m, uint32_t col, uint32_t row);
93044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
94044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
95044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
96044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float __attribute__((overloadable))
971bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixGet(const rs_matrix3x3 *m, uint32_t col, uint32_t row);
98044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
99044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
100044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
101044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float __attribute__((overloadable))
1021bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc BrouilletrsMatrixGet(const rs_matrix2x2 *m, uint32_t col, uint32_t row);
103044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
104044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
105044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Set the elements of a matrix to the identity matrix.
106044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
1071bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to set.
108044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
109044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix4x4 *m);
110044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
111044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
112044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
113044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix3x3 *m);
114044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
115044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
116044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
117044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix2x2 *m);
118044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
119044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
120044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Set the elements of a matrix from an array of floats.
121044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
1221bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * The array of floats should be in row-major order, i.e. the element a
1231bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * <em>row 0, column 0</em> should be first, followed by the element at
1241bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * <em>row 0, column 1</em>, etc.
1251bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
1261bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to set.
1271bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param v The array of values to set the matrix to. These arrays should be
1281bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * 4, 9, or 16 floats long, depending on the matrix size.
129044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
130044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const float *v);
131044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
132044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
133044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
134044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix3x3 *m, const float *v);
135044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
136044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
137044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
138044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix2x2 *m, const float *v);
139044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
1401bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Set the elements of a matrix from another matrix.
1411bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
1421bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * If the source matrix is smaller than the destination, the rest of the
1431bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * destination is filled with elements of the identity matrix.  E.g.
1441bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * loading a rs_matrix2x2 into a rs_matrix4x4 will give:
1451bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
1461bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * \htmlonly<table>
1471bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * <tr><td>m00</td><td>m01</td><td>0.0</td><td>0.0</td></tr>
1481bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * <tr><td>m10</td><td>m11</td><td>0.0</td><td>0.0</td></tr>
1491bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * <tr><td>0.0</td><td>0.0</td><td>1.0</td><td>0.0</td></tr>
1501bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * <tr><td>0.0</td><td>0.0</td><td>0.0</td><td>1.0</td></tr>
1511bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * </table>\endhtmlonly
1521bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
1531bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to set.
1541bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param v The source matrix.
155044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
156044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix4x4 *v);
157044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
158044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
159044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
160044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix3x3 *v);
161044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
1621bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * \overload
163044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
164044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix2x2 *v);
165044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
166044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
167044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
168044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix3x3 *m, const rs_matrix3x3 *v);
169044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
170044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
171044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
172044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix2x2 *m, const rs_matrix2x2 *v);
173044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
174044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
175044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Load a rotation matrix.
176044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
1771bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * This function creates a rotation matrix.  The axis of rotation is the
1781bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * <em>(x, y, z)</em> vector.
1791bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
1801bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * To rotate a vector, multiply the vector by the created matrix
1811bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * using \ref rsMatrixMultiply.
1821bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
1831bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * See http://en.wikipedia.org/wiki/Rotation_matrix .
1841bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
1851bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to set.
1861bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param rot How much rotation to do, in degrees.
1871bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param x The x component of the vector that is the axis of rotation.
1881bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param y The y component of the vector that is the axis of rotation.
1891bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param z The z component of the vector that is the axis of rotation.
190044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
191044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
192044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
193044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
194044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
195044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Load a scale matrix.
196044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
1971bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * This function creates a scaling matrix, where each component of a
1981bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * vector is multiplied by a number.  This number can be negative.
1991bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2001bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * To scale a vector, multiply the vector by the created matrix
2011bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * using \ref rsMatrixMultiply.
2021bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2031bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to set.
2041bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param x The multiple to scale the x components by.
2051bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param y The multiple to scale the y components by.
2061bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param z The multiple to scale the z components by.
207044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
208044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
209044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z);
210044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
211044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
212044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Load a translation matrix.
213044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
2141bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * This function creates a translation matrix, where a
2151bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * number is added to each element of a vector.
2161bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2171bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * To translate a vector, multiply the vector by the created matrix
2181bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * using \ref rsMatrixMultiply.
2191bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2201bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to set.
2211bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param x The number to add to each x component.
2221bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param y The number to add to each y component.
2231bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param z The number to add to each z component.
224044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
225044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
226044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z);
227044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
228044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
2291bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Multiply two matrices.
2301bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2311bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Sets \e m to the matrix product of <em>lhs * rhs</em>.
232044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
2331bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * To combine two 4x4 transformaton matrices, multiply the second transformation matrix
2341bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * by the first transformation matrix.  E.g. to create a transformation matrix that applies
2351bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * the transformation \e s1 followed by \e s2, call
2361bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * </c>rsMatrixLoadMultiply(&combined, &s2, &s1)</c>.
2371bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2381bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * \warning Prior to version 21, storing the result back into right matrix is not supported and
2391bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * will result in undefined behavior.  Use rsMatrixMulitply instead.   E.g. instead of doing
2401bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * rsMatrixLoadMultiply (&m2r, &m2r, &m2l), use rsMatrixMultiply (&m2r, &m2l).
2411bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * rsMatrixLoadMultiply (&m2l, &m2r, &m2l) works as expected.
2421bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2431bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to set.
2441bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param lhs The left matrix of the product.
2451bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param rhs The right matrix of the product.
246044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
247044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
248044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixLoadMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs);
249044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
250044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
251044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
252044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
253044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixLoadMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs);
254044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
255044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
256044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
257044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
258044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixLoadMultiply(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs);
259044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
260044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
2611bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Multiply a matrix into another one.
2621bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2631bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Sets \e m to the matrix product <em>m * rhs</em>.
264044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
2651bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * When combining two 4x4 transformation matrices using this function, the resulting
2661bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * matrix will correspond to performing the \e rhs transformation first followed by
2671bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * the original \e m transformation.
2681bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2691bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The left matrix of the product and the matrix to be set.
2701bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param rhs The right matrix of the product.
271044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
272044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
273044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *rhs);
274044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
275044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
276044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
277044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
278044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *rhs);
279044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
280044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
281044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
282044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
283044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(rs_matrix2x2 *m, const rs_matrix2x2 *rhs);
284044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
285044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
2861bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Multiply the matrix \e m with a rotation matrix.
2871bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2881bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * This function modifies a transformation matrix to first do a rotation.
2891bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * The axis of rotation is the <em>(x, y, z)</em> vector.
290044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
2911bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * To apply this combined transformation to a vector, multiply
2921bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * the vector by the created matrix using \ref rsMatrixMultiply.
2931bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
2941bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to modify.
2951bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param rot How much rotation to do, in degrees.
2961bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param x The x component of the vector that is the axis of rotation.
2971bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param y The y component of the vector that is the axis of rotation.
2981bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param z The z component of the vector that is the axis of rotation.
299044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
300044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
301044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
302044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
303044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
3041bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Multiply the matrix \e m with a scaling matrix.
3051bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3061bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * This function modifies a transformation matrix to first do a scaling.
3071bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * When scaling, each component of a vector is multiplied by a number.
3081bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * This number can be negative.
309044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
3101bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * To apply this combined transformation to a vector, multiply
3111bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * the vector by the created matrix using \ref rsMatrixMultiply.
3121bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3131bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to modify.
3141bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param x The multiple to scale the x components by.
3151bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param y The multiple to scale the y components by.
3161bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param z The multiple to scale the z components by.
317044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
318044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
319044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixScale(rs_matrix4x4 *m, float x, float y, float z);
320044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
321044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
3221bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Multiply the matrix \e m with a translation matrix.
3231bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3241bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * This function modifies a transformation matrix to first
3251bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * do a translation.  When translating, a number is added
3261bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * to each component of a vector.
3271bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3281bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * To apply this combined transformation to a vector, multiply
3291bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * the vector by the created matrix using \ref rsMatrixMultiply.
330044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
3311bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to modify.
3321bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param x The number to add to each x component.
3331bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param y The number to add to each y component.
3341bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param z The number to add to each z component.
335044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
336044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
337044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z);
338044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
339044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
3401bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Load an orthographic projection matrix.
341044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
3421bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Constructs an orthographic projection matrix, transforming the box
3431bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * identified by the six clipping planes <em>left, right, bottom, top,
3441bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * near, far</em> into a unit cube with a corner at
3451bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * <em>(-1, -1, -1)</em> and the opposite at <em>(1, 1, 1)</em>.
3461bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3471bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * To apply this projection to a vector, multiply the vector by the
3481bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * created matrix using \ref rsMatrixMultiply.
3491bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3501bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * See https://en.wikipedia.org/wiki/Orthographic_projection .
3511bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3521bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to set.
353044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param left
354044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param right
355044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param bottom
356044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param top
357044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param near
358044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param far
359044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
360044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
361044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far);
362044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
363044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
3641bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Load a frustum projection matrix.
3651bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3661bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Constructs a frustum projection matrix, transforming the box
3671bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * identified by the six clipping planes <em>left, right, bottom, top,
3681bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * near, far</em>.
369044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
3701bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * To apply this projection to a vector, multiply the vector by the
3711bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * created matrix using \ref rsMatrixMultiply.
3721bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3731bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to set.
374044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param left
375044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param right
376044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param bottom
377044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param top
378044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param near
379044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param far
380044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
381044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
382044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far);
383044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
384044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
3851bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Load a perspective projection matrix.
3861bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3871bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Constructs a perspective projection matrix, assuming a symmetrical field of view.
3881bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
3891bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * To apply this projection to a vector, multiply the vector by the
3901bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * created matrix using \ref rsMatrixMultiply.
391044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
3921bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to set.
393044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param fovy Field of view, in degrees along the Y axis.
394044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * @param aspect Ratio of x / y.
3951bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param near The near clipping plane.
3961bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param far The far clipping plane.
397044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
398044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable))
399044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
400044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
401044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams#if !defined(RS_VERSION) || (RS_VERSION < 14)
402044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
4031bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Multiply a vector by a matrix.
4041bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
4051bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Returns the post-multiplication of the vector by the matrix, ie. <em>m * in</em>.
4061bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
4071bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * When multiplying a \e float3 to a \e rs_matrix4x4, the vector is expanded with (1).
4081bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
4091bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * When multiplying a \e float2 to a \e rs_matrix4x4, the vector is expanded with (0, 1).
4101bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
4111bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * When multiplying a \e float2 to a \e rs_matrix3x3, the vector is expanded with (0).
4121bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
4131bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * This function is available in API version 10-13.  Starting with API 14,
4141bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * the function takes a const matrix as the first argument.
415044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
416044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float4 __attribute__((overloadable))
417044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(rs_matrix4x4 *m, float4 in);
418044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
419044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
420044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
421044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
422044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float4 __attribute__((overloadable))
423044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(rs_matrix4x4 *m, float3 in);
424044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
425044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
426044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
427044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
428044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float4 __attribute__((overloadable))
429044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(rs_matrix4x4 *m, float2 in);
430044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
431044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
432044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
433044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
434044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float3 __attribute__((overloadable))
435044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(rs_matrix3x3 *m, float3 in);
436044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
437044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
438044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
439044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
440044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float3 __attribute__((overloadable))
441044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(rs_matrix3x3 *m, float2 in);
442044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
443044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
444044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
445044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
446044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float2 __attribute__((overloadable))
447044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(rs_matrix2x2 *m, float2 in);
448044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams#else
449044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
4501bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Multiply a vector by a matrix.
4511bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
4521bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Returns the post-multiplication of the vector of the matrix, i.e. <em>m * in</em>.
4531bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
4541bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * When multiplying a \e float3 to a \e rs_matrix4x4, the vector is expanded with (1).
4551bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
4561bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * When multiplying a \e float2 to a \e rs_matrix4x4, the vector is expanded with (0, 1).
4571bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
4581bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * When multiplying a \e float2 to a \e rs_matrix3x3, the vector is expanded with (0).
4591bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
4601bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * This function is available starting with API version 14.
461044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
462044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float4 __attribute__((overloadable))
463044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(const rs_matrix4x4 *m, float4 in);
464044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
465044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
466044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
467044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
468044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float4 __attribute__((overloadable))
469044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(const rs_matrix4x4 *m, float3 in);
470044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
471044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
472044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
473044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
474044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float4 __attribute__((overloadable))
475044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(const rs_matrix4x4 *m, float2 in);
476044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
477044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
478044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
479044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
480044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float3 __attribute__((overloadable))
481044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(const rs_matrix3x3 *m, float3 in);
482044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
483044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
484044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
485044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
486044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float3 __attribute__((overloadable))
487044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(const rs_matrix3x3 *m, float2 in);
488044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
489044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
490044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
491044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
492044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams_RS_RUNTIME float2 __attribute__((overloadable))
493044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason SamsrsMatrixMultiply(const rs_matrix2x2 *m, float2 in);
494044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams#endif
495044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
496044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
497044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
4981bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Inverts a matrix in place.
4991bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
5001bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Returns true if the matrix was successfully inverted.
501044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
5021bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to invert.
503044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
504044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern bool __attribute__((overloadable)) rsMatrixInverse(rs_matrix4x4 *m);
505044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
506044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
5071bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Inverts and transpose a matrix in place.
5081bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet *
5091bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * The matrix is first inverted then transposed.
5101bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Returns true if the matrix was successfully inverted.
511044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
5121bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to modify.
513044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
514044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern bool __attribute__((overloadable)) rsMatrixInverseTranspose(rs_matrix4x4 *m);
515044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
516044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
5171bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * Transpose the matrix m in place.
518044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
5191bb2eed69caa28cf8198d58db7d9134cc2f563f5Jean-Luc Brouillet * @param m The matrix to transpose.
520044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
521044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix4x4 *m);
522044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
523044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
524044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
525044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix3x3 *m);
526044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/**
527044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * \overload
528044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
529044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Samsextern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix2x2 *m);
530044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
531044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
532044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams#endif
533