-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode7.h
86 lines (67 loc) · 2.04 KB
/
mode7.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef MAIN_H_
#define MAIN_H_
#include <tonc.h>
/* mode 7 constants */
#define PIX_PER_BLOCK 16
#define M7_OBJ_COUNT 32
#define M7_D 160 /* focal length */
#define M7_D_SHIFT 8 /* focal shift */
#define M7_RENORM_SHIFT 2 /* renormalization shift */
#define M7_LEFT (-120) /* viewport left */
#define M7_RIGHT 120 /* viewport right */
#define M7_TOP 80 /* viewport top */
#define M7_BOTTOM (-80) /* viewport bottom */
#define M7_NEAR 24 /* near plane for objects */
#define M7_FAR_OBJ 512 /* far plane for objects */
#define M7_FAR_BG 768 /* far plane for floor */
/* mode 7 types */
typedef struct _m7_cam_t {
VECTOR pos;
int theta; /* polar angle */
int phi; /* azimuth angle */
VECTOR u; /* local x-axis */
VECTOR v; /* local y-axis */
VECTOR w; /* local z-axis */
FIXED fov;
} m7_cam_t;
typedef struct _m7_level_t {
m7_cam_t *camera;
u16 *winh; /* window 0 widths */
BG_AFFINE *bgaff; /* affine parameter array */
u16 bgcnt; /* BGxCNT for floor */
const int *blocks;
int blocks_width, blocks_height;
FIXED pixels_per_block, a_x_range;
int texture_width, texture_height;
const FIXED *extent_widths, *extent_offs;
} m7_level_t;
typedef struct _m7_obj_t {
VECTOR pos;
POINT anchor;
OBJ_ATTR obj;
s16 phi;
u8 obj_id;
u8 aff_id;
TILE *tiles;
} m7_obj_t;
typedef struct {
FIXED inv_fov;
FIXED inv_fov_x_ppb;
FIXED x_cs[SCREEN_HEIGHT];
} m7_precompute;
/* accessible both from main and iwram */
extern m7_obj_t m7_obj_arr[M7_OBJ_COUNT];
extern m7_level_t floor_level, wall_level;
extern m7_precompute pre;
/* level functions */
void m7_init(m7_level_t *level, m7_cam_t *cam, BG_AFFINE bgaff[], u16 *winh_arr, u16 bgcnt, int bgno);
/* camera functions */
void m7_rotate(m7_cam_t *cam, int theta);
void m7_translate_local(m7_level_t *level, const VECTOR *dir);
void m7_translate_level(m7_level_t *level, const VECTOR *dir);
/* object functions */
void m7_update_objects(const m7_level_t * level);
/* iwram code */
IWRAM_CODE void m7_prep_affines(m7_level_t *level_2, m7_level_t *level_3);
IWRAM_CODE void m7_hbl();
#endif