Ray casting fully explained. Pseudo 3D game

00:05:09
https://www.youtube.com/watch?v=g8p7nAbDz6Y

Sintesi

TLDRIn this video, Javed X9 provides a detailed explanation of raycasting, a technique used in pseudo-3D game development. The process includes detecting walls within the player's field of view, calculating distance to these walls, and drawing them accurately on the screen. The video discusses elements such as the game's map representation, intersection calculations (both horizontal and vertical), and the math involved in determining how walls are rendered based on their distance and orientation. Techniques like using different colors for wall representations are also covered, along with projections to ensure a proper visual display within the player’s field of vision. This insightful explanation breaks down complex concepts for viewers interested in game development and raycasting.

Punti di forza

  • 🎮 Raycasting is a rendering technique for pseudo-3D games.
  • 📏 It calculates wall intersections based on the player's position.
  • 🌐 The method involves mathematical principles like tangents.
  • 🎨 Wall faces are represented in different colors for distinction.
  • 📈 The closer the player is to a wall, the larger it appears.
  • 📽️ Each column ray corresponds to the screen width for FOV.
  • 🔍 Projections help remove distortion for a clear image.
  • 🔁 Subscribing and liking the video encourages more content.

Linea temporale

  • 00:00:00 - 00:05:09

    The video discusses the concept of raycasting, an important technique for rendering pseudo-3D games, which was notably used in games prior to 'Wolfenstein 3D.' The presenter explains how raycasting works by calculating the intersection of rays from the player with walls in a 2D map, represented as an array where walls are '1's and empty spaces are '0's. To achieve this, the video outlines the steps for finding both horizontal and vertical intersections, emphasizing the use of trigonometric ratios to calculate distances and the intersection points. The final rendering involves factoring in the player's field of view and adjusting the wall heights based on the distance from the player, using color differentiation to visually distinguish wall faces for clarity.

Mappa mentale

Video Domande e Risposte

  • What is raycasting?

    Raycasting is a technique used to render pseudo-3D views in games by calculating intersections of rays with walls.

  • How does the video explain the calculation of intersections?

    The video explains calculating intersections by finding horizontal and vertical intersections, then determining the smallest distance to render accurately.

  • What mathematical principles are used in raycasting?

    The video references ratios involving the tangent of angles, and projections using cosine calculations.

  • What is the visual representation of walls in the game?

    Horizontal walls are displayed in green, while vertical walls are shown in dark green for better distinction.

  • How does the player’s distance affect the rendering?

    The closer the player is to a wall, the larger the wall appears on the screen due to the projection calculations.

  • What should I do if I enjoy the video?

    You can subscribe for more videos and hit the like button if you enjoy the content.

Visualizza altre sintesi video

Ottenete l'accesso immediato ai riassunti gratuiti dei video di YouTube grazie all'intelligenza artificiale!
Sottotitoli
en
Scorrimento automatico:
  • 00:00:00
    half a year ago i saw a video made by
  • 00:00:02
    javed x9
  • 00:00:03
    where he used draycasting to make a
  • 00:00:05
    small game and a console
  • 00:00:06
    and back then i thought it was
  • 00:00:07
    impossible to do
  • 00:00:09
    raycasting is the method which was used
  • 00:00:11
    to render pseudo3d games before
  • 00:00:13
    wolfenstein 3d uses ray casting
  • 00:00:18
    but it's a little bit more advanced
  • 00:00:19
    there so
  • 00:00:21
    how does it exactly work and first it
  • 00:00:24
    cuts away from the player
  • 00:00:25
    and if there is an intersection with the
  • 00:00:27
    wall it draws a line based on the
  • 00:00:29
    distance
  • 00:00:30
    so when the distance is small enough the
  • 00:00:32
    line takes the whole height
  • 00:00:34
    and as the distance gets bigger the line
  • 00:00:36
    gets smaller
  • 00:00:38
    it was obviously a very brief
  • 00:00:40
    explanation let's go further
  • 00:00:42
    firstly we should understand what
  • 00:00:44
    information we have
  • 00:00:45
    we have a map which is stored as an
  • 00:00:47
    array and here one stands for walls and
  • 00:00:50
    zero stands for empty spaces
  • 00:00:54
    also we have a player that stores field
  • 00:00:56
    of view position and direction
  • 00:01:01
    it's better if you organize the tasks so
  • 00:01:04
    the first one is going to be calculating
  • 00:01:06
    distance
  • 00:01:07
    it consists of finding horizontal and
  • 00:01:09
    vertical intersections
  • 00:01:11
    and then getting the smallest one and
  • 00:01:13
    the final step
  • 00:01:14
    is the rendering i'm gonna start with
  • 00:01:18
    finding horizontal intersections
  • 00:01:24
    here if we look attentively we can see
  • 00:01:25
    that y-step is equal to the side of the
  • 00:01:28
    cell
  • 00:01:29
    and from math we know that the ratio of
  • 00:01:31
    y-step and x-step
  • 00:01:32
    is equal to the tangent of the angle
  • 00:01:34
    between them because they form a right
  • 00:01:36
    triangle
  • 00:01:37
    moreover y-step and next step are always
  • 00:01:40
    the same
  • 00:01:41
    and the angle the same because
  • 00:01:43
    horizontal lines are obviously parallel
  • 00:01:46
    therefore we can calculate x step but
  • 00:01:48
    before we can iteratively add
  • 00:01:50
    x-step and y-step we have to calculate
  • 00:01:52
    why nearest and x
  • 00:01:54
    nearest firstly we have to calculate y
  • 00:01:56
    nearest
  • 00:01:57
    that's how we can calculate it warning
  • 00:02:00
    we divide player y position
  • 00:02:01
    by the side of the cell evenly and as we
  • 00:02:04
    calculate the x
  • 00:02:05
    step we can calculate x nearest
  • 00:02:11
    that's great if you've understood now we
  • 00:02:12
    can go on finding vertical intersections
  • 00:02:15
    is similar to what we did before here we
  • 00:02:18
    can see that
  • 00:02:18
    in this case x-tap is equal to the side
  • 00:02:21
    of the cell
  • 00:02:22
    the ratio y step at x step is still
  • 00:02:24
    equal to the tangent of alpha
  • 00:02:26
    hence we can easily calculate y step
  • 00:02:29
    here
  • 00:02:30
    y step and x step are also always the
  • 00:02:32
    same
  • 00:02:33
    we do the same thing for x nearest and y
  • 00:02:36
    nearest
  • 00:02:36
    that's how we can calculate x nearest
  • 00:02:39
    don't forget to divide it evenly
  • 00:02:44
    we have calculated everything we need to
  • 00:02:46
    find intersections
  • 00:02:48
    now we're gonna apply it at first we add
  • 00:02:51
    x nearest and one nearest to the
  • 00:02:53
    player's position projection
  • 00:02:58
    and check if there is a wall
  • 00:03:02
    and if there is nothing we add x step
  • 00:03:04
    and y step
  • 00:03:05
    and check for intersection until we have
  • 00:03:07
    one
  • 00:03:10
    that's how finding horizontal
  • 00:03:11
    intersection works
  • 00:03:13
    here you can see that it also detects
  • 00:03:15
    vertical intersections
  • 00:03:18
    and that's how it works when i merge
  • 00:03:20
    them
  • 00:03:26
    hopefully you got everything i said
  • 00:03:28
    before and we can go on
  • 00:03:30
    this part was a little bit tricky for me
  • 00:03:32
    alpha stands for field of view and
  • 00:03:34
    h equal to the size of the wall here we
  • 00:03:37
    fade with the tangent again
  • 00:03:39
    thus we can calculate the ratio of the
  • 00:03:41
    line and therefore
  • 00:03:42
    based on the ratio we can calculate the
  • 00:03:44
    half of its length
  • 00:03:46
    and and the closer the player is the
  • 00:03:48
    bigger the wall
  • 00:03:49
    seems
  • 00:03:54
    now it's time for the final step here we
  • 00:03:56
    have to calculate this step
  • 00:03:58
    and for it we divide field of view by
  • 00:04:00
    the width of the screen
  • 00:04:02
    hence if we castray for each column in
  • 00:04:05
    total we will get an amount of rays
  • 00:04:07
    equal to the width of the screen we can
  • 00:04:09
    see that if we cast as many rays with
  • 00:04:12
    this step
  • 00:04:12
    it gives us the field of view so it
  • 00:04:15
    doesn't matter what field of view or
  • 00:04:16
    screen width you have
  • 00:04:19
    the image will just stretch or shrink
  • 00:04:25
    to remove the distortion we have to get
  • 00:04:27
    a projection of the distance vector
  • 00:04:29
    onto the player's direction and for it
  • 00:04:32
    we multiply the distorted distance by
  • 00:04:34
    the cosine of the angle between them
  • 00:04:38
    for a better image we need to somehow
  • 00:04:40
    distinguish faces of walls
  • 00:04:42
    at first i tried to use color
  • 00:04:44
    interpolation but it didn't look well
  • 00:04:46
    for me
  • 00:04:46
    [Music]
  • 00:04:47
    that's how it looked
  • 00:04:50
    then i decided to use different colors
  • 00:04:53
    for walls faces
  • 00:04:54
    i'm using green for horizontal and dark
  • 00:04:56
    green for vertical faces
  • 00:05:02
    i hope you found it helpful subscribe to
  • 00:05:05
    see more videos and pray the like button
  • 00:05:07
    if you enjoy the video
Tag
  • raycasting
  • game development
  • pseudo-3D
  • Wolfenstein 3D
  • intersections
  • math principles
  • wall rendering
  • field of view
  • color differentiation
  • Javed X9