hal_gfx_matrix4x4.h
Go to the documentation of this file.
1 
2 /** @addtogroup GRAPHICS_SDK Graphics
3  * @{
4  */
5 
6 /** @defgroup HAL_GFX_MATRIX4X4 Hal gfx matrix4x4
7  * @brief Base matrix4x4 Operation.
8  * @{
9  */
10 
11 
12 #ifndef HAL_GFX_MATRIX4X4_H__
13 #define HAL_GFX_MATRIX4X4_H__
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 /**
19  * @defgroup HAL_GFX_MATRIX4X4_TYPEDEF Typedefs
20  * @{
21  */
22 typedef float hal_gfx_matrix4x4_t[4][4];/**< Global define matrix4x4 variable. */
23 /** @} */
24 
25 /**
26  * @defgroup HAL_GFX_MATRIX4X4_FUNCTION Functions
27  * @{
28  */
29 /**
30  *****************************************************************************************
31  * @brief Load a 4x4 Identity Matrix
32  *
33  * @param[in] m: Matrix to be loaded
34  *
35  *****************************************************************************************
36  */
38 
39 /**
40  *****************************************************************************************
41  * @brief Multiply two 4x4 matrices
42  *
43  * @param[in] m: Result Matrix
44  * @param[in] m_l: Left operand
45  * @param[in] m_r: Right operand
46  *
47  *****************************************************************************************
48  */
52 
53 /**
54  *****************************************************************************************
55  * @brief Multiply a 4x1 vector with a 4x4 matrix
56  *
57  * @param[in] m: Matrix to be multiplied
58  * @param[in] x: Vector first element
59  * @param[in] y: Vector second element
60  * @param[in] z: Vector third element
61  * @param[in] w: Vector forth element
62  *
63  *****************************************************************************************
64  */
65 void hal_gfx_mat4x4_mul_vec(hal_gfx_matrix4x4_t m, float *x, float *y, float *z, float *w);
66 
67 // ------------------------------------------------------------------------------------
68 // Object Transformation - ModelView Matrix
69 // Object Coordinates to Eye Coordinates
70 // ------------------------------------------------------------------------------------
71 /**
72  *****************************************************************************************
73  * @brief Apply translate transformation
74  *
75  * @param[in] m: Matrix to apply transformation
76  * @param[in] tx: X translation factor
77  * @param[in] ty: Y translation factor
78  * @param[in] tz: Z translation factor
79  *
80  *****************************************************************************************
81  */
82 void hal_gfx_mat4x4_translate(hal_gfx_matrix4x4_t m, float tx, float ty, float tz);
83 
84 /**
85  *****************************************************************************************
86  * @brief Apply scale transformation
87  *
88  * @param[in] m: Matrix to apply transformation
89  * @param[in] sx: X scaling factor
90  * @param[in] sy: Y scaling factor
91  * @param[in] sz: Z scaling factor
92  *
93  *****************************************************************************************
94  */
95 void hal_gfx_mat4x4_scale(hal_gfx_matrix4x4_t m, float sx, float sy, float sz);
96 
97 /**
98  *****************************************************************************************
99  * @brief Apply rotate transformation around X axis
100  *
101  * @param[in] m: Matrix to apply transformation
102  * @param[in] angle_degrees: Angle to rotate in degrees
103  *
104  *****************************************************************************************
105  */
106 void hal_gfx_mat4x4_rotate_X (hal_gfx_matrix4x4_t m, float angle_degrees);
107 
108 /**
109  *****************************************************************************************
110  * @brief Apply rotate transformation around Y axis
111  *
112  * @param[in] m: Matrix to apply transformation
113  * @param[in] angle_degrees: Angle to rotate in degrees
114  *
115  *****************************************************************************************
116  */
117 void hal_gfx_mat4x4_rotate_Y (hal_gfx_matrix4x4_t m, float angle_degrees);
118 
119 /**
120  *****************************************************************************************
121  * @brief Apply rotate transformation around Z axis
122  *
123  * @param[in] m: Matrix to apply transformation
124  * @param[in] angle_degrees: Angle to rotate in degrees
125  *
126  *****************************************************************************************
127  */
128 void hal_gfx_mat4x4_rotate_Z (hal_gfx_matrix4x4_t m, float angle_degrees);
129 
130 // ------------------------------------------------------------------------------------
131 // Scene Transformation/Frustum - Projection Matrix
132 // Eye Coordinates to Clip Coordinates
133 // ------------------------------------------------------------------------------------
134 /**
135  *****************************************************************************************
136  * @brief Set up a perspective projection matrix
137  *
138  * @param[in] m: A 4x4 Matrix
139  * @param[in] fovy_degrees: Field of View in degrees
140  * @param[in] aspect: Aspect ratio that determines the field of view in the x direction.
141  * @param[in] nearVal: Distance from the viewer to the near clipping plane (always positive)
142  * @param[in] farVal: Distance from the viewer to the far clipping plane (always positive)
143  *
144  *****************************************************************************************
145  */
146 void hal_gfx_mat4x4_load_perspective(hal_gfx_matrix4x4_t m, float fovy_degrees, float aspect,
147  float nearVal, float farVal);
148 
149 /**
150  *****************************************************************************************
151  * @brief Set up an orthographic projection matrix
152  *
153  * @param[in] m: A 4x4 Matrix
154  * @param[in] left: Left vertical clipping plane
155  * @param[in] right: Right vertical clipping plane
156  * @param[in] bottom: bottom horizontal clipping plane
157  * @param[in] top: Top horizontal clipping plane
158  * @param[in] nearVal: Distance from the viewer to the near clipping plane (always positive)
159  * @param[in] farVal: Distance from the viewer to the far clipping plane (always positive)
160  *
161  *****************************************************************************************
162  */
164  float left, float right,
165  float bottom, float top,
166  float nearVal, float farVal);
167 
168 /**
169  *****************************************************************************************
170  * @brief Set up a 2D orthographic projection matrix
171  *
172  * @param[in] m: A 4x4 Matrix
173  * @param[in] left: Left vertical clipping plane
174  * @param[in] right: Right vertical clipping plane
175  * @param[in] bottom: bottom horizontal clipping plane
176  * @param[in] top: Top horizontal clipping plane
177  *
178  *****************************************************************************************
179  */
181  float left, float right,
182  float bottom, float top);
183 
184 // ------------------------------------------------------------------------------------
185 // Clip Coordinates to Window Coordinates
186 // ------------------------------------------------------------------------------------
187 /**
188  *****************************************************************************************
189  * @brief Convenience Function to calculate window coordinates from object coordinates
190  *
191  * @param[in] mvp: Model, View and Projection Matrix
192  * @param[in] x_orig: Window top left X coordinate
193  * @param[in] y_orig: Window top left Y coordinate
194  * @param[in] width: Window width
195  * @param[in] height: Window height
196  * @param[in] nearVal: Distance from the viewer to the near clipping plane (always positive)
197  * @param[in] farVal: Distance from the viewer to the far clipping plane (always positive)
198  * @param[in] x: X object coordinate
199  * @param[in] y: Y object coordinate
200  * @param[in] z: Z object coordinate
201  * @param[in] w: W object coordinate
202 
203  * @return 1 if vertex is outside frustum (should be clipped)
204  *****************************************************************************************
205  */
207  float x_orig, float y_orig,
208  int width, int height,
209  float nearVal, float farVal,
210  float *x,
211  float *y,
212  float *z,
213  float *w);
214 /** @} */
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif
221 /** @} */
222 /** @} */
223 
hal_gfx_mat4x4_rotate_X
void hal_gfx_mat4x4_rotate_X(hal_gfx_matrix4x4_t m, float angle_degrees)
Apply rotate transformation around X axis.
hal_gfx_mat4x4_translate
void hal_gfx_mat4x4_translate(hal_gfx_matrix4x4_t m, float tx, float ty, float tz)
Apply translate transformation.
hal_gfx_mat4x4_load_perspective
void hal_gfx_mat4x4_load_perspective(hal_gfx_matrix4x4_t m, float fovy_degrees, float aspect, float nearVal, float farVal)
Set up a perspective projection matrix.
hal_gfx_mat4x4_load_ortho
void hal_gfx_mat4x4_load_ortho(hal_gfx_matrix4x4_t m, float left, float right, float bottom, float top, float nearVal, float farVal)
Set up an orthographic projection matrix.
hal_gfx_matrix4x4_t
float hal_gfx_matrix4x4_t[4][4]
Definition: hal_gfx_matrix4x4.h:22
hal_gfx_mat4x4_mul_vec
void hal_gfx_mat4x4_mul_vec(hal_gfx_matrix4x4_t m, float *x, float *y, float *z, float *w)
Multiply a 4x1 vector with a 4x4 matrix.
hal_gfx_mat4x4_rotate_Y
void hal_gfx_mat4x4_rotate_Y(hal_gfx_matrix4x4_t m, float angle_degrees)
Apply rotate transformation around Y axis.
hal_gfx_mat4x4_mul
void hal_gfx_mat4x4_mul(hal_gfx_matrix4x4_t m, hal_gfx_matrix4x4_t m_l, hal_gfx_matrix4x4_t m_r)
Multiply two 4x4 matrices.
hal_gfx_mat4x4_rotate_Z
void hal_gfx_mat4x4_rotate_Z(hal_gfx_matrix4x4_t m, float angle_degrees)
Apply rotate transformation around Z axis.
hal_gfx_mat4x4_scale
void hal_gfx_mat4x4_scale(hal_gfx_matrix4x4_t m, float sx, float sy, float sz)
Apply scale transformation.
hal_gfx_mat4x4_obj_to_win_coords
int hal_gfx_mat4x4_obj_to_win_coords(hal_gfx_matrix4x4_t mvp, float x_orig, float y_orig, int width, int height, float nearVal, float farVal, float *x, float *y, float *z, float *w)
Convenience Function to calculate window coordinates from object coordinates.
hal_gfx_mat4x4_load_ortho_2d
void hal_gfx_mat4x4_load_ortho_2d(hal_gfx_matrix4x4_t m, float left, float right, float bottom, float top)
Set up a 2D orthographic projection matrix.
hal_gfx_mat4x4_load_identity
void hal_gfx_mat4x4_load_identity(hal_gfx_matrix4x4_t m)
Load a 4x4 Identity Matrix.