better struct and files organization, and still only half raycast on map but no view created
This commit is contained in:
@@ -1,35 +1,75 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
void plr_turn_left(t_game *game)
|
||||
void rotate(t_plr *plr, t_coord *coord)
|
||||
{
|
||||
int old_x;
|
||||
t_coord tmp;
|
||||
|
||||
// do nothing if not rotating
|
||||
if (plr->rot == 0)
|
||||
return ;
|
||||
// offset center
|
||||
tmp.x = coord->x - plr->pos.x;
|
||||
tmp.y = coord->y - plr->pos.y;
|
||||
// calculate new coordinates
|
||||
old_x = tmp.x;
|
||||
tmp.x = tmp.x * plr->cosi + tmp.y * plr->cosj;
|
||||
tmp.y = old_x * plr->sini + tmp.y * plr->sinj;
|
||||
// de-offset center
|
||||
coord->x = tmp.x + plr->pos.x;
|
||||
coord->y = tmp.y + plr->pos.y;
|
||||
}
|
||||
|
||||
void rotate_double(t_plr *plr, t_d_coord *coord)
|
||||
{
|
||||
double old_x;
|
||||
t_d_coord tmp;
|
||||
|
||||
// do nothing if not rotating
|
||||
if (plr->rot == 0)
|
||||
return ;
|
||||
// offset center
|
||||
tmp.x = coord->x - plr->exact.x;
|
||||
tmp.y = coord->y - plr->exact.y;
|
||||
// calculate new coordinates
|
||||
old_x = tmp.x;
|
||||
tmp.x = tmp.x * plr->cosi + tmp.y * plr->cosj;
|
||||
tmp.y = old_x * plr->sini + tmp.y * plr->sinj;
|
||||
// de-offset center
|
||||
coord->x = tmp.x + plr->exact.x;
|
||||
coord->y = tmp.y + plr->exact.y;
|
||||
}
|
||||
|
||||
void plr_turn_left(t_plr *plr)
|
||||
{
|
||||
double radi;
|
||||
double radj;
|
||||
|
||||
if (game->rot == -180)
|
||||
(game->rot) *= -1;
|
||||
(game->rot)--;
|
||||
if (plr->rot == -180)
|
||||
(plr->rot) *= -1;
|
||||
(plr->rot)--;
|
||||
// calculate trigo for rotations
|
||||
radi = game->rot * M_PI / 180;
|
||||
radi = plr->rot * M_PI / 180;
|
||||
radj = radi + (M_PI / 2);
|
||||
game->cosi = cos(radi);
|
||||
game->sini = sin(radi);
|
||||
game->cosj = cos(radj);
|
||||
game->sinj = sin(radj);
|
||||
plr->cosi = cos(radi);
|
||||
plr->sini = sin(radi);
|
||||
plr->cosj = cos(radj);
|
||||
plr->sinj = sin(radj);
|
||||
}
|
||||
|
||||
void plr_turn_right(t_game *game)
|
||||
void plr_turn_right(t_plr *plr)
|
||||
{
|
||||
double radi;
|
||||
double radj;
|
||||
|
||||
if (game->rot == 180)
|
||||
(game->rot) *= -1;
|
||||
(game->rot)++;
|
||||
if (plr->rot == 180)
|
||||
(plr->rot) *= -1;
|
||||
(plr->rot)++;
|
||||
// calculate trigo for rotations
|
||||
radi = game->rot * M_PI / 180;
|
||||
radi = plr->rot * M_PI / 180;
|
||||
radj = radi + (M_PI / 2);
|
||||
game->cosi = cos(radi);
|
||||
game->sini = sin(radi);
|
||||
game->cosj = cos(radj);
|
||||
game->sinj = sin(radj);
|
||||
plr->cosi = cos(radi);
|
||||
plr->sini = sin(radi);
|
||||
plr->cosj = cos(radj);
|
||||
plr->sinj = sin(radj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user