heres my RayCasting code on VB2010(it can be another programming language, i will get the same bug):
Private Function GetPositionMap(ByVal Position As Double) As Integer
Return fix(Position / ObjectSize)
End Function
Private Sub DrawRays()
Dim StepX As Double
Dim StepY As Double
Dim VertX As Double
Dim VertY As Double
Dim HorizX As Double
Dim HorizY As Double
Dim MapX As Long
Dim MapY As Long
Dim HorizDist As Double
Dim VertDist As Double
Dim WallDistance As Double
Dim RayHeight As Double
Dim RayRadians As Double
Dim RadiansSteps As Double
Dim RayCount As Long
Dim RayCounts As Long = 0
Dim OffSetGrid As Long
Dim PreviousRayX As Double = 0
Dim PreviousRayY As Double = 0
Dim RayX As Double = 0
Dim RayY As Double = 0
'Get viewe Width:
RayCount = 320
'Divide the FOV in a Radians steps by level width:
RadiansSteps = Radian60 / RayCount
'Get the FOV start radians(player minus half of FOV):
RayRadians = (player.Radians - Radian30)
RayCounts = 0
Do While RayCounts < RayCount
If (RayRadians > Radian360) Then RayRadians -= Radian360 'correct some Radians
If (RayRadians < 0) Then RayRadians += Radian360
'Check for horizontal intersections:
'and get the 1st horizontal line intersection:
If RayRadians >= 0 And RayRadians <= Math.PI Then 'Facing down
HorizY = (fix(player.PosY / ObjectSize) * ObjectSize) + ObjectSize ' Calculate grid position
HorizX = player.PosX + (HorizY - player.PosY) / Math.Tan(RayRadians)
StepY = ObjectSize
Else 'Facing Up
HorizY = (fix(player.PosY / ObjectSize) * ObjectSize) - 1
HorizX = player.PosX + (HorizY - player.PosY) / Math.Tan(RayRadians)
StepY = -ObjectSize
End If
StepX = StepY / Math.Tan(RayRadians)
MapX = GetPositionMap(HorizX)
MapY = GetPositionMap(HorizY)
'Get all Vertical intersection lines until hit a wall:
Do
If MapX < 0 Or MapX > 9 Or MapY < 0 Or MapY > 9 Then Exit Do
If MapLevel0(MapY, MapX) = Color.Black Then Exit Do
HorizX = HorizX + StepX
HorizY = HorizY + StepY
MapX = HorizX \ ObjectSize
MapY = HorizY \ ObjectSize
Loop
'Get the Ray Distance:
HorizDist = Math.Abs((player.PosX - HorizX) / Math.Cos(RayRadians))
'Check for vertical intersections:
'and get the 1st vertical line intersection:
If RayRadians <= Radian90 Or RayRadians >= Radian270 Then 'Facing right
VertX = (fix(Player.PosX / ObjectSize) * ObjectSize) + ObjectSize ' Calculate grid position
VertY = Player.PosY + (Player.PosX - VertX) * -Math.Tan(RayRadians)
StepX = ObjectSize
Else 'Facing left
VertX = (fix(Player.PosX / ObjectSize) * ObjectSize) - 1
VertY = Player.PosY + (Player.PosX - VertX) * -Math.Tan(RayRadians)
StepX = -ObjectSize
End If
StepY = StepX * Math.Tan(RayRadians)
MapX = GetPositionMap(VertX)
MapY = GetPositionMap(VertY)
'Get all Vertical intersection lines until hit a wall:
Do
If MapX < 0 Or MapX > 9 Or MapY < 0 Or MapY > 9 Then Exit Do
If MapLevel0(MapY, MapX) = Color.Black Then Exit Do
VertX = VertX + StepX
VertY = VertY + StepY
MapX = VertX \ ObjectSize
MapY = VertY \ ObjectSize
Loop
'Get the Ray Distance:
VertDist = Math.Abs((Player.PosX - VertX) / Math.Cos(RayRadians))
'Get the nearst Ray:
Dim clr As New Pen(Color.Blue, 1)
Dim ImagePosition As Long = 0
If VertDist < HorizDist Then
WallDistance = VertDist
OffSetGrid = VertY Mod ObjectSize
clr.Color = Color.Blue
Else
OffSetGrid = HorizX Mod ObjectSize
WallDistance = HorizDist
clr.Color = Color.DarkBlue
End If
'Draw the nearst Ray(4 is the circle\player center):
'imgverticallineGraphics.DrawLine(Pens.Blue, New Point(player.PosX + 4, player.PosY + 4), New Point(RayX, RayY))
'Avoiding the Fish Effect:
WallDistance = WallDistance * Math.Cos(RayRadians - Player.Radians)
'Calculate the vertical line Height:
RayHeight = (ObjectSize / WallDistance) * 200
'Get the texture vertical line:
'picWall1.DrawTextureVerticalLine(A.MemoryHDC, OffSetGrid, fix(RayHeight * 4), RayCounts, 5)
'Debug.Print(CStr(OffSetGrid))
'draw a vertical line:
'imgLevelMap0Graphics.DrawLine(clr, New Point(RayCounts, 300 / 2 - RayHeight / 2), New Point(RayCounts, 300 / 2 + RayHeight / 2))
'draw the vertical line:
img.ForeColor(RGB(clr.Color.R, clr.Color.G, clr.Color.B), 0, clr.Width)
img.DrawLine(RayCounts, Fix(300 / 2 - RayHeight / 2), RayCounts, Fix(300 / 2 + RayHeight / 2))
RayCounts = RayCounts + 1 'next vertical line
RayRadians += RadiansSteps 'next vertical line angle
Loop
End Sub
the result: https://imgur.com/kN8i4lQ
why i get that more width vertical line?
to be honest i have these question in several places and no luck :( .... if i'm expressing wrong or is need more information, please tell me.