source: NonGTP/FCollada/FMath/FMMatrix33.h @ 964

Revision 964, 4.4 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*
2        Copyright (C) 2005-2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5
6/**
7        @file FMMatrix33.h
8        The file containing the class and global functions for 3x3 matrices.
9*/
10
11#ifndef _FM_MATRIX33_H_
12#define _FM_MATRIX33_H_
13
14/**
15        A 3x3 matrix: use to represent 2D transformations.
16        Not used within FCollada.
17       
18        @ingroup FMath
19*/
20class FCOLLADA_EXPORT FMMatrix33
21{
22public:
23        float m[3][3];  /**< The matrix elements stored in a 2D array. */
24
25        /**
26         * Creates a FMMatrix33 from the \c float array.
27         *
28         * The float array stores the elements in the following order: m[0][0],
29         * m[1][0], m[2][0], m[0][1], m[1][1], m[2][1], m[0][2], m[1][2], m[2][2].
30         *
31         * @param _m The \c float array to create the matrix from.
32         */
33        FMMatrix33(float* _m);
34       
35        /**
36         * Creates an empty FMMatrix33.
37         *
38         * The default values are non deterministic.
39         */
40        #ifndef _DEBUG
41        FMMatrix33() {}
42        #else
43        FMMatrix33() { memset(m, 55, 3 * 3 * sizeof(float)); }
44        #endif
45
46        /**
47         * Get this FMMatrix33 as an array of \c floats.
48         *
49         * The array contains the elements in the following order: m[0][0],
50         * m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2].
51         *
52         * @return The \c float array.
53         */
54        operator float*() { return &m[0][0]; }
55
56        /**
57         * Get this FMMatrix as an array of \c floats.
58         *
59         * The array contains the elements in the following order: m[0][0],
60         * m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2].
61         *
62         * @return The \c float array.
63         */
64        operator const float*() const { return &m[0][0]; }
65
66        /**
67         * Get a specified row of FMMatrix33 as an array of \c floats.
68         *
69         * @param a The row index, starting at 0, of the row to get.
70         * @return The \c float array of the elements in the specified row.
71         */
72        float* operator[](int a) { return m[a]; }
73
74        /**
75         * Assign this FMMatrix33's elements to be the same as that of the given
76         * FMMatrix33.
77         *
78         * @param copy The FMMatrix to copy elements from.
79         * @return This FMMatrix.
80         */
81        FMMatrix33& operator=(const FMMatrix33& copy);
82
83        /**
84         * Gets the transposed of this FMMatrix33.
85         *
86         * @return The transposed of this FMMatrix.
87         */
88        FMMatrix33 Transposed() const;
89
90        /**
91         * Gets the inversion of this FMMatrix33.
92         *
93         * @return The inversion of this FMMatrix.
94         */
95        FMMatrix33 Inverted() const;
96
97public:
98        static FMMatrix33 identity;     /**< The identity FMMatrix33. */
99
100        /**
101         * Gets the FMMatrix33 representation of a 2D counter-clockwise rotation
102         * about the z-axis.
103         *
104         * @param angle The angle of rotation in radians.
105         * @return The rotation FMMatrix.
106         */
107        static FMMatrix33 RotationMatrix(float angle);
108
109        /**
110         * Gets the FMMatrix33 representation of a 2D translation.
111         *
112         * @param tx The translation in the x direction.
113         * @param ty The translation in the y direction.
114         * @return The translation FMMatrix.
115         */
116        static FMMatrix33 TranslationMatrix(float tx, float ty);
117       
118        /**
119         * Gets the FMMatrix33 representation of a 2D scale.
120         *
121         * @param sx The scale factor in the x direction.
122         * @param sy The scale factor in the y direction.
123         * @return The scale FMMatrix.
124         */
125        static FMMatrix33 ScaleMatrix(float sx, float sy);
126
127        /**
128         * Gets the FMMatrix33 representation of a 2D translation.
129         *
130         * The translation in the x direction is the \a u componenet of the given
131         * FMVector2 and the translation in the y direction is the \a v component.
132         *
133         * @param translation The FMVector2 to get the translation components from.
134         * @return The translation FMMatrix33.
135         */
136        static inline FMMatrix33 TranslationMatrix(FMVector2 translation) { return TranslationMatrix(translation.u, translation.v); }
137
138        /**
139         * Gets the FMMatrix33 representation of a 2D scale.
140         *
141         * The scale in the x direction is the \a u componenet of the given
142         * FMVector and the scale in the y direction is the \a v component.
143         *
144         * @param scale The FMVector2 to get the scale components from.
145         * @return The scale FMMatrix33.
146         */
147        static inline FMMatrix33 ScaleMatrix(FMVector2 scale) { return ScaleMatrix(scale.u, scale.v); }
148};
149
150/**
151 * Matrix multiplication with two FMMatrix33.
152 *
153 * @param m1 The first matrix.
154 * @param m2 The second matrix.
155 * @return The FMMatrix44 representation of the resulting matrix.
156 */
157FMMatrix33 FCOLLADA_EXPORT operator*(const FMMatrix33& m1, const FMMatrix33& m2);
158
159#endif // _FM_MATRIX33_H_
Note: See TracBrowser for help on using the repository browser.