PS2SDK
PS2 Homebrew Libraries
math3d.h
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # (c) 2005 Naomi Peori <naomi@peori.ca>
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 #ifndef __MATH3D_H__
17 #define __MATH3D_H__
18 
19 #include <tamtypes.h>
20 
21 typedef float VECTOR[4] __attribute__((__aligned__(16)));
22 
23 typedef float MATRIX[16] __attribute__((__aligned__(16)));
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /* VECTOR FUNCTIONS */
31 extern void vector_apply(VECTOR output, VECTOR input0, MATRIX input1);
32 
34 extern void vector_clamp(VECTOR output, VECTOR input0, float min, float max);
35 
37 extern void vector_copy(VECTOR output, VECTOR input0);
38 
40 extern float vector_innerproduct(VECTOR input0, VECTOR input1);
41 
43 extern void vector_multiply(VECTOR output, VECTOR input0, VECTOR input1);
44 
46 extern void vector_normalize(VECTOR output, VECTOR input0);
47 
49 extern void vector_outerproduct(VECTOR output, VECTOR input0, VECTOR input1);
50 
52 extern void vector_add(VECTOR sum, VECTOR addend, VECTOR summand);
53 
55 extern void vector_cross_product(VECTOR product, VECTOR multiplicand, VECTOR multiplier);
56 
58 extern void vector_triangle_normal(VECTOR output, VECTOR a, VECTOR b, VECTOR c);
59 
60 /* MATRIX FUNCTIONS */
62 extern void matrix_copy(MATRIX output, MATRIX input0);
63 
65 extern void matrix_inverse(MATRIX output, MATRIX input0);
66 
68 extern void matrix_multiply(MATRIX output, MATRIX input0, MATRIX input1);
69 
71 extern void matrix_rotate(MATRIX output, MATRIX input0, VECTOR input1);
72 
74 extern void matrix_scale(MATRIX output, MATRIX input0, VECTOR input1);
75 
77 extern void matrix_translate(MATRIX output, MATRIX input0, VECTOR input1);
78 
80 extern void matrix_transpose(MATRIX output, MATRIX input0);
81 
83 extern void matrix_unit(MATRIX output);
84 
85 /* CREATE FUNCTIONS */
86 
90 extern void create_local_world(MATRIX local_world, VECTOR translation, VECTOR rotation);
91 
95 extern void create_local_light(MATRIX local_light, VECTOR rotation);
96 
100 extern void create_world_view(MATRIX world_view, VECTOR translation, VECTOR rotation);
101 
105 extern void create_view_screen(MATRIX view_screen, float aspect, float left, float right, float bottom, float top, float near, float far);
106 
110 extern void create_local_screen(MATRIX local_screen, MATRIX local_world, MATRIX world_view, MATRIX view_screen);
111 
112 /* CALCULATE FUNCTIONS */
113 
115 #define LIGHT_AMBIENT 0
116 
117 #define LIGHT_DIRECTIONAL 1
118 
120 extern void calculate_normals(VECTOR *output, int count, VECTOR *normals, MATRIX local_light);
121 
123 extern void calculate_lights(VECTOR *output, int count, VECTOR *normals, VECTOR *light_directions, VECTOR *light_colours, const int *light_types, int light_count);
124 
126 extern void calculate_colours(VECTOR *output, int count, VECTOR *colours, VECTOR *lights);
127 
129 extern void calculate_vertices(VECTOR *output, int count, VECTOR *vertices, MATRIX local_screen);
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif /* __MATH3D_H__ */
vector_normalize
void vector_normalize(VECTOR output, VECTOR input0)
Definition: math3d.c:121
calculate_colours
void calculate_colours(VECTOR *output, int count, VECTOR *colours, VECTOR *lights)
Definition: math3d.c:571
create_local_screen
void create_local_screen(MATRIX local_screen, MATRIX local_world, MATRIX world_view, MATRIX view_screen)
Definition: math3d.c:466
calculate_vertices
void calculate_vertices(VECTOR *output, int count, VECTOR *vertices, MATRIX local_screen)
Definition: math3d.c:589
matrix_translate
void matrix_translate(MATRIX output, MATRIX input0, VECTOR input1)
Definition: math3d.c:358
vector_clamp
void vector_clamp(VECTOR output, VECTOR input0, float min, float max)
Definition: math3d.c:50
vector_apply
void vector_apply(VECTOR output, VECTOR input0, MATRIX input1)
Definition: math3d.c:20
vector_outerproduct
void vector_outerproduct(VECTOR output, VECTOR input0, VECTOR input1)
Definition: math3d.c:151
calculate_lights
void calculate_lights(VECTOR *output, int count, VECTOR *normals, VECTOR *light_directions, VECTOR *light_colours, const int *light_types, int light_count)
Definition: math3d.c:524
vector_multiply
void vector_multiply(VECTOR output, VECTOR input0, VECTOR input1)
Definition: math3d.c:107
matrix_rotate
void matrix_rotate(MATRIX output, MATRIX input0, VECTOR input1)
Definition: math3d.c:317
count
u32 count
start sector of fragmented bd/file
Definition: usbhdfsd-common.h:3
create_local_light
void create_local_light(MATRIX local_light, VECTOR rotation)
Definition: math3d.c:418
matrix_copy
void matrix_copy(MATRIX output, MATRIX input0)
Definition: math3d.c:207
vector_triangle_normal
void vector_triangle_normal(VECTOR output, VECTOR a, VECTOR b, VECTOR c)
Definition: math3d.c:191
vector_innerproduct
float vector_innerproduct(VECTOR input0, VECTOR input1)
Definition: math3d.c:87
tamtypes.h
matrix_inverse
void matrix_inverse(MATRIX output, MATRIX input0)
Definition: math3d.c:233
calculate_normals
void calculate_normals(VECTOR *output, int count, VECTOR *normals, MATRIX local_light)
Definition: math3d.c:478
matrix_unit
void matrix_unit(MATRIX output)
Definition: math3d.c:396
matrix_multiply
void matrix_multiply(MATRIX output, MATRIX input0, MATRIX input1)
Definition: math3d.c:251
__attribute__
Definition: gif_registers.h:38
vector_copy
void vector_copy(VECTOR output, VECTOR input0)
Definition: math3d.c:73
create_view_screen
void create_view_screen(MATRIX view_screen, float aspect, float left, float right, float bottom, float top, float near, float far)
Definition: math3d.c:448
matrix_scale
void matrix_scale(MATRIX output, MATRIX input0, VECTOR input1)
Definition: math3d.c:346
vector_cross_product
void vector_cross_product(VECTOR product, VECTOR multiplicand, VECTOR multiplier)
Definition: math3d.c:182
create_local_world
void create_local_world(MATRIX local_world, VECTOR translation, VECTOR rotation)
Definition: math3d.c:409
create_world_view
void create_world_view(MATRIX world_view, VECTOR translation, VECTOR rotation)
Definition: math3d.c:426
vector_add
void vector_add(VECTOR sum, VECTOR addend, VECTOR summand)
Definition: math3d.c:173
matrix_transpose
void matrix_transpose(MATRIX output, MATRIX input0)
Definition: math3d.c:370