Results 1 to 17 of 17

Thread: VB6 - raycasting: how get the image line?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    VB6 - raycasting: how get the image line?

    i have the line height and i can draw it:
    Code:
    a.drawline(x0,y0,x1,y1) A.DrawLine 475 + 50 + RayCounts, 200 / 2 - RayHeight / 2, 475 + 50 + RayCounts, 200 / 2 + RayHeight / 2
    'a' is my image class instance.
    now i want get the image line:
    Code:
    If VertDist < HorizDist Then
                ' Draw the vertical ray:
                A.DrawLine Fix(Player.PosX), Fix(Player.PosY), Fix(VertX), Fix(VertY)
                WallDistance = VertDist
                'getting the image line position:
                GridX = VertX Mod ObjectSize
                GridY = VertY Mod ObjectSize
            Else
                ' Draw the horizontal ray:
                A.DrawLine Fix(Player.PosX), Fix(Player.PosY), Fix(HorizX), Fix(HorizY)
                
                WallDistance = HorizDist
                'getting the image line position:
                GridX = HorizX Mod ObjectSize
                GridY = HorizY Mod ObjectSize
            End If
            'Debug.Print GridX & "  " & GridY
            WallDistance = WallDistance * Cos(RayRadians - Player.Radians) 'avoiding the Fish Effect
            RayHeight = (ObjectSize / WallDistance) * 200 ' is the height screen\
            'a.drawline(x0,y0,x1,y1) A.DrawLine 475 + 50 + RayCounts, 200 / 2 - RayHeight / 2, 475 + 50 + RayCounts, 200 / 2 + RayHeight / 2
            If (GridX = 0) Then
                StretchBlt A.MemoryHDC, 475 + 50 + RayCounts, 200 / 2 - RayHeight / 2, 475 + 50 + RayCounts, 200 / 2 + RayHeight / 2, picWall1.hdc, 0, GridY, 1, picWall1.Height, SRCCOPY
            Else
                StretchBlt A.MemoryHDC, 475 + 50 + RayCounts, 200 / 2 - RayHeight / 2, 475 + 50 + RayCounts, 200 / 2 + RayHeight / 2, picWall1.hdc, GridX, 0, picWall1.Width, 1, SRCCOPY
            End If
    the image line is drawed... but incorrectly
    heres the result: https://imgur.com/W6NbjQp
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    Re: VB6 - raycasting: how get the image line?

    finally i get more correct values:
    Code:
    Private Sub DrawRays2()
         
        Dim AY As Double
        Dim AX As Double
        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 Integer
        Dim RayCounts As Integer
        Dim blnSomething As Boolean
        Dim OffSetGrid As Long
    
        
        RayCount = 320
    
        MapX = Player.MapX
        MapY = Player.MapY
        RadiansSteps = Radian60 / 320
        
        'On Error Resume Next
        RayRadians = (Player.Radians - Radian30)
        RayCounts = 0
        Do While RayCounts < RayCount
            If (RayRadians > (2 * pi)) Then RayRadians = 0.001
            'If (RayRadians < 0) Then RayRadians = (2 * pi)
            'Check for horizontal intersections:
            If RayRadians > 0 And RayRadians < pi Then 'Facing down
                AY = (Int(Player.PosY / ObjectSize) * ObjectSize) + ObjectSize ' Calculate grid position
                AX = Player.PosX + (AY - Player.PosY) / Tan(RayRadians)
                StepY = ObjectSize
            ElseIf RayRadians = 0 Or RayRadians = pi Then
                AY = Player.PosY
                AX = Player.PosX
            Else 'Facing Up
                AY = (Int(Player.PosY / ObjectSize) * ObjectSize) - 1
                AX = Player.PosX + (AY - Player.PosY) / Tan(RayRadians)
                StepY = -ObjectSize
            End If
    
    
            HorizX = AX
            HorizY = AY
            StepX = StepY / Tan(RayRadians)
            If HorizX < 0 Then
                MapX = 0
            ElseIf HorizX > 9 * ObjectSize Then
                MapX = 9
            Else
                MapX = Fix(HorizX / ObjectSize)
            End If
            
            If HorizY < 0 Then
                MapY = 0
            ElseIf HorizY > 9 * ObjectSize Then
                MapY = 9
            Else
                MapY = Fix(HorizY / ObjectSize)
            End If
           
            
            blnSomething = True
     
            Do While blnSomething = True
                If MapX < 0 Or MapX > 9 Or MapY < 0 Or MapY > 9 Then blnSomething = False
                If blnSomething = True Then
                  If LevelMap0(MapY, MapX) = vbBlue Then blnSomething = False
                End If
                If blnSomething = True Then
    
                    HorizX = HorizX + StepX
                    HorizY = HorizY + StepY
    
                    MapX = Fix((HorizX) / ObjectSize)
                    MapY = Fix((HorizY) / ObjectSize)
                End If
            Loop
            
    
            HorizDist = Abs((Player.PosX - HorizX) / Cos(RayRadians))
    
            'Check for vertical intersections:
            If RayRadians < pi / 2 Or RayRadians > 3 * pi / 2 Then 'Facing right
                AX = (Int(Player.PosX / ObjectSize) * ObjectSize) + ObjectSize ' Calculate grid position
                AY = Player.PosY + (Player.PosX - AX) * -Tan(RayRadians)
                StepX = ObjectSize
            ElseIf RayRadians = pi / 2 Or RayRadians = 3 * pi / 2 Then
                AY = Player.PosY
                AX = Player.PosX
            Else 'Facing left
                AX = (Int(Player.PosX / ObjectSize) * ObjectSize) - 1
                AY = Player.PosY + (Player.PosX - AX) * -Tan(RayRadians)
                StepX = -ObjectSize
            End If
    
    
            VertX = AX
            VertY = AY
            StepY = StepX * Tan(RayRadians)
            If VertX < 0 Then
                MapX = 0
            ElseIf VertX > 9 * ObjectSize Then
                MapX = 9
            Else
                MapX = Fix(VertX / ObjectSize)
            End If
            
            If VertY < 0 Then
                MapY = 0
            ElseIf VertY > 9 * ObjectSize Then
                MapY = 9
            Else
                MapY = Fix(VertY / ObjectSize)
            End If
            
            blnSomething = True
           Do While blnSomething = True
                If MapX < 0 Or MapX > 9 Or MapY < 0 Or MapY > 9 Then blnSomething = False
                If blnSomething = True Then
                  If LevelMap0(MapY, MapX) = vbBlue Then blnSomething = False
                End If
                If blnSomething = True Then
    
                    VertX = VertX + StepX
                    VertY = VertY + StepY
        
                    MapX = Fix((VertX) / ObjectSize)
                    MapY = Fix((VertY) / ObjectSize)
        
                End If
            Loop
    
            VertDist = Abs((Player.PosX - VertX) / Cos(RayRadians))
            
            
            'obter o a linha mais curta(horizontal ou vertical):
            If VertDist < HorizDist Then
                ' Draw the vertical ray:
                A.DrawLine Fix(Player.PosX), Fix(Player.PosY), Fix(VertX), Fix(VertY)
                WallDistance = VertDist
                
                
            Else
                ' Draw the horizontal ray:
                A.DrawLine Fix(Player.PosX), Fix(Player.PosY), Fix(HorizX), Fix(HorizY)
                
                WallDistance = HorizDist
                
                
            End If
            OffSetGrid = VertY Mod ObjectSize
            If (OffSetGrid = 0) Then OffSetGrid = VertX Mod ObjectSize
            WallDistance = WallDistance * Cos(RayRadians - Player.Radians) 'avoiding the Fish Effect
            RayHeight = (ObjectSize / WallDistance) * 200 ' is the height screen\
            picWall1.DrawTextureVerticalLine A.MemoryHDC, OffSetGrid, CLng(RayHeight), 475 + 50 + RayCounts, 60
            OffSetGrid = 0
            RayRadians = RayRadians + RadiansSteps
            
            RayCounts = RayCounts + 1
            
        Loop
    End Sub
    but i need ask: why i lose some pixels when i'm loking up?
    https://imgur.com/33mUDTb
    i'm testing and i found the problem: how we calculate, correctly the 'OffSetGrid'?
    Last edited by joaquim; Feb 3rd, 2024 at 05:56 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    Re: VB6 - raycasting: how get the image line?

    finally i fix that problem:
    Code:
    Private Sub DrawRays()
         
        Dim AY As Double
        Dim AX As Double
        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 Integer
        Dim RayCounts As Integer
        Dim blnSomething As Boolean
        Dim OffSetGrid As Long
    
        
        RayCount = 320
    
        MapX = Player.MapX
        MapY = Player.MapY
        RadiansSteps = Radian60 / 320
        
        'On Error Resume Next
        RayRadians = (Player.Radians - Radian30)
        RayCounts = 0
        Do While RayCounts < RayCount
            If (RayRadians > (2 * pi)) Then RayRadians = 0.001
            'Check for horizontal intersections:
            
            If RayRadians >= 0 And RayRadians <= pi Then 'Facing down
                AY = (Int(Player.PosY / ObjectSize) * ObjectSize) + ObjectSize ' Calculate grid position
                AX = Player.PosX + (AY - Player.PosY) / Tan(RayRadians)
                StepY = ObjectSize
            ElseIf RayRadians = 0 Or RayRadians = pi Then
                AY = Player.PosY
                AX = Player.PosX
            Else 'Facing Up
                AY = (Int(Player.PosY / ObjectSize) * ObjectSize) - 1
                AX = Player.PosX + (AY - Player.PosY) / Tan(RayRadians)
                StepY = -ObjectSize
            End If
    
    
            HorizX = AX
            HorizY = AY
            StepX = StepY / Tan(RayRadians)
            If HorizX < 0 Then
                MapX = 0
            ElseIf HorizX > 9 * ObjectSize Then
                MapX = 9
            Else
                MapX = Fix(HorizX / ObjectSize)
            End If
            
            If HorizY < 0 Then
                MapY = 0
            ElseIf HorizY > 9 * ObjectSize Then
                MapY = 9
            Else
                MapY = Fix(HorizY / ObjectSize)
            End If
           
            
            blnSomething = True
     
            Do While blnSomething = True
                If MapX < 0 Or MapX > 9 Or MapY < 0 Or MapY > 9 Then blnSomething = False
                If blnSomething = True Then
                  If LevelMap0(MapY, MapX) = vbBlue Then blnSomething = False
                End If
                If blnSomething = True Then
    
                    HorizX = HorizX + StepX
                    HorizY = HorizY + StepY
                    If ((HorizX < 0 And HorizX > 9 * ObjectSize) Or (HorizY < 0 And HorizY > 9 * ObjectSize)) Then blnSomething = False
                    MapX = Fix((HorizX) / ObjectSize)
                    MapY = Fix((HorizY) / ObjectSize)
                End If
            Loop
            
    
            HorizDist = Abs((Player.PosX - HorizX) / Cos(RayRadians))
    
            'Check for vertical intersections:
            If RayRadians < pi / 2 Or RayRadians > 3 * pi / 2 Then 'Facing right
                AX = (Int(Player.PosX / ObjectSize) * ObjectSize) + ObjectSize ' Calculate grid position
                AY = Player.PosY + (Player.PosX - AX) * -Tan(RayRadians)
                StepX = ObjectSize
            ElseIf RayRadians = pi / 2 Or RayRadians = 3 * pi / 2 Then
                AY = Player.PosY
                AX = Player.PosX
            Else 'Facing left
                AX = (Int(Player.PosX / ObjectSize) * ObjectSize) - 1
                AY = Player.PosY + (Player.PosX - AX) * -Tan(RayRadians)
                StepX = -ObjectSize
            End If
    
    
            VertX = AX
            VertY = AY
            StepY = StepX * Tan(RayRadians)
            If VertX < 0 Then
                MapX = 0
            ElseIf VertX > 9 * ObjectSize Then
                MapX = 9
            Else
                MapX = Fix(VertX / ObjectSize)
            End If
            
            If VertY < 0 Then
                MapY = 0
            ElseIf VertY > 9 * ObjectSize Then
                MapY = 9
            Else
                MapY = Fix(VertY / ObjectSize)
            End If
            
            blnSomething = True
           Do While blnSomething = True
                If MapX < 0 Or MapX > 9 Or MapY < 0 Or MapY > 9 Then blnSomething = False
                If blnSomething = True Then
                  If LevelMap0(MapY, MapX) = vbBlue Then blnSomething = False
                End If
                If blnSomething = True Then
                    
                    VertX = VertX + StepX
                    VertY = VertY + StepY
                    If ((VertY < 0 And VertY > 9 * ObjectSize) Or (VertX < 0 Or VertX > 9 * ObjectSize)) Then blnSomething = False
                    MapX = Fix((VertX) / ObjectSize)
                    MapY = Fix((VertY) / ObjectSize)
        
                End If
            Loop
    
            VertDist = Abs((Player.PosX - VertX) / Cos(RayRadians))
            
            
            'obter o a linha mais curta(horizontal ou vertical):
            If VertDist < HorizDist Then
                ' Draw the vertical ray:
                A.DrawLine Fix(Player.PosX), Fix(Player.PosY), Fix(VertX), Fix(VertY)
                WallDistance = VertDist
                OffSetGrid = VertY - (Int(VertY / ObjectSize) * ObjectSize)
                
            Else
                ' Draw the horizontal ray:
                A.DrawLine Fix(Player.PosX), Fix(Player.PosY), Fix(HorizX), Fix(HorizY)
                OffSetGrid = HorizX - (Int(HorizX / ObjectSize) * ObjectSize)
                WallDistance = HorizDist
                
            End If
            
            WallDistance = WallDistance * 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 A.MemoryHDC, OffSetGrid, CLng(RayHeight), 475 + 50 + RayCounts, 60
            OffSetGrid = 0
            RayRadians = RayRadians + RadiansSteps
            
            RayCounts = RayCounts + 1
            
        Loop
    End Sub
    the problem was here:
    Code:
    'obter o a linha mais curta(horizontal ou vertical):
            If VertDist < HorizDist Then
                ' Draw the vertical ray:
                A.DrawLine Fix(Player.PosX), Fix(Player.PosY), Fix(VertX), Fix(VertY)
                WallDistance = VertDist
                OffSetGrid = VertY - (Int(VertY / ObjectSize) * ObjectSize) 'here fixed
                
            Else
                ' Draw the horizontal ray:
                A.DrawLine Fix(Player.PosX), Fix(Player.PosY), Fix(HorizX), Fix(HorizY)
                OffSetGrid = HorizX - (Int(HorizX / ObjectSize) * ObjectSize) 'here fixed
                WallDistance = HorizDist
                
            End If
    i getted the AI help
    now i must fix a bug, because some vertical lines(on square limites) are printed in a different angle\position:
    https://imgur.com/SPP20UD
    here i notice:
    1 - on Horizontal Intersection, between PI and zero, these bug happens;
    2 - on Vertical Intersection, between PI/2 and 3*PI/2, these bug happens...
    how can i fix it?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    Re: VB6 - raycasting: how get the image line?

    heres another print: https://imgur.com/iCCH5zy
    you see a different color on same vertical(or even horizontal) walls... it happens on object size
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: VB6 - raycasting: how get the image line?

    Assuming you have ZBuffering, some of your polygons are overlapping past the corners. Polygon piercing is common in that regard. Similar to a triangle stabbing into another like a knife. Or a wall sticking through another. Check if it is either that or don't round your numbers and keep them in double precision form.

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    Re: VB6 - raycasting: how get the image line?

    what i only know is:
    Code:
    OffSetGrid = HorizX - (Int(HorizX / ObjectSize) * ObjectSize)
    give me the X object vertical line.... is for texture.... but if OffSetGrid is the object width, these bug happens... i was trying avoiding these bug, but i only get:
    - an empty vertical line(at least no bug kkkk);
    - nothing is drawed(here is try
    Code:
    If (OffSetGrid < 0 Or OffSetGrid >= picWall1.Width) Then RayCounts = RayCounts + 1
    i must review the idea.. but tell me more please
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: VB6 - raycasting: how get the image line?

    Your empty vertical line appears to be the pierced wall. Which means your values are off for sure. Try calculating it by hand before you code it. Its how I sometimes fix my bugs lol.

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    Re: VB6 - raycasting: how get the image line?

    endeed lol
    but why, on basic, that happens?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  9. #9
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: VB6 - raycasting: how get the image line?

    It doesn't matter what language you use. The math is what matters in the end. Like I said do the math by hand. In this case, have the camera be top view as you calculate. If any poly is sticking out of a wall, you'll know where it faulted. Never assume the code you got from a book / website, or even code from AI works right off the bat. Do it by hand and visually see it.

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    Re: VB6 - raycasting: how get the image line?

    from what you said, i did these print:
    Code:
    Wall Height: 1231,6805742712	OffSetGrid: 7
    Wall Height: 1222,38967241935	OffSetGrid: 7
    Wall Height: 1213,13354863251	OffSetGrid: 7
    Wall Height: 1203,91181085628	OffSetGrid: 7
    Wall Height: 1194,72407141136	OffSetGrid: 7
    Wall Height: 1185,56994692283	OffSetGrid: 7
    Wall Height: 1176,44905825067	OffSetGrid: 7
    Wall Height: 1167,36103042159	OffSetGrid: 7
    Wall Height: 1158,305492562	OffSetGrid: 8
    Wall Height: 1149,28207783219	OffSetGrid: 8
    Wall Height: 1140,29042336169	OffSetGrid: 8
    Wall Height: 1131,33017018577	OffSetGrid: 8
    Wall Height: 1122,40096318301	OffSetGrid: 8
    Wall Height: 1113,50245101401	OffSetGrid: 8
    Wall Height: 1104,63428606116	OffSetGrid: 8
    Wall Height: 1095,79612436942	OffSetGrid: 8
    Wall Height: 1086,98762558811	OffSetGrid: 8
    Wall Height: 1078,20845291382	OffSetGrid: 8
    Wall Height: 1069,45827303413	OffSetGrid: 8
    Wall Height: 1060,73675607239	OffSetGrid: 8
    Wall Height: 1052,04357553345	OffSetGrid: 8
    Wall Height: 1043,37840825022	OffSetGrid: 8
    Wall Height: 1034,74093433124	OffSetGrid: 8
    Wall Height: 1026,13083710904	OffSetGrid: 8
    Wall Height: 1017,54780308941	OffSetGrid: 8
    Wall Height: 1008,99152190148	OffSetGrid: 8
    Wall Height: 1000,4616862487	OffSetGrid: 8
    Wall Height: 991,957991860514	OffSetGrid: 8
    Wall Height: 983,480137444944	OffSetGrid: 9
    Wall Height: 975,027824641863	OffSetGrid: 9
    Wall Height: 966,600757977076	OffSetGrid: 9
    Wall Height: 958,198644817135	OffSetGrid: 9
    Wall Height: 949,821195324875	OffSetGrid: 9
    Wall Height: 941,468122415675	OffSetGrid: 9
    Wall Height: 933,139141714413	OffSetGrid: 9
    Wall Height: 924,833971513111	OffSetGrid: 9
    Wall Height: 916,552332729248	OffSetGrid: 9
    Wall Height: 908,293948864736	OffSetGrid: 9
    Wall Height: 900,058545965535	OffSetGrid: 9
    Wall Height: 891,845852581903	OffSetGrid: 9
    Wall Height: 883,655599729268	OffSetGrid: 9
    Wall Height: 875,487520849699	OffSetGrid: 9
    Wall Height: 867,341351773979	OffSetGrid: 9
    Wall Height: 859,216830684257	OffSetGrid: 9
    Wall Height: 851,113698077266	OffSetGrid: 10
    Wall Height: 843,03169672811	OffSetGrid: 10
    Wall Height: 834,970571654591	OffSetGrid: 10
    Wall Height: 826,930070082074	OffSetGrid: 10
    Wall Height: 818,909941408885	OffSetGrid: 10
    Wall Height: 810,909937172211	OffSetGrid: 10
    Wall Height: 802,929811014521	OffSetGrid: 10
    Wall Height: 794,96931865047	OffSetGrid: 10
    Wall Height: 787,028217834295	OffSetGrid: 10
    Wall Height: 779,106268327686	OffSetGrid: 10
    Wall Height: 771,203231868119	OffSetGrid: 10
    Wall Height: 763,318872137649	OffSetGrid: 10
    Wall Height: 755,452954732153	OffSetGrid: 10
    Wall Height: 747,605247131009	OffSetGrid: 11
    Wall Height: 739,775518667203	OffSetGrid: 11
    Wall Height: 731,963540497862	OffSetGrid: 11
    Wall Height: 724,169085575199	OffSetGrid: 11
    Wall Height: 716,391928617863	OffSetGrid: 11
    Wall Height: 708,631846082681	OffSetGrid: 11
    Wall Height: 700,8886161368	OffSetGrid: 11
    Wall Height: 693,162018630197	OffSetGrid: 11
    Wall Height: 685,451835068576	OffSetGrid: 11
    Wall Height: 677,757848586618	OffSetGrid: 11
    Wall Height: 670,079843921602	OffSetGrid: 12
    Wall Height: 662,41760738737	OffSetGrid: 12
    Wall Height: 654,770926848641	OffSetGrid: 12
    Wall Height: 647,139591695661	OffSetGrid: 12
    Wall Height: 639,52339281918	OffSetGrid: 12
    Wall Height: 631,922122585768	OffSetGrid: 12
    Wall Height: 624,335574813428	OffSetGrid: 12
    Wall Height: 616,76354474754	OffSetGrid: 12
    Wall Height: 609,205829037099	OffSetGrid: 13
    Wall Height: 601,662225711257	OffSetGrid: 13
    Wall Height: 594,132534156153	OffSetGrid: 13
    Wall Height: 586,616555092042	OffSetGrid: 13
    Wall Height: 579,11409055069	OffSetGrid: 13
    Wall Height: 571,624943853058	OffSetGrid: 13
    Wall Height: 564,148919587248	OffSetGrid: 13
    Wall Height: 556,685823586719	OffSetGrid: 13
    Wall Height: 549,235462908759	OffSetGrid: 14
    Wall Height: 541,79764581321	OffSetGrid: 14
    Wall Height: 534,372181741448	OffSetGrid: 14
    Wall Height: 526,958881295602	OffSetGrid: 14
    Wall Height: 519,557556218009	OffSetGrid: 14
    Wall Height: 512,168019370911	OffSetGrid: 14
    Wall Height: 504,79008471637	OffSetGrid: 15
    Wall Height: 497,42356729642	OffSetGrid: 15
    Wall Height: 490,068283213425	OffSetGrid: 15
    Wall Height: 482,724049610665	OffSetGrid: 15
    Wall Height: 475,390684653117	OffSetGrid: 15
    Wall Height: 468,068007508459	OffSetGrid: 16
    Wall Height: 460,75583832826	OffSetGrid: 16
    Wall Height: 453,453998229377	OffSetGrid: 16
    Wall Height: 446,16230927554	OffSetGrid: 16
    Wall Height: 438,880594459128	OffSetGrid: 17
    Wall Height: 431,608677683125	OffSetGrid: 17
    Wall Height: 424,346383743267	OffSetGrid: 17
    Wall Height: 417,09353831035	OffSetGrid: 17
    Wall Height: 409,849967912723	OffSetGrid: 18
    Wall Height: 402,615499918944	OffSetGrid: 18
    Wall Height: 395,389962520604	OffSetGrid: 18
    Wall Height: 388,173184715305	OffSetGrid: 18
    Wall Height: 380,964996289807	OffSetGrid: 19
    Wall Height: 373,765227803316	OffSetGrid: 19
    Wall Height: 366,573710570931	OffSetGrid: 19
    Wall Height: 359,390276647232	OffSetGrid: 20
    Wall Height: 352,214758810016	OffSetGrid: 20
    Wall Height: 345,046990544169	OffSetGrid: 21
    Wall Height: 337,886806025675	OffSetGrid: 21
    Wall Height: 330,734040105754	OffSetGrid: 21
    Wall Height: 323,588528295139	OffSetGrid: 22
    Wall Height: 316,450106748472	OffSetGrid: 22
    Wall Height: 309,318612248819	OffSetGrid: 23
    Wall Height: 302,193882192318	OffSetGrid: 23
    Wall Height: 295,075754572928	OffSetGrid: 24
    Wall Height: 287,964067967304	OffSetGrid: 24
    Wall Height: 280,858661519775	OffSetGrid: 25
    Wall Height: 273,759374927434	OffSetGrid: 25
    Wall Height: 266,666048425328	OffSetGrid: 26
    Wall Height: 259,57852277175	OffSetGrid: 27
    Wall Height: 252,496639233635	OffSetGrid: 27
    Wall Height: 245,420239572047	OffSetGrid: 28
    Wall Height: 238,349166027753	OffSetGrid: 29
    Wall Height: 231,283261306902	OffSetGrid: 30
    Wall Height: 224,222368566774	OffSetGrid: 31
    Wall Height: 217,166331401626	OffSetGrid: 31
    Wall Height: 213,333333333333	OffSetGrid: 31
    Wall Height: 213,333333333333	OffSetGrid: 31
    Wall Height: 213,333333333333	OffSetGrid: 31
    Wall Height: 213,333333333333	OffSetGrid: 31
    Wall Height: 213,333333333333	OffSetGrid: 31
    Wall Height: 174,923368291323	OffSetGrid: 7
    Wall Height: 167,896974559183	OffSetGrid: 8
    Wall Height: 160,874199213759	OffSetGrid: 10
    Wall Height: 153,854889157485	OffSetGrid: 12
    Wall Height: 146,838891592221	OffSetGrid: 14
    Wall Height: 139,826054005839	OffSetGrid: 16
    Wall Height: 132,816224158869	OffSetGrid: 18
    Wall Height: 125,809250071192	OffSetGrid: 21
    Wall Height: 118,804980008781	OffSetGrid: 24
    Wall Height: 111,803262470485	OffSetGrid: 27
    Wall Height: 104,803946174861	OffSetGrid: 31
    Wall Height: 103,225806451613	OffSetGrid: 31
    Wall Height: 103,225806451613	OffSetGrid: 31
    Wall Height: 83,8188949496925	OffSetGrid: 14
    Wall Height: 76,8276747456444	OffSetGrid: 21
    Wall Height: 69,8381022143388	OffSetGrid: 30
    Wall Height: 68,0851063829787	OffSetGrid: 31
    Wall Height: 55,863299347596	OffSetGrid: 21
    Wall Height: 50,7936507936508	OffSetGrid: 31
    Wall Height: 41,8932859122681	OffSetGrid: 27
    Wall Height: 40,5063291139241	OffSetGrid: 31
    Wall Height: 28,8288288288288	OffSetGrid: 31
    Wall Height: 25,1968503937008	OffSetGrid: 32
    Wall Height: 25,1968503937008	OffSetGrid: 0
    Wall Height: 25,1968503937008	OffSetGrid: 1
    Wall Height: 25,1968503937008	OffSetGrid: 2
    Wall Height: 25,1968503937008	OffSetGrid: 3
    Wall Height: 25,1968503937008	OffSetGrid: 4
    Wall Height: 25,1968503937008	OffSetGrid: 4
    Wall Height: 25,1968503937008	OffSetGrid: 5
    Wall Height: 25,1968503937008	OffSetGrid: 6
    Wall Height: 25,1968503937008	OffSetGrid: 7
    Wall Height: 25,1968503937008	OffSetGrid: 8
    Wall Height: 25,1968503937008	OffSetGrid: 9
    Wall Height: 25,1968503937008	OffSetGrid: 9
    Wall Height: 25,1968503937008	OffSetGrid: 10
    Wall Height: 25,1968503937008	OffSetGrid: 11
    Wall Height: 25,1968503937008	OffSetGrid: 12
    Wall Height: 25,1968503937008	OffSetGrid: 13
    Wall Height: 25,1968503937008	OffSetGrid: 14
    Wall Height: 25,1968503937008	OffSetGrid: 14
    Wall Height: 25,1968503937008	OffSetGrid: 15
    Wall Height: 25,1968503937008	OffSetGrid: 16
    Wall Height: 25,1968503937008	OffSetGrid: 17
    Wall Height: 25,1968503937008	OffSetGrid: 18
    Wall Height: 25,1968503937008	OffSetGrid: 19
    Wall Height: 25,1968503937008	OffSetGrid: 19
    Wall Height: 25,1968503937008	OffSetGrid: 20
    Wall Height: 25,1968503937008	OffSetGrid: 21
    Wall Height: 25,1968503937008	OffSetGrid: 22
    Wall Height: 25,1968503937008	OffSetGrid: 23
    Wall Height: 25,1968503937008	OffSetGrid: 24
    Wall Height: 25,1968503937008	OffSetGrid: 25
    Wall Height: 25,1968503937008	OffSetGrid: 25
    Wall Height: 25,1968503937008	OffSetGrid: 26
    Wall Height: 25,1968503937008	OffSetGrid: 27
    Wall Height: 25,1968503937008	OffSetGrid: 28
    Wall Height: 25,1968503937008	OffSetGrid: 29
    Wall Height: 25,1968503937008	OffSetGrid: 30
    Wall Height: 25,1968503937008	OffSetGrid: 30
    Wall Height: 25,1968503937008	OffSetGrid: 31
    Wall Height: 25,1968503937008	OffSetGrid: 0
    Wall Height: 25,1968503937008	OffSetGrid: 1
    Wall Height: 25,1968503937008	OffSetGrid: 2
    Wall Height: 25,1968503937008	OffSetGrid: 3
    Wall Height: 25,1968503937008	OffSetGrid: 3
    Wall Height: 25,1968503937008	OffSetGrid: 4
    Wall Height: 25,1968503937008	OffSetGrid: 5
    Wall Height: 25,1968503937008	OffSetGrid: 6
    Wall Height: 25,1968503937008	OffSetGrid: 7
    Wall Height: 25,1968503937008	OffSetGrid: 8
    Wall Height: 25,1968503937008	OffSetGrid: 9
    Wall Height: 25,1968503937008	OffSetGrid: 9
    Wall Height: 25,1968503937008	OffSetGrid: 10
    Wall Height: 25,1968503937008	OffSetGrid: 11
    Wall Height: 25,1968503937008	OffSetGrid: 12
    Wall Height: 25,1968503937008	OffSetGrid: 13
    Wall Height: 25,1968503937008	OffSetGrid: 14
    Wall Height: 25,1968503937008	OffSetGrid: 15
    Wall Height: 25,1968503937008	OffSetGrid: 15
    Wall Height: 25,1968503937008	OffSetGrid: 16
    Wall Height: 25,1968503937008	OffSetGrid: 17
    Wall Height: 25,1968503937008	OffSetGrid: 18
    Wall Height: 40,9849967912728	OffSetGrid: 30
    Wall Height: 41,7093538310356	OffSetGrid: 27
    Wall Height: 42,4346383743273	OffSetGrid: 25
    Wall Height: 43,1608677683131	OffSetGrid: 22
    Wall Height: 43,8880594459133	OffSetGrid: 20
    Wall Height: 44,6162309275546	OffSetGrid: 17
    Wall Height: 45,3453998229383	OffSetGrid: 15
    Wall Height: 46,0755838328266	OffSetGrid: 13
    Wall Height: 46,8068007508465	OffSetGrid: 11
    Wall Height: 47,5390684653123	OffSetGrid: 9
    Wall Height: 48,2724049610671	OffSetGrid: 7
    Wall Height: 49,0068283213431	OffSetGrid: 5
    Wall Height: 49,7423567296426	OffSetGrid: 3
    Wall Height: 50,7936507936508	OffSetGrid: 32
    Wall Height: 50,7936507936508	OffSetGrid: 0
    Wall Height: 50,7936507936508	OffSetGrid: 1
    Wall Height: 50,7936507936508	OffSetGrid: 1
    Wall Height: 50,7936507936508	OffSetGrid: 2
    Wall Height: 50,7936507936508	OffSetGrid: 2
    Wall Height: 50,7936507936508	OffSetGrid: 2
    Wall Height: 50,7936507936508	OffSetGrid: 3
    Wall Height: 50,7936507936508	OffSetGrid: 3
    Wall Height: 50,7936507936508	OffSetGrid: 4
    Wall Height: 50,7936507936508	OffSetGrid: 4
    Wall Height: 50,7936507936508	OffSetGrid: 5
    Wall Height: 50,7936507936508	OffSetGrid: 5
    Wall Height: 50,7936507936508	OffSetGrid: 6
    Wall Height: 50,7936507936508	OffSetGrid: 6
    Wall Height: 50,7936507936508	OffSetGrid: 6
    Wall Height: 50,7936507936508	OffSetGrid: 7
    Wall Height: 50,7936507936508	OffSetGrid: 7
    Wall Height: 50,7936507936508	OffSetGrid: 8
    Wall Height: 50,7936507936508	OffSetGrid: 8
    Wall Height: 50,7936507936508	OffSetGrid: 9
    Wall Height: 50,7936507936508	OffSetGrid: 9
    Wall Height: 50,7936507936508	OffSetGrid: 10
    Wall Height: 50,7936507936508	OffSetGrid: 10
    Wall Height: 68,5451835068582	OffSetGrid: 31
    Wall Height: 69,3162018630203	OffSetGrid: 30
    Wall Height: 70,0888616136806	OffSetGrid: 29
    Wall Height: 70,8631846082687	OffSetGrid: 28
    Wall Height: 71,6391928617869	OffSetGrid: 27
    Wall Height: 72,4169085575205	OffSetGrid: 26
    Wall Height: 73,1963540497868	OffSetGrid: 25
    Wall Height: 73,9775518667209	OffSetGrid: 25
    Wall Height: 74,7605247131015	OffSetGrid: 24
    Wall Height: 75,5452954732159	OffSetGrid: 23
    Wall Height: 76,3318872137655	OffSetGrid: 22
    Wall Height: 77,1203231868125	OffSetGrid: 21
    Wall Height: 77,9106268327693	OffSetGrid: 20
    Wall Height: 78,7028217834302	OffSetGrid: 19
    Wall Height: 79,4969318650476	OffSetGrid: 19
    Wall Height: 80,2929811014527	OffSetGrid: 18
    Wall Height: 81,0909937172217	OffSetGrid: 17
    Wall Height: 81,8909941408891	OffSetGrid: 16
    Wall Height: 82,6930070082081	OffSetGrid: 15
    Wall Height: 83,4970571654597	OffSetGrid: 15
    Wall Height: 84,3031696728116	OffSetGrid: 14
    Wall Height: 85,1113698077272	OffSetGrid: 13
    Wall Height: 85,9216830684263	OffSetGrid: 12
    Wall Height: 86,7341351773986	OffSetGrid: 12
    Wall Height: 87,5487520849705	OffSetGrid: 11
    Wall Height: 88,3655599729274	OffSetGrid: 10
    Wall Height: 89,1845852581909	OffSetGrid: 10
    Wall Height: 90,0058545965541	OffSetGrid: 9
    Wall Height: 90,8293948864743	OffSetGrid: 8
    Wall Height: 91,6552332729255	OffSetGrid: 8
    Wall Height: 92,4833971513118	OffSetGrid: 7
    Wall Height: 93,313914171442	OffSetGrid: 7
    Wall Height: 94,1468122415682	OffSetGrid: 6
    Wall Height: 94,9821195324882	OffSetGrid: 5
    Wall Height: 95,8198644817142	OffSetGrid: 5
    Wall Height: 96,6600757977083	OffSetGrid: 4
    Wall Height: 97,5027824641869	OffSetGrid: 4
    Wall Height: 98,3480137444951	OffSetGrid: 3
    Wall Height: 99,1957991860521	OffSetGrid: 3
    Wall Height: 100,04616862487	OffSetGrid: 2
    Wall Height: 100,899152190149	OffSetGrid: 1
    Wall Height: 103,225806451613	OffSetGrid: 32
    Wall Height: 103,225806451613	OffSetGrid: 32
    Wall Height: 103,474093433125	OffSetGrid: 32
    Wall Height: 103,225806451613	OffSetGrid: 0
    Wall Height: 103,225806451613	OffSetGrid: 1
    Wall Height: 103,225806451613	OffSetGrid: 1
    Wall Height: 103,225806451613	OffSetGrid: 1
    Wall Height: 103,225806451613	OffSetGrid: 1
    Wall Height: 103,225806451613	OffSetGrid: 2
    Wall Height: 103,225806451613	OffSetGrid: 2
    Wall Height: 103,225806451613	OffSetGrid: 2
    Wall Height: 103,225806451613	OffSetGrid: 2
    Wall Height: 103,225806451613	OffSetGrid: 3
    Wall Height: 103,225806451613	OffSetGrid: 3
    Wall Height: 103,225806451613	OffSetGrid: 3
    Wall Height: 103,225806451613	OffSetGrid: 3
    Wall Height: 103,225806451613	OffSetGrid: 4
    Wall Height: 103,225806451613	OffSetGrid: 4
    Wall Height: 103,225806451613	OffSetGrid: 4
    Wall Height: 103,225806451613	OffSetGrid: 4
    Wall Height: 103,225806451613	OffSetGrid: 5
    Wall Height: 103,225806451613	OffSetGrid: 5
    Wall Height: 103,225806451613	OffSetGrid: 5
    Wall Height: 103,225806451613	OffSetGrid: 6
    like you see the Wall Height with same OffSetGrid, repeats several times....
    seen these part of function:
    Code:
    WallDistance = WallDistance * Math.Cos(RayRadians - player.Radians) 'avoiding the Fish Effect
                RayHeight = (ObjectSize / WallDistance) * 200 ' is the height screen\
                Debug.Print("Wall Height: " & CStr(RayHeight) & vbTab & "OffSetGrid: " & OffSetGrid)
                '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
            Application.Exit()
    how can avoid:
    1 - 'RayCounts' counted;
    2 - loop repeating without finished;
    3 - vertical empty line...
    ?????
    VB6 2D Sprite control

    To live is difficult, but we do it.

  11. #11

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    Re: VB6 - raycasting: how get the image line?

    and more printed:
    Code:
    PosX2: 39	Pos2Y: 31
    PosX2: 39	Pos2Y: 31
    PosX2: 39	Pos2Y: 31
    PosX2: 39	Pos2Y: 31
    PosX2: 39	Pos2Y: 31
    PosX2: 39	Pos2Y: 31
    PosX2: 39	Pos2Y: 31
    PosX2: 39	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 40	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 41	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 42	Pos2Y: 31
    PosX2: 43	Pos2Y: 31
    PosX2: 43	Pos2Y: 31
    PosX2: 43	Pos2Y: 31
    PosX2: 43	Pos2Y: 31
    PosX2: 43	Pos2Y: 31
    PosX2: 43	Pos2Y: 31
    PosX2: 43	Pos2Y: 31
    PosX2: 43	Pos2Y: 31
    PosX2: 43	Pos2Y: 31
    PosX2: 43	Pos2Y: 31
    PosX2: 44	Pos2Y: 31
    PosX2: 44	Pos2Y: 31
    PosX2: 44	Pos2Y: 31
    PosX2: 44	Pos2Y: 31
    PosX2: 44	Pos2Y: 31
    PosX2: 44	Pos2Y: 31
    PosX2: 44	Pos2Y: 31
    PosX2: 44	Pos2Y: 31
    PosX2: 45	Pos2Y: 31
    PosX2: 45	Pos2Y: 31
    PosX2: 45	Pos2Y: 31
    PosX2: 45	Pos2Y: 31
    PosX2: 45	Pos2Y: 31
    PosX2: 45	Pos2Y: 31
    PosX2: 45	Pos2Y: 31
    PosX2: 45	Pos2Y: 31
    PosX2: 46	Pos2Y: 31
    PosX2: 46	Pos2Y: 31
    PosX2: 46	Pos2Y: 31
    PosX2: 46	Pos2Y: 31
    PosX2: 46	Pos2Y: 31
    PosX2: 46	Pos2Y: 31
    PosX2: 47	Pos2Y: 31
    PosX2: 47	Pos2Y: 31
    PosX2: 47	Pos2Y: 31
    PosX2: 47	Pos2Y: 31
    PosX2: 47	Pos2Y: 31
    PosX2: 48	Pos2Y: 31
    PosX2: 48	Pos2Y: 31
    PosX2: 48	Pos2Y: 31
    PosX2: 48	Pos2Y: 31
    PosX2: 49	Pos2Y: 31
    PosX2: 49	Pos2Y: 31
    PosX2: 49	Pos2Y: 31
    PosX2: 49	Pos2Y: 31
    PosX2: 50	Pos2Y: 31
    PosX2: 50	Pos2Y: 31
    PosX2: 50	Pos2Y: 31
    PosX2: 50	Pos2Y: 31
    PosX2: 51	Pos2Y: 31
    PosX2: 51	Pos2Y: 31
    PosX2: 51	Pos2Y: 31
    PosX2: 52	Pos2Y: 31
    PosX2: 52	Pos2Y: 31
    PosX2: 53	Pos2Y: 31
    PosX2: 53	Pos2Y: 31
    PosX2: 53	Pos2Y: 31
    PosX2: 54	Pos2Y: 31
    PosX2: 54	Pos2Y: 31
    PosX2: 55	Pos2Y: 31
    PosX2: 55	Pos2Y: 31
    PosX2: 56	Pos2Y: 31
    PosX2: 56	Pos2Y: 31
    PosX2: 57	Pos2Y: 31
    PosX2: 57	Pos2Y: 31
    PosX2: 58	Pos2Y: 31
    PosX2: 59	Pos2Y: 31
    PosX2: 59	Pos2Y: 31
    PosX2: 60	Pos2Y: 31
    PosX2: 61	Pos2Y: 31
    PosX2: 62	Pos2Y: 31
    PosX2: 63	Pos2Y: 31
    PosX2: 63	Pos2Y: 31
    PosX2: 64	Pos2Y: 31
    PosX2: 64	Pos2Y: 31
    PosX2: 64	Pos2Y: 31
    PosX2: 64	Pos2Y: 31
    PosX2: 64	Pos2Y: 31
    PosX2: 71	Pos2Y: 31
    PosX2: 72	Pos2Y: 31
    PosX2: 74	Pos2Y: 31
    PosX2: 76	Pos2Y: 31
    PosX2: 78	Pos2Y: 31
    PosX2: 80	Pos2Y: 31
    PosX2: 82	Pos2Y: 31
    PosX2: 85	Pos2Y: 31
    PosX2: 88	Pos2Y: 31
    PosX2: 91	Pos2Y: 31
    PosX2: 95	Pos2Y: 31
    PosX2: 96	Pos2Y: 31
    PosX2: 96	Pos2Y: 31
    PosX2: 110	Pos2Y: 31
    PosX2: 117	Pos2Y: 31
    PosX2: 126	Pos2Y: 31
    PosX2: 128	Pos2Y: 31
    PosX2: 149	Pos2Y: 31
    PosX2: 160	Pos2Y: 31
    PosX2: 187	Pos2Y: 31
    PosX2: 192	Pos2Y: 31
    PosX2: 256	Pos2Y: 31
    PosX2: 288	Pos2Y: 32
    PosX2: 288	Pos2Y: 32
    PosX2: 288	Pos2Y: 33
    PosX2: 288	Pos2Y: 34
    PosX2: 288	Pos2Y: 35
    PosX2: 288	Pos2Y: 36
    PosX2: 288	Pos2Y: 36
    PosX2: 288	Pos2Y: 37
    PosX2: 288	Pos2Y: 38
    PosX2: 288	Pos2Y: 39
    PosX2: 288	Pos2Y: 40
    PosX2: 288	Pos2Y: 41
    PosX2: 288	Pos2Y: 41
    PosX2: 288	Pos2Y: 42
    PosX2: 288	Pos2Y: 43
    PosX2: 288	Pos2Y: 44
    PosX2: 288	Pos2Y: 45
    PosX2: 288	Pos2Y: 46
    PosX2: 288	Pos2Y: 46
    PosX2: 288	Pos2Y: 47
    PosX2: 288	Pos2Y: 48
    PosX2: 288	Pos2Y: 49
    PosX2: 288	Pos2Y: 50
    PosX2: 288	Pos2Y: 51
    PosX2: 288	Pos2Y: 51
    PosX2: 288	Pos2Y: 52
    PosX2: 288	Pos2Y: 53
    PosX2: 288	Pos2Y: 54
    PosX2: 288	Pos2Y: 55
    PosX2: 288	Pos2Y: 56
    PosX2: 288	Pos2Y: 57
    PosX2: 288	Pos2Y: 57
    PosX2: 288	Pos2Y: 58
    PosX2: 288	Pos2Y: 59
    PosX2: 288	Pos2Y: 60
    PosX2: 288	Pos2Y: 61
    PosX2: 288	Pos2Y: 62
    PosX2: 288	Pos2Y: 62
    PosX2: 288	Pos2Y: 63
    PosX2: 288	Pos2Y: 64
    PosX2: 288	Pos2Y: 65
    PosX2: 288	Pos2Y: 66
    PosX2: 288	Pos2Y: 67
    PosX2: 288	Pos2Y: 67
    PosX2: 288	Pos2Y: 68
    PosX2: 288	Pos2Y: 69
    PosX2: 288	Pos2Y: 70
    PosX2: 288	Pos2Y: 71
    PosX2: 288	Pos2Y: 72
    PosX2: 288	Pos2Y: 73
    PosX2: 288	Pos2Y: 73
    PosX2: 288	Pos2Y: 74
    PosX2: 288	Pos2Y: 75
    PosX2: 288	Pos2Y: 76
    PosX2: 288	Pos2Y: 77
    PosX2: 288	Pos2Y: 78
    PosX2: 288	Pos2Y: 79
    PosX2: 288	Pos2Y: 79
    PosX2: 288	Pos2Y: 80
    PosX2: 288	Pos2Y: 81
    PosX2: 288	Pos2Y: 82
    PosX2: 190	Pos2Y: 64
    PosX2: 187	Pos2Y: 64
    PosX2: 185	Pos2Y: 64
    PosX2: 182	Pos2Y: 64
    PosX2: 180	Pos2Y: 64
    PosX2: 177	Pos2Y: 64
    PosX2: 175	Pos2Y: 64
    PosX2: 173	Pos2Y: 64
    PosX2: 171	Pos2Y: 64
    PosX2: 169	Pos2Y: 64
    PosX2: 167	Pos2Y: 64
    PosX2: 165	Pos2Y: 64
    PosX2: 163	Pos2Y: 64
    PosX2: 160	Pos2Y: 64
    PosX2: 160	Pos2Y: 64
    PosX2: 160	Pos2Y: 65
    PosX2: 160	Pos2Y: 65
    PosX2: 160	Pos2Y: 66
    PosX2: 160	Pos2Y: 66
    PosX2: 160	Pos2Y: 66
    PosX2: 160	Pos2Y: 67
    PosX2: 160	Pos2Y: 67
    PosX2: 160	Pos2Y: 68
    PosX2: 160	Pos2Y: 68
    PosX2: 160	Pos2Y: 69
    PosX2: 160	Pos2Y: 69
    PosX2: 160	Pos2Y: 70
    PosX2: 160	Pos2Y: 70
    PosX2: 160	Pos2Y: 70
    PosX2: 160	Pos2Y: 71
    PosX2: 160	Pos2Y: 71
    PosX2: 160	Pos2Y: 72
    PosX2: 160	Pos2Y: 72
    PosX2: 160	Pos2Y: 73
    PosX2: 160	Pos2Y: 73
    PosX2: 160	Pos2Y: 74
    PosX2: 160	Pos2Y: 74
    PosX2: 127	Pos2Y: 64
    PosX2: 126	Pos2Y: 64
    PosX2: 125	Pos2Y: 64
    PosX2: 124	Pos2Y: 64
    PosX2: 123	Pos2Y: 64
    PosX2: 122	Pos2Y: 64
    PosX2: 121	Pos2Y: 64
    PosX2: 121	Pos2Y: 64
    PosX2: 120	Pos2Y: 64
    PosX2: 119	Pos2Y: 64
    PosX2: 118	Pos2Y: 64
    PosX2: 117	Pos2Y: 64
    PosX2: 116	Pos2Y: 64
    PosX2: 115	Pos2Y: 64
    PosX2: 115	Pos2Y: 64
    PosX2: 114	Pos2Y: 64
    PosX2: 113	Pos2Y: 64
    PosX2: 112	Pos2Y: 64
    PosX2: 111	Pos2Y: 64
    PosX2: 111	Pos2Y: 64
    PosX2: 110	Pos2Y: 64
    PosX2: 109	Pos2Y: 64
    PosX2: 108	Pos2Y: 64
    PosX2: 108	Pos2Y: 64
    PosX2: 107	Pos2Y: 64
    PosX2: 106	Pos2Y: 64
    PosX2: 106	Pos2Y: 64
    PosX2: 105	Pos2Y: 64
    PosX2: 104	Pos2Y: 64
    PosX2: 104	Pos2Y: 64
    PosX2: 103	Pos2Y: 64
    PosX2: 103	Pos2Y: 64
    PosX2: 102	Pos2Y: 64
    PosX2: 101	Pos2Y: 64
    PosX2: 101	Pos2Y: 64
    PosX2: 100	Pos2Y: 64
    PosX2: 100	Pos2Y: 64
    PosX2: 99	Pos2Y: 64
    PosX2: 99	Pos2Y: 64
    PosX2: 98	Pos2Y: 64
    PosX2: 97	Pos2Y: 64
    PosX2: 96	Pos2Y: 64
    PosX2: 96	Pos2Y: 64
    PosX2: 96	Pos2Y: 64
    PosX2: 96	Pos2Y: 64
    PosX2: 96	Pos2Y: 65
    PosX2: 96	Pos2Y: 65
    PosX2: 96	Pos2Y: 65
    PosX2: 96	Pos2Y: 65
    PosX2: 96	Pos2Y: 66
    PosX2: 96	Pos2Y: 66
    PosX2: 96	Pos2Y: 66
    PosX2: 96	Pos2Y: 66
    PosX2: 96	Pos2Y: 67
    PosX2: 96	Pos2Y: 67
    PosX2: 96	Pos2Y: 67
    PosX2: 96	Pos2Y: 67
    PosX2: 96	Pos2Y: 68
    PosX2: 96	Pos2Y: 68
    PosX2: 96	Pos2Y: 68
    PosX2: 96	Pos2Y: 68
    PosX2: 96	Pos2Y: 69
    PosX2: 96	Pos2Y: 69
    PosX2: 96	Pos2Y: 69
    PosX2: 96	Pos2Y: 70
    some lines can be avoided... right?
    Last edited by joaquim; Mar 25th, 2024 at 04:24 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  12. #12
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: VB6 - raycasting: how get the image line?

    Sure you printed the results but what do you want your expected results to be? You want the walls to at least align on the corners. If you see it being one or two pixels off or more to where it is very noticable, and you expected the walls to connect, that is where you will look at your code and be like "Ooooooooh!!! Of course!"

    [EDIT]

    I am a little suspicious of this division that rounds to the nearest integer ---> RayHeight \ 2
    Personally, I would have kept everything double. But assuming you really really need it, I would have made that a constant rather than constantly dividing RayHeight by 2, especially twice on the same line! Also did you really need to floor this? Fix(RayHeight * 4) Anywho, have results you can compare to! Don't just print values. Know what you want your results to be and compare them to your results. This is what computer science is about. You can make a simpler version off a piece of paper with 2 hand drawn grids and use the same math (assuming top view for simplicity). One grid will have the walls already aligned which will be your expected results, and the other grid will be using your current formulas with the data given. If it does not align, you will clearly see why in your code this way. I done this many times before in graphics programming. Kinda odd to do it by hand but sometimes that is how you solve problems like this. At least with a hand drawn grid comparison approach, you'll have less pixels to work off of than off a computer lol.

  13. #13

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    Re: VB6 - raycasting: how get the image line?

    what is much more crazy!?!
    is that i created a dll on VB6 and i'm using it on VB2010.... on VB6 these don't happens, but only on VB2010 lol
    VB6 2D Sprite control

    To live is difficult, but we do it.

  14. #14
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: VB6 - raycasting: how get the image line?

    Maybe you can simplify it and focus only on the vertices rather than every freaking pixel. You want the vertices to connect with the walls. Try it like that then calculate.

  15. #15

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    Re: VB6 - raycasting: how get the image line?

    i use Trignometry instead pixel a pixel less calculations unless my code is wrong lol
    Code:
    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
            Dim PreviousX As Double = -1
            Dim PreviousY As Double = -1
    
            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
    
                'Check for horizontal intersections:            
                If RayRadians >= 0 And RayRadians <= Math.PI Then 'Facing down
                    HorizY = (Math.Floor(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 = (Math.Floor(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 = GetPositionMap(HorizX)
                    MapY = GetPositionMap(HorizY)
    
                Loop
    
                HorizDist = Math.Abs((player.PosX - HorizX) / Math.Cos(RayRadians))
                'HorizDist = Math.Sqrt(Math.Pow((player.PosX - VertX), 1) + Math.Pow((player.PosY - VertY), 1))
                'Check for vertical intersections:
                If RayRadians < Radian90 Or RayRadians > Radian270 Then 'Facing right
                    VertX = (Math.Floor(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 = (Math.Floor(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 = GetPositionMap(VertX)
                    MapY = GetPositionMap(VertY)
                Loop
    
                VertDist = Math.Abs((player.PosX - VertX) / Math.Cos(RayRadians))
                'VertDist = Math.Sqrt(Math.Pow((player.PosX - VertX), 2) + Math.Pow((player.PosY - VertY), 2))
                Dim VertColor As Color
                If VertDist < HorizDist Then
                    WallDistance = VertDist
                    OffSetGrid = VertY Mod ObjectSize
                    VertColor = Color.Blue
                    'Debug.Print("PosX2: " & CStr(CInt(VertX)) & vbTab & "Pos2Y: " & CStr(CInt(VertY)) & vbTab & "OffSetGrid: " & CStr(OffSetGrid))
    
                Else
                    OffSetGrid = HorizX Mod ObjectSize
                    WallDistance = HorizDist
    
                    VertColor = Color.DarkBlue
                    'Debug.Print("PosX2: " & CStr(CInt(HorizX)) & vbTab & "Pos2Y: " & CStr(CInt(HorizY)) & vbTab & "OffSetGrid: " & CStr(OffSetGrid))
                End If
    
                WallDistance = WallDistance * Math.Cos(RayRadians - player.Radians) 'avoiding the Fish Effect
                RayHeight = (ObjectSize / WallDistance) * 200 ' is the height screen\
    
                'picWall1.DrawTextureVerticalLine(img.MemoryHDC, OffSetGrid, math.floor(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
                If RayRadians >= 2 * Math.PI Then
                    RayRadians = 0
                End If
    
                RayCounts = RayCounts + 1
            Loop
        End Sub
    VB6 2D Sprite control

    To live is difficult, but we do it.

  16. #16
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: VB6 - raycasting: how get the image line?

    I think you are missing what I am saying. Grab your wall data, which I am sure you have, and use your code to, not on a computer, but calculate it by hand on a piece of paper at every corner (vertex) where the walls should intersect with one another. Then, and only then, will you find a flaw in your code if the edge of one wall does not align with the other. Remember to assume top view. We are fixing your polygon piercing issue. I cannot exam your code line by line due to my insane busy schedule. I work and go to school fulltime. But I can isolate your problem by having you do this by hand where the root cause is. Use paper for this one. Trust me.

  17. #17

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,923

    Re: VB6 - raycasting: how get the image line?

    i found the math problems here:
    Code:
     'Check for horizontal intersections:            
                If RayRadians >= 0 And RayRadians <= Math.PI Then 'Facing down
                    HorizY = (Math.Floor(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 = (Math.Floor(player.PosY / ObjectSize) * ObjectSize) - 1
                    HorizX = player.PosX + (HorizY - player.PosY) / Math.Tan(RayRadians)
                    StepY = -ObjectSize
                End If
    
                StepX = StepY / Math.Tan(RayRadians)
    and:
    Code:
    'Check for vertical intersections:
                If RayRadians < Radian90 Or RayRadians > Radian270 Then 'Facing right
                    VertX = (Math.Floor(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 = (Math.Floor(player.PosX / ObjectSize) * ObjectSize) - 1
                    VertY = player.PosY + (player.PosX - VertX) * Math.Tan(RayRadians)
                    StepX = -ObjectSize
                End If
    
                StepY = StepX * Math.Tan(RayRadians)
    i must review the code
    i did some tests, and the problems seems here
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width