820dfbdc5d0d4a7254e8cd24f58298afff5af10c
[vrlugburz] / src / player.c
1 #include "player.h"
2
3 void init_player(struct player *p)
4 {
5         memset(p, 0, sizeof *p);
6         cgm_qcons(&p->vrot, 0, 0, 0, 1);
7
8         p->height = 1.75;
9         p->hp = p->hp_max = 10;
10         p->mp = p->mp_max = 10;
11 }
12
13 void upd_player_xform(struct player *p)
14 {
15         cgm_vec3 pos;
16         float celld = p->lvl ? p->lvl->cell_size : DEF_CELL_SIZE;
17
18         cgm_vcons(&pos, p->cx * celld, p->height, -p->cy * celld);
19         cgm_vadd(&pos, &p->cpos);
20
21         cgm_midentity(p->view_xform);
22         cgm_mprerotate_x(p->view_xform, -p->phi);
23         cgm_mprerotate_y(p->view_xform, -p->theta);
24         cgm_mrotate_quat(p->view_xform, &p->vrot);
25         cgm_mpretranslate(p->view_xform, -pos.x, -pos.y, -pos.z);
26 }