feat: adding the full screen support (hard-coded)

This commit is contained in:
Raphael 2024-11-27 19:53:13 +01:00
parent 2faabaa713
commit f100ccef11
3 changed files with 21 additions and 19 deletions

View file

@ -6,7 +6,7 @@
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2024/11/26 14:41:12 by rparodi ### ########.fr #
# Updated: 2024/11/27 19:51:13 by rparodi ### ########.fr #
# #
# **************************************************************************** #
@ -33,16 +33,16 @@ INCLUDES = -I /usr/include -I ./includes -I ./includes/include -I ./minilibx-lin
MLX_DIR = ./minilibx-linux
# Library flags
LDFLAGS = -L./build -lm
LDFLAGS = -L./build -lmlx -lm
# MiniLibX flags for macOS with XQuartz
MLXFLAGS = -L$(MLX_DIR) -lmlx -lX11 -lXext
MLXFLAGS = -L$(MLX_DIR) -lX11 -lXext
#MLXFLAGS += -L/opt/X11/lib
# Add MLXFLAGS to the linker flags
LDFLAGS += $(MLXFLAGS)
SRC = test2.c
SRC = test.c
# Objects
OBJDIRNAME = ./build

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/27 12:07:20 by rparodi #+# #+# */
/* Updated: 2024/11/27 12:08:19 by rparodi ### ########.fr */
/* Updated: 2024/11/27 19:29:06 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,8 +18,8 @@
# include <stdio.h>
# include <stdlib.h>
# define WINDOW_WIDTH 1024
# define WINDOW_HEIGHT 768
# define WINDOW_WIDTH 1920
# define WINDOW_HEIGHT 1080
# define MAP_WIDTH 24
# define MAP_HEIGHT 24
# define MOVE_SPEED 0.5
@ -40,6 +40,8 @@ typedef struct s_data
double dir_y;
double plane_x;
double plane_y;
int screen_x;
int screen_y;
} t_data;
#endif

View file

@ -6,11 +6,10 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/27 12:09:00 by rparodi #+# #+# */
/* Updated: 2024/11/27 16:00:23 by rparodi ### ########.fr */
/* Updated: 2024/11/27 19:36:33 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minilibx-linux/mlx.h"
#include "test.h"
int worldMap[MAP_WIDTH][MAP_HEIGHT] = {\
@ -153,10 +152,10 @@ int render_frame(t_data *data)
int x;
y = 0;
while (y < WINDOW_HEIGHT)
while (y < data->screen_y)
{
x = 0;
while (x < WINDOW_WIDTH)
while (x < data->screen_x)
{
my_mlx_pixel_put(data, x, y, 0x00000000);
x++;
@ -164,9 +163,9 @@ int render_frame(t_data *data)
y++;
}
for(int x = 0; x < WINDOW_WIDTH; x++)
for(int x = 0; x < data->screen_x; x++)
{
double cameraX = 2 * x / (double)WINDOW_WIDTH - 1;
double cameraX = 2 * x / (double)data->screen_x - 1;
double rayDirX = data->dir_x + data->plane_x * cameraX;
double rayDirY = data->dir_y + data->plane_y * cameraX;
@ -216,11 +215,11 @@ int render_frame(t_data *data)
else
perpWallDist = (mapY - data->pos_y + (1 - stepY) / 2) / rayDirY;
int lineHeight = (int)(WINDOW_HEIGHT / perpWallDist);
int drawStart = -lineHeight / 2 + WINDOW_HEIGHT / 2;
int lineHeight = (int)(data->screen_y / perpWallDist);
int drawStart = -lineHeight / 2 + data->screen_y / 2;
if(drawStart < 0) drawStart = 0;
int drawEnd = lineHeight / 2 + WINDOW_HEIGHT / 2;
if(drawEnd >= WINDOW_HEIGHT) drawEnd = WINDOW_HEIGHT - 1;
int drawEnd = lineHeight / 2 + data->screen_y / 2;
if(drawEnd >= data->screen_y) drawEnd = data->screen_y - 1;
int color;
if (side == 0 && stepX > 0)
@ -244,8 +243,9 @@ int main(void)
t_data data;
data.mlx = mlx_init();
data.win = mlx_new_window(data.mlx, WINDOW_WIDTH, WINDOW_HEIGHT, "Raycaster");
data.img = mlx_new_image(data.mlx, WINDOW_WIDTH, WINDOW_HEIGHT);
mlx_get_screen_size(data.mlx, &data.screen_x, &data.screen_y);
data.win = mlx_new_window(data.mlx, data.screen_x, data.screen_y, "Raycaster");
data.img = mlx_new_image(data.mlx, data.screen_x, data.screen_y);
data.addr = mlx_get_data_addr(data.img, &data.bits_per_pixel, &data.line_length, &data.endian);
data.pos_x = 22;