mouse movement now works :)

This commit is contained in:
djonker 2023-10-29 12:11:25 +01:00
parent d6f462f9bf
commit f705f20fe8
3 changed files with 41 additions and 3 deletions

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */ /* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */
/* Updated: 2023/10/27 16:46:25 by djonker ######## odam.nl */ /* Updated: 2023/10/29 11:50:54 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -51,6 +51,8 @@ typedef struct s_varlist
int stepy; int stepy;
int hit; int hit;
int side; int side;
double oldmouseposx;
double oldmouseposy;
int32_t fcolor; int32_t fcolor;
int32_t ccolor; int32_t ccolor;
char *northwt; char *northwt;
@ -71,6 +73,7 @@ void ft_movementkeys(t_varlist *vl);
void keyhook(mlx_key_data_t kd, void *param); void keyhook(mlx_key_data_t kd, void *param);
void scrollhook(double xdelta, double ydelta, void *param); void scrollhook(double xdelta, double ydelta, void *param);
void resizehook(int x, int y, void *param); void resizehook(int x, int y, void *param);
void cursorhook(double x, double y, void *param);
// raycast.c // raycast.c
void ft_raycast(t_varlist *vl); void ft_raycast(t_varlist *vl);
// draw.c // draw.c

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */ /* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */
/* Updated: 2023/10/29 06:34:27 by houtworm ######## odam.nl */ /* Updated: 2023/10/29 12:10:26 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -120,6 +120,39 @@ void scrollhook(double xdelta, double ydelta, void *param)
ft_putendl("scroll down"); ft_putendl("scroll down");
} }
#include <stdio.h>
void cursorhook(double xpos, double ypos, void *param)
{
t_varlist *vl;
double olddirx;
double oldplanex;
double speed;
vl = param;
ypos++;
if (xpos < vl->oldmouseposx)
{
speed = (vl->oldmouseposx - xpos) * vl->rotspeed / 20;
olddirx = vl->dirx;
vl->dirx = vl->dirx * cos(speed) - vl->diry * sin(speed);
vl->diry = olddirx * sin(speed) + vl->diry * cos(speed);
oldplanex = vl->planex;
vl->planex = vl->planex * cos(speed) - vl->planey * sin(speed);
vl->planey = oldplanex * sin(speed) + vl->planey * cos(speed);
}
if (xpos > vl->oldmouseposx)
{
speed = (xpos - vl->oldmouseposx) * vl->rotspeed / 20;
olddirx = vl->dirx;
vl->dirx = vl->dirx * cos(-speed) - vl->diry * sin(-speed);
vl->diry = olddirx * sin(-speed) + vl->diry * cos(-speed);
oldplanex = vl->planex;
vl->planex = vl->planex * cos(-speed) - vl->planey * sin(-speed);
vl->planey = oldplanex * sin(-speed) + vl->planey * cos(-speed);
}
vl->oldmouseposx = xpos;
}
void resizehook(int x, int y, void *param) void resizehook(int x, int y, void *param)
{ {
t_varlist *vl; t_varlist *vl;

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */ /* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */
/* Updated: 2023/10/27 14:59:03 by djonker ######## odam.nl */ /* Updated: 2023/10/29 12:08:59 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -51,6 +51,8 @@ int main(int argc, char **argv)
mlx_key_hook(vl.mlx, &keyhook, &vl); mlx_key_hook(vl.mlx, &keyhook, &vl);
mlx_resize_hook(vl.mlx, &resizehook, &vl); mlx_resize_hook(vl.mlx, &resizehook, &vl);
mlx_scroll_hook(vl.mlx, &scrollhook, &vl); mlx_scroll_hook(vl.mlx, &scrollhook, &vl);
mlx_set_cursor_mode(vl.mlx, MLX_MOUSE_DISABLED);
mlx_cursor_hook(vl.mlx, &cursorhook, &vl);
mlx_loop_hook(vl.mlx, &mainloop, &vl); mlx_loop_hook(vl.mlx, &mainloop, &vl);
mlx_loop(vl.mlx); mlx_loop(vl.mlx);
mlx_delete_image(vl.mlx, vl.img); mlx_delete_image(vl.mlx, vl.img);