-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
107 lines (99 loc) · 2.48 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
** utils.c for in /home/bertra_v/tek_1/IGraph/MUL_2014_wolf3d
**
** Made by Florent Bertrand
** Login <[email protected]>
**
** Started on Fri Dec 19 18:51:31 2014 Florent Bertrand
** Last update Sun Dec 21 16:20:37 2014 Florent Bertrand
*/
#include <stdlib.h>
#include <math.h>
#include "my.h"
#include "mlx.h"
#include "wolf3D.h"
void clear_img(t_mlx *mlx, t_params *params)
{
int x;
int y;
y = 0;
x = 0;
while (x < WIDTH)
{
y = 0;
while (y < HEIGHT / 2)
{
my_put_pixel_in_image(mlx, x, y, 0xADD8E6);
y++;
}
while (y < HEIGHT)
{
my_put_pixel_in_image(mlx, x, y, 0x66cc66);
y++;
}
x++;
}
}
void aff_wall(t_mlx *mlx, t_params *params, double DX, double DY)
{
if (map[mlx->niv][(int)DX][(int)DY] == 1)
{
while (params->s_wall <= params->e_wall)
{
if (DX - (int)DX >= 0.01 && DX - (int)DX <= 0.99)
my_put_pixel_in_image(mlx, params->j, params->s_wall++, 0x808080);
else
my_put_pixel_in_image(mlx, params->j, params->s_wall++, 0x9E9E9E);
}
}
else if (map[mlx->niv][(int)DX][(int)DY] == 2)
while (params->s_wall <= params->e_wall)
my_put_pixel_in_image(mlx, params->j, params->s_wall++, 0xFF0000);
else if (map[mlx->niv][(int)DX][(int)DY] == 3)
while (params->s_wall <= params->e_wall)
my_put_pixel_in_image(mlx, params->j, params->s_wall++, 0x00FF00);
else if (map[mlx->niv][(int)DX][(int)DY] == 4)
while (params->s_wall <= params->e_wall)
my_put_pixel_in_image(mlx, params->j, params->s_wall++, 0x0000FF);
}
void d_wall(t_params *params, t_mlx *mlx, double pMx, double pMy)
{
double DP;
double DX;
double DY;
double height;
DX = params->Xo + pMx;
DY = params->Yo + pMy;
while (map[mlx->niv][(int)DX][(int)DY] == 0)
{
DX += pMx * 0.001;
DY += pMy * 0.001;
}
DP = sqrt(pow((params->Xo - DX), 2) + pow((params->Yo - DY), 2));
DP /= sqrt(pow(pMx, 2) + pow(pMy, 2));
height = HEIGHT / (DP / 1);
params->s_wall = HEIGHT / 2 - height / 2;
params->e_wall = params->s_wall + height;
aff_wall(mlx, params, DX, DY);
}
void wolf_calc(t_mlx *mlx, t_params *params)
{
int i;
int Mx;
double pMx;
double My;
double pMy;
i = 0;
Mx = 1;
clear_img(mlx, params);
while (i <= WIDTH)
{
My = (WIDTH / 2.f - i) / WIDTH;
pMx = Mx * cos(params->angle) - My * sin(params->angle);
pMy = Mx * sin(params->angle) + My * cos(params->angle);
params->j = i;
d_wall(params, mlx, pMx, pMy);
i++;
}
expose_hook(mlx);
}