Visual Basic 2010: como evitar algumas linhas verticais em RayCasting?

Cambalinho

Power Member
eu tenho esta função para calcular e desenhar as linhas verticais no RayCasting:
Código:
 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
        Dim OffSetGrid As Long

        RayCount = imgverticalline.Width

        MapX = Player.MapX
        MapY = Player.MapY
        RadiansSteps = Radian60 / RayCount

        RayRadians = (Player.Radians - Radian30)
        RayCounts = 0
        img.ForeColor(RGB(255, 0, 0))
        Do While RayCounts < RayCount
            If (RayRadians > Radian360) Then RayRadians = 0.001
            'Check for horizontal intersections:

            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
            ElseIf RayRadians = 0 Or RayRadians = Math.PI Then
                HorizY = player.PosY
                HorizX = player.PosX
            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)

            Do
                If MapX < 0 Or MapX > 9 Or MapY < 0 Or MapY > 9 Then Exit Do
                If levelmap0(MapY, MapX) = Color.Black Then Exit Do
                HorizX = HorizX + StepX
                HorizY = HorizY + StepY
                MapX = HorizX \ ObjectSize
                MapY = HorizY \ ObjectSize

            Loop

            HorizDist = Math.Abs((player.PosX - HorizX) / Math.Cos(RayRadians))

            'Check for vertical intersections:
            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
            ElseIf RayRadians = Radian90 Or RayRadians = Radian270 Then
                VertY = Player.PosY
                VertX = Player.PosX
            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)
            Do
                If MapX < 0 Or MapX > 9 Or MapY < 0 Or MapY > 9 Then Exit Do
                If levelmap0(MapY, MapX) = Color.Black Then Exit Do
                VertX = VertX + StepX
                VertY = VertY + StepY
                MapX = VertX \ ObjectSize
                MapY = VertY \ ObjectSize
            Loop
            VertDist = Math.Abs((player.PosX - VertX) / Math.Cos(RayRadians))
            Dim VertColor As Color
            If VertDist < HorizDist Then
                WallDistance = VertDist
                OffSetGrid = VertY Mod ObjectSize
                img.DrawLine(Math.Round(player.PosX), Math.Round(player.PosY), Math.Round(VertX), Math.Round(VertY))
                VertColor = Color.BlueViolet
            Else
                OffSetGrid = HorizX Mod ObjectSize
                WallDistance = HorizDist
                img.DrawLine(Math.Round(player.PosX), Math.Round(player.PosY), Math.Round(HorizX), Math.Round(HorizY))
                VertColor = Color.Blue
            End If

            WallDistance = WallDistance * Math.Cos(RayRadians - player.Radians) 'avoiding the Fish Effect
            RayHeight = (ObjectSize / WallDistance) * 200 ' is the height screen\
            'If (OffSetGrid < 0 Or OffSetGrid >= picWall1.Width) Then OffSetGrid = 0
            'picWall1.DrawTextureVerticalLine(img.MemoryHDC, OffSetGrid, Fix(RayHeight * 4), RayCounts, 5)

            imgverticalline.ForeColor(RGB(VertColor.R, VertColor.G, VertColor.B))
            imgverticalline.DrawLine(RayCounts, imgverticalline.Height / 2 - RayHeight \ 2, RayCounts, imgverticalline.Height / 2 + RayHeight \ 2)
            RayRadians = RayRadians + RadiansSteps
            RayCounts = RayCounts + 1
        Loop

    End Sub
eis o resultado:
como posso evitar essa linha vertical que aparece na largura da parede\objeto?
 
Back
Topo