manque even, mlx fonction et definition map
This commit is contained in:
parent
f7f92cbaa8
commit
bdd7e86f3c
2 changed files with 125 additions and 67 deletions
63
algo.c
63
algo.c
|
@ -6,7 +6,7 @@
|
|||
/* By: greg <greg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */
|
||||
/* Updated: 2024/10/03 17:42:13 by greg ### ########.fr */
|
||||
/* Updated: 2024/10/03 18:59:06 by greg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -23,6 +23,8 @@ static int initalgo(t_ray *ray)
|
|||
ray->planeY = 0.66; // FOV de 66 degres
|
||||
ray->currtime = 0;
|
||||
ray->oldtime = 0;
|
||||
ray->movespeed = 0.1;
|
||||
ray->rotspeed = 0.1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -47,7 +49,7 @@ int algo()
|
|||
x = 0;
|
||||
width = 640;
|
||||
height = 480;
|
||||
while (x < w)
|
||||
while (x < width)
|
||||
{
|
||||
// position et direction du rayon
|
||||
ray.cameraX = 2 * x / width - 1;
|
||||
|
@ -119,6 +121,63 @@ int algo()
|
|||
if(drawEnd >= height)
|
||||
drawEnd = height - 1;
|
||||
|
||||
/*mlx fontction color
|
||||
|
||||
give x and y sides different brightness
|
||||
if (side == 1) {color = color / 2;}
|
||||
|
||||
//draw the pixels of the stripe as a vertical line
|
||||
verLine(x, drawStart, drawEnd, color); */
|
||||
|
||||
|
||||
//timing for input to dissociate speed from speed processor (same speed on all pc)
|
||||
ray.oldtime = ray.currtime;
|
||||
ray.currtime = getTicks();
|
||||
// put image to window
|
||||
// destroy old image
|
||||
|
||||
|
||||
// hook event
|
||||
|
||||
readKeys();
|
||||
//move forward if no wall in front of you
|
||||
if (keyDown(move_up))
|
||||
{
|
||||
if(worldMap[(ray.posX + ray.dirX * ray.movespeed)][(int)(ray.posY)] == 0)
|
||||
ray.posX += ray.dirX * ray.movespeed;
|
||||
if(worldMap[(ray.posX)][((int)ray.posY + (int)ray.dirY * (int)ray.movespeed)] == 0)
|
||||
ray.posY += ray.dirY * ray.movespeed;
|
||||
}
|
||||
//move backwards if no wall behind you
|
||||
if (keyDown(moove_down))
|
||||
{
|
||||
if(worldMap[(ray.posX - ray.dirX * ray.movespeed)][(int)(ray.posY)] == 0)
|
||||
ray.posX -= ray.dirX * ray.movespeed;
|
||||
if(worldMap[(ray.posX)][((int)ray.posY - (int)ray.dirY * (int)ray.movespeed)] == 0)
|
||||
ray.posY -= ray.dirY * ray.movespeed;
|
||||
}
|
||||
//rotate to the right
|
||||
if (keyDown(moove_right))
|
||||
{
|
||||
//both camera direction and camera plane must be rotated
|
||||
ray.oldDirX = ray.dirX;
|
||||
ray.dirX = ray.dirX * cos(-ray.rotspeed) - ray.dirY * sin(-ray.rotspeed);
|
||||
ray.dirY = ray.oldDirX * sin(-ray.rotspeed) + ray.dirY * cos(-ray.rotspeed);
|
||||
ray.oldPlaneX = ray.planeX;
|
||||
ray.planeX = ray.planeX * cos(-ray.rotspeed) - ray.planeY * sin(-ray.rotspeed);
|
||||
ray.planeY = ray.oldPlaneX * sin(-ray.rotspeed) + ray.planeY * cos(-ray.rotspeed);
|
||||
}
|
||||
//rotate to the left
|
||||
if (keyDown(moove_left))
|
||||
{
|
||||
//both camera direction and camera plane must be rotated
|
||||
ray.oldDirX = ray.dirX;
|
||||
ray.dirX = ray.dirX * cos(ray.rotspeed) - ray.dirY * sin(ray.rotspeed);
|
||||
ray.dirY = ray.oldDirX * sin(ray.rotspeed) + ray.dirY * cos(ray.rotspeed);
|
||||
ray.oldPlaneX = ray.planeX;
|
||||
ray.planeX = ray.planeX * cos(ray.rotspeed) - ray.planeY * sin(ray.rotspeed);
|
||||
ray.planeY = ray.oldPlaneX * sin(ray.rotspeed) + ray.planeY * cos(ray.rotspeed);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
|
||||
|
|
11
algo.h
11
algo.h
|
@ -6,7 +6,7 @@
|
|||
/* By: greg <greg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */
|
||||
/* Updated: 2024/10/03 17:26:27 by greg ### ########.fr */
|
||||
/* Updated: 2024/10/03 18:59:43 by greg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -27,10 +27,6 @@ typedef struct s_ray
|
|||
// orientation cam on map
|
||||
double planeX;
|
||||
double planeY;
|
||||
// current frame
|
||||
double currtime;
|
||||
// last frame
|
||||
double oldtime;
|
||||
// camera pos
|
||||
double cameraX;
|
||||
// direction rayon
|
||||
|
@ -47,7 +43,10 @@ typedef struct s_ray
|
|||
// step direction (can be -1 or +1)
|
||||
int stepX;
|
||||
int stepY;
|
||||
//wall hit?
|
||||
double movespeed;
|
||||
double rotspeed;
|
||||
double oldDirX;
|
||||
double oldPlaneX;
|
||||
} t_ray;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue