• Stars
    star
    172
  • Rank 221,201 (Top 5 %)
  • Language
    C
  • Created over 4 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Some examples for those who try to use MLX library for 42 subject CUB3D or miniRT. And some helpful links.

English Ver. (Korean Ver. is down below, ํ•œ๊ตญ์–ด ๋ฒ„์ „์€ ๋ฐ‘์— ์žˆ์Šต๋‹ˆ๋‹ค.)

0. Intro

On the 42 intra subject page, there are two files minilibx_opengl.tgz and minilibx_mms_20200219_beta.tgz. Let's call them mlx and mlx_beta respectively.


1. Explaning my mlx example.

โ€‹ There is Makefile on evey example, and you can compile and run the program by typing make.

โ€‹ (gcc -Lmlx -lmlx -framework OpenGL -framework AppKit <- Compile option)

  • 01first_example: Create a simple window.
  • 02key_handling: Receive events on the keyboard.
      W: Add 1 to x.
      S: Subtract 1 from x.
      ESC: Quit program.
      Other keys: Show current x value.
    
  • 03img_loading: Draw the loaded xpm file on the window.
  • 04img_making: Draw pixels on the window without loading image file.
  • 05img_loading_and_modifying: Modify pixels on the window after loading image file.

Example 1 to 5 show basic mlx features while example 6 handles advanced features

  • 06map_2d: Make simple two-dimensional map. (Only Esc key and the close key on the top menu close the window. There's no other key interaction.)

2. Explaining major functions and their prototypes.

manual page: go to mlx_beta/man/man3 and type man ./[manual file].3

โ€‹ e.g. man ./mlx.3

man ./mlx.3 (Manual command)

  • void *mlx_init ();
man ./mlx_new_window.3

  • void *mlx_new_window ( void *mlx_ptr, int size_x, int size_y, char *title );
man ./mlx_loop.3

  • int mlx_loop ( void *mlx_ptr );

    • Keeps the program running when included in the last part of the program.
  • int mlx_key_hook ( void *win_ptr, int (*funct_ptr)(), void *param );

    • Handles key inputs.

    • Not used anymore because mlx_hook() function below is better in every circumstance.

  • int mlx_loop_hook ( void *mlx_ptr, int (*funct_ptr)(), void *param );

    • Keeps the program running even when there are no inputs (keyboard, mouse etc).
    • Continuously draws the screen based on the player's current location.
  • int mlx_hook(void *win_ptr, int x_event, int x_mask, int (*funct)(), void *param);

    • Major and powerful function that handles all inputs, but has no manual

    • Can receive key_press, key_release, mouse click, close button click, etc based on the x_event value

man ./mlx_new_image.3

โ€‹ I recommend that you see my image example

  • void *mlx_new_image ( void *mlx_ptr, int width, int height );
  • char *mlx_get_data_addr ( void *img_ptr, int *bits_per_pixel, int *size_line, int *endian );
  • int mlx_put_image_to_window ( void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y );
  • void* mlx_xpm_file_to_image ( void *mlx_ptr, char *filename, int *width, int *height );

3. Reference Sites

Course

  • Hard

    • Learn basic mlx features through my examples or referece #1 and reference #2.
    • Understand raycasting through reference #3 and reference #4
    • Code yourself with the help of the code in reference #5
  • Normal

    • Understand raycasting through reference #3
    • Learn mlx features through my examples
    • Code yourself with the help of the code in reference #5 (copy paste is one of the coding methods)
  • Easy

    • Learn mlx features through my examples
    • Code yourself with the help of the code in reference #5 (copy paste is one of the coding methods)

Reference

  1. Collection of mlx information && ft_libgfx tutorial

    • Contains most of the mlx information, but no easy to understand

    • Recommended to learn little by little

  2. Intra MinilibX Lecture

    • Basic mlx features for beginners
    • Add up to only 20~30 lines of codes in total
    • My examples and reference #1 already contain this information
  3. Raycasting Basics with JavaScript

    • Explains raycasting in a less mathematical way
    • Basic mathematical concepts such as sin and cos are explained
    • However, uses non-mlx graphic libraries to draw figures (no mlx explanations)
  • Need to refer to reference #4 because does not explain how to handle textures
  1. Raycasting explained(Lode's Computer Graphics Tutorial)

    • Need to understand most of this reference to understand cub3d

    • A challenging tutorial that made me want to give up, but I had to come back to this because the code I referred to was based on this tutorial

  2. The code I referred to (42-cub3d-glagan)

    • Cub3d repository with the most stars
    • Concise and well structured
    • Based on reference #4
    • But need to modify some parts (macro function usage, --save option, unable to receive nonsquare maps, etc)
  3. mlx image tutorials(images_example-keuhdall)

    • Recommended before handling images
    • Easy to understand
    • But does not provide information on how to load images

Other references


  1. key , mouse handling, etc (Both contain the same information)

  2. Keyboard code numbers


4. Some tips

  1. Two compressed files mlx and mlx_beta are given with the subject and mlx_beta seems to be more recent. However, I only used mlx

  2. However, mlx does not have a manual page so I referred to mlx_beta's manual page

  3. mlx's image files use xpm extensions but mlx_beta seem to handle png files as well

  4. mlx_pixel_put and mlx_put_image_to_window have almost the same features

    • mlx_put_image_to_window collect image information before drawing them at once

    • mlx_pixel_put seems slower because it draws dots right away

    • Better to collect pixel information and draw them at once with mlx_put_iamge_to_window

      • Experienced delay when used it twice
  5. Need to know DDA Algorithm when drawing pixels to form a line

    • reference #1 introduces other algorithms as well and reference #3 does not use DDA Algorithm
    • However, essential to understand raycasting explained in reference #4 and reference #5
  6. Can convert image files to xpm in the following site https://convertio.co/kr/png-xpm/

  7. Need to solve norm erros derived from reference #5's macro functions (Forbidden to use macro functions that use parameters)


Korean Ver.

์ˆ˜์ •์‚ฌํ•ญ

  • Lodev raycasting ๋ฒˆ์—ญ ๋ธ”๋กœ๊ทธ ์ถ”๊ฐ€ - 20.05.30
  • 06map_2d ์˜ˆ์ œ ์ถ”๊ฐ€ - 20.05.30
  • ์˜คํƒ€ ์ˆ˜์ • (ykoh๋‹˜ ์ œ๋ณด) - 20.10.18
  • Iwoo๋‹˜ ๋งต ํ…Œ์Šคํ„ฐ ์ถ”๊ฐ€ - 20.10.18

0. ๋“ค์–ด๊ฐ€๊ธฐ์— ์•ž์„œ

  1. cub3D ์„œ๋ธŒ์ ํŠธ ํŽ˜์ด์ง€์— ์ฒจ๋ถ€๋œ ์••์ถ•ํŒŒ์ผ minilibx_opengl.tgz๊ณผ minilibx_mms_20200219_beta.tgz 2๊ฐœ๊ฐ€ ์žˆ๋Š”๋ฐ ์ „์ž๋ฅผ mlx, ํ›„์ž๋ฅผ mlx_beta๋กœ ์ง€์นญํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

  2. ์ œ๊ฐ€ ๋ณด๋ ค๊ณ  ์จ๋†“์€ ์„œ๋ธŒ์ ํŠธ ๋ฒˆ์—ญ๋ณธ์ธ๋ฐ ๋ถ€์กฑํ•˜์ง€๋งŒ ํ•„์š”ํ•˜์‹œ๋ฉด ์‚ฌ์šฉํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

    ์ €๋งŒ ๋ณด๋ ค๊ณ  ๋Œ€์ถฉ ์จ๋†“์•„์„œ ํ—ˆ์ ‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์„œ๋ธŒ์ ํŠธ ๋ฒˆ์—ญ๋ณธ


1. ์˜ˆ์ œ ์„ค๋ช…

โ€‹ ๋ชจ๋“  ์ฝ”๋“œ๋งˆ๋‹ค Makefile์ด ์žˆ๊ณ  make ๋ฅผ ์น˜์‹œ๋ฉด ์ปดํŒŒ์ผ ๋ฐ ์‹คํ–‰์ด ๋ฉ๋‹ˆ๋‹ค.

โ€‹ (gcc -Lmlx -lmlx -framework OpenGL -framework AppKit <- ์ปดํŒŒ์ผ ์˜ต์…˜)

  • 01first_example: mlx๋กœ ์ฐฝ๋„์šฐ๋Š” ๊ฐ„๋‹จ์˜ˆ์ œ
  • 02key_handling: ํ‚ค๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ  ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
      W: x ๋ณ€์ˆ˜์— 1์„ ๋”ํ•จ
      S: x ๋ณ€์ˆ˜์—์„œ 1์„ ๋บŒ
      ESC: ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ 
      ๋‹ค๋ฅธํ‚ค: ํ˜„์žฌ x๊ฐ’ ์ถœ๋ ฅ
    
  • 03img_loading: xpmํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์™€์„œ ํ™”๋ฉด์— ๊ทธ๋ ค ์ฐฝ์— ๋„์›๋‹ˆ๋‹ค.
  • 04img_making: ํŒŒ์ผ์ด ์•„๋‹Œ ์ง์ ‘ ํ”ฝ์…€์— ์ ์„ ์ฐ์–ด์„œ ๊ทธ๋ฆผ์„ ๊ทธ๋ ค ์ฐฝ์— ๋„์›๋‹ˆ๋‹ค.
  • 05img_loading_and_modifying: ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜จ ๋’ค ๊ทธ ์œ„์— ํ”ฝ์…€์„ ์ฐ์–ด์„œ ์ฐฝ์— ๋„์›๋‹ˆ๋‹ค.

05๋ฒˆ๊นŒ์ง€๋Š” mlx์˜ ๊ธฐ๋ณธ ๊ธฐ๋Šฅ์„ ๋Œ€๋ถ€๋ถ„ ์‚ดํŽด๋ณด์•˜๊ณ  ์ดํ›„๋Š” ์‘์šฉ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

  • 06map_2d: ๊ฐ„๋‹จํ•œ 2d๋งต์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. (escํ‚ค, ์ฐฝ๋‹ซ๊ธฐ๋ฒ„ํŠผ์œผ๋กœ ์ข…๋ฃŒ๊ฐ€๋Šฅ, ๊ทธ ์ด์™ธ์˜ interaction ์—†์Œ)

2. ์ฃผ์š” ํ•จ์ˆ˜ prototype ๋ฐ ์„ค๋ช…

mlx_beta/man/man3ํด๋” ๋“ค์–ด๊ฐ€์…”์„œ ๊ฐ•์กฐ๋œ ์ œ๋ชฉ์œผ๋กœ ๋ช…๋ น์–ด ์น˜์‹œ๋ฉด ๋ฉ”๋‰ด์–ผ ํŽ˜์ด์ง€ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

man ./mlx.3

  • void *mlx_init ();
man ./mlx_new_window.3

  • void *mlx_new_window ( void *mlx_ptr, int size_x, int size_y, char *title );
man ./mlx_loop.3

  • int mlx_loop ( void *mlx_ptr );

    ๋งˆ์ง€๋ง‰์— ์ด๊ฑธ ์ณ์ค˜์•ผ ํ”„๋กœ๊ทธ๋žจ์ด ์ข…๋ฃŒํ•˜์ง€ ์•Š๊ณ  ๊ณ„์† ๋Œ์•„๊ฐ‘๋‹ˆ๋‹ค.

  • int mlx_key_hook ( void *win_ptr, int (*funct_ptr)(), void *param );

    ํ‚ค๋ณด๋“œ์˜ ํ‚ค๋“ค์„ ์ž…๋ ฅ๋ฐ›๋Š” ํ•จ์ˆ˜์ด์ง€๋งŒ ์•ˆ์”๋‹ˆ๋‹ค.

    ์ด์œ ๋Š” ๋ฐ‘์— mlx_hook()๊ฐ€ ๋” ์ข‹๊ธฐ ๋•Œ๋ฌธ์—

  • int mlx_loop_hook ( void *mlx_ptr, int (*funct_ptr)(), void *param );

    ์•„๋ฌด ์ž…๋ ฅ์ด ์—†์„๋•Œ ๊ณ„์† loop๋ฅผ ๋Œ๋ฆฌ๋Š” ํ•จ์ˆ˜. ์ด ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ํ˜„์žฌ ์œ„์น˜ ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ™”๋ฉด์„ ๋งค๋ฒˆ ์ƒˆ๋กœ ๊ทธ๋ฆฌ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

  • int mlx_hook(void *win_ptr, int x_event, int x_mask, int (*funct)(), void *param);

    ๊ผญ ํ•„์š”ํ•œ ํ•จ์ˆ˜๊ณ  ๊ฐ•๋ ฅํ•œ ํ•จ์ˆ˜์ธ๋ฐ ํŠน์ดํ•˜๊ฒŒ man์— ์—†์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  ์ž…๋ ฅ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜ x_event๊ฐ’์— ๋”ฐ๋ผ key_press, key_release, mouseํด๋ฆญ, ์ฐฝ๋‹ซ๊ธฐ๋ฒ„ํŠผ ๋“ฑ ์ž…๋ ฅ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์Œ

man ./mlx_new_image.3

โ€‹ ์—ฌ๊ธฐ๋Š” ์ œ ์ด๋ฏธ์ง€ ์˜ˆ์ œ๋ฅผ ํ•œ๋ฒˆ ๋ณด์‹œ๋Š” ๊ฒƒ์„ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

  • void *mlx_new_image ( void *mlx_ptr, int width, int height );
  • char *mlx_get_data_addr ( void *img_ptr, int *bits_per_pixel, int *size_line, int *endian );
  • int mlx_put_image_to_window ( void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y );
  • void* mlx_xpm_file_to_image ( void *mlx_ptr, char *filename, int *width, int *height );

3. ์ฐธ๊ณ  ์‚ฌ์ดํŠธ

  • ์ฝ”์Šค
    • Hard: ์ œ๊ฐ€ ๋งŒ๋“  ์˜ˆ์ œ๋‚˜ 1,2๋ฒˆ์œผ๋กœ mlx ๊ฐ์„ ์žก๊ณ  3,4๋ฒˆ์„ ํ†ตํ•ด raycasting์„ ์ดํ•ดํ•˜๋ฉด์„œ 5๋ฒˆ ์ฝ”๋“œ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ์ž‘์„ฑํ•˜๊ธฐ
    • Normal: 3๋ฒˆ ์‚ฌ์ดํŠธ๋กœ raycasting ๊ฐœ๋…์„ ์ดํ•ด ํ•œ๋’ค ์ œ๊ฐ€ ๋งŒ๋“  ์˜ˆ์ œ๋กœ mlx๋ฅผ ํŒŒ์•…ํ•˜๊ณ  5๋ฒˆ ๊นƒํ—™์„ ์ฐธ๊ณ ํ•ด์„œ ์ œ์ถœํ•˜๊ธฐ. (์ฐธ๊ณ ๋ผ๊ณ  ์“ฐ๊ณ  ํ•„์‚ฌ๋ผ๊ณ  ์ฝ๋Š”๋‹ค.)
    • Easy: ์ œ๊ฐ€ ๋งŒ๋“  ์˜ˆ์ œ๋กœ mlxํŒŒ์•… ํ›„ 5๋ฒˆ ์ฝ”๋“œ ์ฐธ๊ณ ํ•ด์„œ ์ œ์ถœํ•˜๊ธฐ. (์ฐธ๊ณ ๋ผ๊ณ  ์“ฐ๊ณ  ํ•„์‚ฌ๋ผ๊ณ  ์ฝ๋Š”๋‹ค.)
  1. mlx๊ด€๋ จ ์ž๋ฃŒ ๋ชจ์Œ์ง‘, ํŠœํ† ๋ฆฌ์–ผft_libgfx

    mlx์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์ „์ฒด์ ์œผ๋กœ ๋‹ด๊ฒจ์žˆ์ง€๋งŒ ์ฒ˜์Œ ๋ณด๊ธฐ ์‰ฝ์ง€์•Š์Šต๋‹ˆ๋‹ค.

    ํ•œ๋ฒˆ์— ๋‹ค ํŒŒ์•…ํ•˜์ง€ ๋ง๊ณ  ํ•„์š”ํ•œ ๋งŒํผ์”ฉ ํŒŒ์•…ํ•˜์‹œ๋Š” ๊ฑธ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

  2. Intra MinilibX๊ฐ•์˜

    ์ฒ˜์Œ์— mlx๋ฅผ ์–ด๋–ป๊ฒŒ ๋‹ค๋ค„์•ผ ํ•˜๋Š”์ง€ ์‹œ์ž‘๋งŒ ์•Œ๋ ค์ค๋‹ˆ๋‹ค.(์•„์ฃผ ๊ธฐ๋ณธ)

    ์‚ฌ์‹ค ์š”์•ฝํ•˜๋ฉด ์ฝ”๋“œ 20~30์ค„ ์ •๋„๋ฐ–์— ์•ˆ๋˜๊ณ  ๊ทธ ์ฝ”๋“œ๊ฐ€ 1๋ฒˆ์‚ฌ์ดํŠธ๋‚˜ ์ œ ์˜ˆ์ œ์— ์ ํ˜€์žˆ์–ด์„œ ์•ˆ๋ด๋„ ๋ฌด๋ฐฉํ•ฉ๋‹ˆ๋‹ค.

  3. Raycasting Basics with JavaScript

    ์ˆ˜ํ•™์ ์ธ ๊ฐœ๋…์„ ๋ชจ๋ฅด๊ณ  raycasting์„ ์ดํ•ดํ• ์ˆ˜ ์žˆ๊ฒŒ ์„ค๋ช…ํ•ด์ค๋‹ˆ๋‹ค.

    sin, cos์ด ์“ฐ์ด๋Š”๋ฐ ๊ฐœ๋…๋ถ€ํ„ฐ ์ฐจ๊ทผ์ฐจ๊ทผํžˆ ์„ค๋ช…ํ•ด์ค๋‹ˆ๋‹ค.

    ๋‹ค๋งŒ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ์“ฐ๋Š” ๊ทธ๋ž˜ํ”ฝ ํ•จ์ˆ˜๊ฐ€ mlx์™€ ๋‹ฌ๋ผ์„œ ์ง์ ‘ ๊ตฌํ˜„ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.(์ง์„ , ์‚ฌ๊ฐํ˜•, ์› ๊ทธ๋ฆฌ๊ธฐ ๋“ฑ)

    ๊ทธ๋ฆฌ๊ณ  texture๋ฅผ ๋‹ค๋ฃจ๋Š” ๋ฐฉ๋ฒ•์€ ์•ˆ์“ฐ์—ฌ์žˆ๊ณ  ๋ฐ‘์— 4,5๋ฒˆ ์‚ฌ์ดํŠธ์™€ ๋ฐฉ์‹์ด ๋‹ฌ๋ผ์„œ ์–ด์ฉ”์ˆ˜ ์—†์ด 4๋ฒˆ ์‚ฌ์ดํŠธ์˜ ์„ค๋ช…์„ ๋ด์•ผํ•ฉ๋‹ˆ๋‹ค.

  4. Raycasting explained(Lode's Computer Graphics Tutorial)

    • ์œ„ ์‚ฌ์ดํŠธ์˜ ๋ฒˆ์—ญ ๊นƒํ—™ (365kim)
      • ๊ธฐ์กด์—๋„ ์œ—๊ธ€์„ ๋ฒˆ์—ญํ•œ ๋ธ”๋กœ๊ทธ๊ฐ€ ์žˆ์—ˆ๋Š”๋ฐ ๊ทธ ๋ฒˆ์—ญ๋ณด๋‹ค ํ›จ์”ฌ ์ž์—ฐ์Šค๋Ÿฝ๊ณ  ์ฝ๊ธฐ ์‰ฝ๊ฒŒ ๋ฒˆ์—ญ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
      • ๋˜ํ•œ mdํŒŒ์ผ๋กœ ์›๋ฌธ๋ณด๋‹ค ํ›จ์”ฌ ์ฝ๊ธฐ ๊น”๋”ํ•˜๊ฒŒ ์ •๋ฆฌ๋˜์–ด ์žˆ์–ด์„œ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค!!

    cub3d๋ฅผ ์ดํ•ดํ•˜๋ ค๋ฉด 4๋ฒˆ์„ ๊ฑฐ์˜ ์ „๋ถ€ ์ดํ•ดํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

    ์™ธ๋ฉดํ•˜๊ณ  ์‹ถ์€ ์ˆœ๊ฐ„์ด ํ•œ๋‘๋ฒˆ์ด ์•„๋‹ˆ์—ˆ์ง€๋งŒ ์ œ๊ฐ€ ์ฐธ๊ณ ํ•œ ์ฝ”๋“œ๊ฐ€ ์ด ๊ฐ•์˜๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๊ณ  ์žˆ์–ด์„œ

    ๋ง‰ํž๋•Œ๋งˆ๋‹ค ์ด ์‚ฌ์ดํŠธ๋ฅผ ๋ถ™์žก๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

  5. ์ œ๊ฐ€ ์ฐธ๊ณ ํ•œ cub3d github(42-cub3d-glagan)

    ์ œ๊ฐ€ ์ฐธ๊ณ ํ•œ ๊นƒํ—™ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. (github์—์„œ cub3d๋กœ ๊ฒ€์ƒ‰ํ–ˆ์„ ๋•Œ star์ œ์ผ ๋งŽ์Œ)

    ์ฝ”๋“œ๊ฐ€ ์ƒ๋‹นํžˆ ๊น”๋”ํ•˜๊ฒŒ ์งœ์—ฌ์ ธ์žˆ๊ณ  4๋ฒˆ์˜ ์„ค๋ช…์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๊ณ  ์žˆ์–ด์„œ 4๋ฒˆ์„ ์ดํ•ดํ•˜๋ฉด์„œ ๋ณด๊ธฐ ์ข‹์Šต๋‹ˆ๋‹ค.

    ๋‹ค๋งŒ ์ˆ˜์ •ํ•ด์•ผํ•  ๋ถ€๋ถ„๋“ค์ด ๋ช‡๊ตฐ๋ฐ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.(macro ํ•จ์ˆ˜ ์‚ฌ์šฉ๋ถ€๋ถ„, --save์˜ต์…˜, ์ •์‚ฌ๊ฐํ˜•์ด ์•„๋‹Œ ๋งต ๋“ฑ)

  6. mlx ์ด๋ฏธ์ง€ ๊ด€๋ จ ํŠœํ† ๋ฆฌ์–ผ(images_example-keuhdall)

    ์ด๋ฏธ์ง€๋ฅผ ๋‹ค๋ฃจ๊ธฐ์ „์— ํ•œ๋ฒˆ ํ•ด๋ณด๋ฉด ์ข‹์€ ๊นƒํ—™์ž…๋‹ˆ๋‹ค.

    ์„ค๋ช…์ด ์ž˜ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

    ๋‹ค๋งŒ ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“œ๋Š”๋ฒ•์€ ์žˆ์ง€๋งŒ ๋กœ๋”ฉํ•˜๋Š” ๋ฒ•์ด ์—†์—ˆ๋˜ ๊ฒƒ์œผ๋กœ ๊ธฐ์–ตํ•ฉ๋‹ˆ๋‹ค.

  7. Cub3D Map Tester(42 Cadet Iwoo๋‹˜๊ป˜์„œ ์ œ์ž‘)

    ์œ ํšจํ•œ ๋งต์ธ์ง€ ๊ฒ€์‚ฌํ•ด์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค!

๊ธฐํƒ€ ์ฐธ๊ณ  ์‚ฌ์ดํŠธ


  1. key , mouse handling๊ด€๋ จ(๋‘˜์ด ๊ฐ™์€ ๋‚ด์šฉ)

  2. ํ‚ค๋ณด๋“œ์˜ ์ฝ”๋“œ๋ฒˆํ˜ธ๋ฅผ ์ •๋ฆฌํ•ด๋†“์€ ์ž๋ฃŒ


4. ์•ฝ๊ฐ„์˜ ํŒ

  1. ์„œ๋ธŒ์ ํŠธ ๋ฐ›์„ ๋•Œ mlx์™€ mlx_beta ๋‘ ์••์ถ•ํŒŒ์ผ์„ ์ฃผ๋Š”๋ฐ beta๊ฐ€ ๊ฐœ์„ ๋ฒ„์ „์ธ๋“ฏ ํ•œ๋ฐ ์ €๋Š” mlx๋กœ๋งŒ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

    ๋‹ค๋งŒ mlx์—๋Š” manํŽ˜์ด์ง€๊ฐ€ ์—†์–ด์„œ mlx_beta์˜ manํŽ˜์ด์ง€๋ฅผ ์ฐธ๊ณ ํ–ˆ์Šต๋‹ˆ๋‹ค.

    mlx๋Š” ์ด๋ฏธ์ง€ํŒŒ์ผ์ด xpmํ™•์žฅ์ž๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•˜๋Š”๋ฐ mlx_beta๋Š” png๋„ ๊ฐ€๋Šฅํ•œ๋“ฏํ•ฉ๋‹ˆ๋‹ค.

  2. mlx_pixel_put๊ณผ mlx_put_image_to_window๋Š” ๊ฑฐ์˜ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ํ•ฉ๋‹ˆ๋‹ค๋งŒ mlx_put_image_to_window๋Š” ์ด๋ฏธ์ง€ ์ •๋ณด๋ฅผ ๋ชจ์•˜๋‹ค๊ฐ€ ํ•œ๋ฒˆ์— ๊ทธ๋ฆฌ๊ณ , mlx_pixel_put์€ ๋งค๋ฒˆ ์ ์„ ๊ทธ๋ ค์„œ ์†๋„๊ฐ€ ๋Š๋ฆฐ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    ๋”ฐ๋ผ์„œ mlx_put_image_to_window๋Š” ํ™”๋ฉด์˜ ๋ชจ๋“  pixel์ •๋ณด๋ฅผ ๋ชจ์•˜๋‹ค๊ฐ€ ํ•œ๋ฒˆ์— ๊ทธ๋ฆฌ๋Š”๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค. (์ด ์ด์œ ๋•Œ๋ฌธ์ธ์ง€ ํ™•์‹ค์นœ ์•Š์ง€๋งŒ, ๋‘๋ฒˆ๋งŒ ์จ๋„ ์†๋„๊ฐ€ ๋Š๋ ค์ง€๋Š”๊ฒƒ์„ ๋Š๊ผˆ์Šต๋‹ˆ๋‹ค)

  3. ๋„ํŠธ์— ์„ ์„ ๊ทธ๋ฆด ๋•Œ DDA Algorithm์„ ์•Œ์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์œ„์— 1๋ฒˆ์‚ฌ์ดํŠธ์—์„œ ๋‹ค๋ฅธ ์•Œ๊ณ ๋ฆฌ์ฆ˜๋„ ์†Œ๊ฐœ๋˜๊ธด ํ•˜๋Š”๋ฐ ์œ„์˜ 4,5๋ฒˆ ์‚ฌ์ดํŠธ์—์„œ raycasting์„ ์ดํ•ดํ•  ๋•Œ ๊ผญ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. 3๋ฒˆ ์‚ฌ์ดํŠธ์—์„œ๋Š” ํ•„์š”ํ•˜์ง€ ์•Š์•˜๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  4. ์•„๋ž˜ ์‚ฌ์ดํŠธ์—์„œ ๊ฐ์ข… ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ xpm์œผ๋กœ ๋ณ€ํ™˜ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. https://convertio.co/kr/png-xpm/

  5. ์œ„์˜ glagan github์˜ ์ฝ”๋“œ์ค‘ macroํ•จ์ˆ˜๋Š” ํ˜„์žฌ norm ์—๋Ÿฌ๊ฐ€ ๋– ์„œ ํ•ด๊ฒฐํ•ด ์ฃผ์–ด์•ผํ•ฉ๋‹ˆ๋‹ค. (ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋งคํฌ๋กœ ํ•จ์ˆ˜ ๊ธˆ์ง€)

  6. sprite๊ฐ€ ๋ฒฝ๊ณผ ํ•ฉ์ณ์ง€๋Š” ์˜ค๋ฅ˜๋ฐœ์ƒ์‹œ ํŒ์ž…๋‹ˆ๋‹ค.(42 Iwoo๋‹˜ ์ œ๋ณด)

์ถฉ๋ถ„ํžˆ ๊ณ ๋ฏผํ•˜์…จ์œผ๋ฉด ์ฐธ๊ณ ํ•ด๋ณด์„ธ์š”.

[Raycasting explained(Lode's Computer Graphics Tutorial)](https://lodev.org/cgtutor/raycasting.html)๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์„ฑ์‹คํžˆ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์…จ๋‚˜์š”? :)
์ด ๊ฒฝ์šฐ! ๋งต ๊ฒฉ์ž๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์„ ๋•Œ
11111
11211
10N01
10001
11111
์•„๋ž˜ ์ด๋ฏธ์ง€์ฒ˜๋Ÿผ ๋ณด์ด๋Š” ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
![sprite_pos_error](https://user-images.githubusercontent.com/54612343/83328284-e5224080-a2bc-11ea-8756-8f5d4b23c105.JPG)
**์ด๋Š” sprite์˜ ์œ„์น˜์ขŒํ‘œ๊ฐ€ ๋งต๊ฒฉ์ž์˜ ๋ชจ์„œ๋ฆฌ์— ํ•ด๋‹นํ•˜๋Š” ์ •์ˆ˜๊ฐ’์œผ๋กœ ์„ค์ •๋˜์–ด์„œ ์ƒ๊ธฐ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.**

sprite[i].x์™€ sprite[i].y์˜ ๊ฐ’์— 0.5์”ฉ ์ถ”๊ฐ€ํ•˜์—ฌ sprite์˜ ์œ„์น˜๊ฐ€ ๋งต๊ฒฉ์ž์˜ ์ค‘์•™์— ์˜ค๋„๋ก ์„ค์ •ํ•ด๋ณด์„ธ์š” :)
๋งˆ์ฐฌ๊ฐ€์ง€๋กœ player์˜ ์ดˆ๊ธฐ position๋„ ๊ฐœ์„ ํ•ด๋ณด์‹œ๋Š”๊ฑธ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค.