Author Topic: 3D Land Grid  (Read 2924 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: 3D Land Grid
« Reply #15 on: May 21, 2020, 06:13:10 pm »
I now have a Sun and Compass for when you fly. The Sun is in the West and moves when you turn. I also moved the air speed and altitude numbers to the bottom as well as the compass reading.
I'm having lots of fun with this. :D

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 21, 2020.
  3. 'V. 0.5 - Added Sun and Compass.
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. xs = 10
  7. GOSUB grid:
  8. c = 0
  9. e = 100
  10. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  11.     _LIMIT 1000
  12.     a$ = INKEY$
  13.  
  14.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  15.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  16.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  17.     IF a$ = "-" THEN
  18.         speed2 = speed2 - 10
  19.         IF speed2 < 0 THEN speed = 0: b = 1: d = 0
  20.     END IF
  21.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3 'Right
  22.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4 'Left
  23.     IF a$ = " " THEN d = 0
  24.     IF a$ = CHR$(27) THEN END
  25.     IF d = 1 THEN speed = speed + 4: b = 0
  26.     IF d = 3 AND speed > 0 THEN
  27.         v = v - 1
  28.         vv = vv - 2
  29.         tilt = tilt - 2
  30.     END IF
  31.     IF d = 4 AND speed > 0 THEN
  32.         v = v + 1
  33.         vv = vv + 2
  34.         tilt = tilt + 2
  35.     END IF
  36.     IF d = 3 AND speed <= 0 THEN
  37.         v = v - 1
  38.         vv = vv - 2
  39.         tilt = tilt - 2
  40.         speed = speed + 4
  41.     END IF
  42.     IF d = 4 AND speed <= 0 THEN
  43.         v = v + 1
  44.         vv = vv + 2
  45.         tilt = tilt + 2
  46.         speed = speed + 4
  47.     END IF
  48.     IF d = 5 THEN speed = speed + 4: b = 0
  49.     IF d = 6 THEN speed = speed + 4: b = 0
  50.  
  51.     IF tilt > 200 THEN tilt = 200
  52.     IF tilt < -200 THEN tilt = -200
  53.     IF (d = 3 OR d = 4 OR d = 5 OR d = 6) AND b = 0 THEN speed = speed + 1
  54.     IF (d = 3 OR d = 4) AND b = 1 THEN speed = speed - 1
  55.     IF e > 100 THEN e = 100
  56.     IF e < 0 THEN e = 0
  57.     elevation = e - 100
  58.     elevation = -elevation
  59.     elevation = elevation * 100
  60.     GOSUB grid:
  61.     IF speed2 < 0 THEN speed2 = 0
  62.     IF speed2 > 2000 THEN speed2 = 2000
  63.     delay = 2 / speed2
  64.     IF delay < .002 THEN delay = .002
  65.     IF delay > .02 THEN delay = .02
  66.     _DELAY delay
  67.  
  68.  
  69. grid:
  70. LINE (0, 299 - e - tilt)-(800, 299 - e + tilt), _RGB32(0, 0, 150)
  71. PAINT (400, 2), _RGB32(0, 0, 150)
  72. LINE (0, 300 - e - tilt)-(800, 300 - e + tilt), _RGB32(0, 155, 0)
  73. PAINT (400, 599), _RGB32(0, 155, 0)
  74.  
  75. 'Calculate Compass
  76. tilt2 = tilt
  77. IF tilt2 < 0 THEN tilt2 = -tilt2
  78.  
  79. IF tilt < 0 THEN c = c - tilt2 / 314
  80. IF tilt > 0 THEN c = c + tilt2 / 314
  81. IF c > 359 THEN c = 0
  82. IF c < 0 THEN c = 359
  83. cc = INT(c)
  84. LOCATE 35, 1: PRINT "Compass:"; cc
  85.  
  86. 'Sun
  87. IF cc < 225 OR cc > 315 THEN til = 0: GOTO nosun:
  88. tilt3 = tilt / 50
  89. IF cc = 315 THEN sunx = 800
  90. IF cc = 225 THEN sunx = 0
  91. IF cc < 315 AND tilt < 0 AND tilt3 = oldtilt3 THEN sunx = sunx - 10: til = til - tilt3
  92. IF cc > 225 AND tilt > 0 AND tilt3 = oldtilt3 THEN sunx = sunx + 10: til = til + tilt3
  93. oldtilt3 = tilt3
  94. FOR sz = .25 TO 10 STEP .25
  95.     CIRCLE (sunx, til), sz, _RGB32(255, 255, 127)
  96. NEXT sz
  97. nosun:
  98.  
  99.  
  100. 'Left vertical lines.
  101. FOR x = 395 - e TO -300 STEP -xs - xx - e
  102.     xx = xx + 5
  103.     IF v > 7 + e THEN v = -7
  104.     IF v < -7 THEN v = 7 + e
  105.     IF vv > 300 THEN vv = 300
  106.     IF vv < -300 THEN vv = -300
  107.     FOR findy = 0 TO 600
  108.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy = findy: GOTO nex:
  109.     NEXT findy
  110.     nex:
  111.     IF POINT(x - xx + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy) = _RGB32(0, 0, 150) THEN GOTO skip:
  112.     LINE (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  113.     skip:
  114.  
  115. 'Right vertical lines.
  116. FOR x = 405 + e TO 1100 STEP xs + xx2 + e
  117.     xx2 = xx2 + 5
  118.     IF v > 7 + e THEN v = -7
  119.     IF v < -7 THEN v = 7 + e
  120.     IF vv > 300 THEN vv = 300
  121.     IF vv < -300 THEN vv = -300
  122.     FOR findy = 0 TO 600
  123.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy2 = findy: GOTO nex2:
  124.     NEXT findy
  125.     nex2:
  126.     IF POINT(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy2) = _RGB32(0, 0, 150) THEN GOTO skip2:
  127.     LINE (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  128.     skip2:
  129.  
  130. 'Horizontal lines.
  131. FOR hy = 0 TO 600 STEP xs + xx3 + e
  132.     xx3 = xx3 + 5
  133.     IF speed > 7 + e THEN speed = -7
  134.     IF speed < -7 THEN speed = 7 + e
  135.     FOR findx = 0 TO 800
  136.         IF POINT(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  137.             xx4 = findx
  138.         END IF
  139.     NEXT findx
  140.     FOR findx2 = 0 TO 800
  141.         IF POINT(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  142.             xx5 = findx2
  143.             LINE (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
  144.             GOTO nex3:
  145.         END IF
  146.     NEXT findx2
  147.     nex3:
  148. NEXT hy
  149. LOCATE 33, 1: PRINT "Altitude:"; elevation
  150. LOCATE 34, 1: PRINT "Airspeed:"; speed2
  151.  
  152. xx = 0: xx2 = 0: xx3 = 0
  153.  
  154.  


Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: 3D Land Grid
« Reply #16 on: May 22, 2020, 09:27:58 am »
Cool, I use something similar in my spacecraft vectoring ap. When one is zoomed in on a local planetary system, the display shows a yellow ball icon on a "protractor ring" to orient that user as to the relative bearing to the primary star.
« Last Edit: May 22, 2020, 09:29:18 am by OldMoses »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: 3D Land Grid
« Reply #17 on: May 22, 2020, 11:31:27 am »
That's neat OldMoses. :) Yeah I had to make a whole new system for the compass and Sun. 

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: 3D Land Grid
« Reply #18 on: May 22, 2020, 03:11:48 pm »
I made a better 3D perspective as you fly higher and fixed the grid to keep going as you turn. I also reduced the air speed to a 500 limit to make the grid look better.

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 21, 2020.
  3. 'V. 0.5 - Added Sun and Compass.
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. xs = 10
  7. GOSUB grid:
  8. c = 0
  9. e = 100
  10. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  11.     _LIMIT 1000
  12.     a$ = INKEY$
  13.  
  14.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  15.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  16.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  17.     IF a$ = "-" THEN
  18.         speed2 = speed2 - 10
  19.         IF speed2 < 0 THEN speed = 0: b = 1: d = 0
  20.     END IF
  21.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3: speed2 = speed2 + .2 'Right
  22.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4: speed2 = speed2 + .2 'Left
  23.     IF a$ = CHR$(27) THEN END
  24.     IF d = 1 THEN speed = speed + 2: b = 0
  25.     IF d = 3 AND speed > 0 THEN
  26.         v = v - 1
  27.         vv = vv - 2
  28.         tilt = tilt - 2
  29.     END IF
  30.     IF d = 4 AND speed > 0 THEN
  31.         v = v + 1
  32.         vv = vv + 2
  33.         tilt = tilt + 2
  34.     END IF
  35.     IF d = 3 AND speed <= 0 THEN
  36.         v = v - 1
  37.         vv = vv - 2
  38.         tilt = tilt - 2
  39.         speed = speed + 4
  40.     END IF
  41.     IF d = 4 AND speed <= 0 THEN
  42.         v = v + 1
  43.         vv = vv + 2
  44.         tilt = tilt + 2
  45.         speed = speed + 4
  46.     END IF
  47.     IF d = 5 OR speed2 > 0 THEN speed = speed + 1: b = 0
  48.     IF d = 6 OR speed2 > 0 THEN speed = speed + 1: b = 0
  49.  
  50.     IF tilt > 200 THEN tilt = 200
  51.     IF tilt < -200 THEN tilt = -200
  52.     IF (d = 3 OR d = 4 OR d = 5 OR d = 6) AND b = 0 THEN speed = speed + 1
  53.     IF (d = 3 OR d = 4) AND b = 1 THEN speed = speed - 1
  54.     IF e > 100 THEN e = 100
  55.     IF e < 0 THEN e = 0
  56.     elevation = e - 100
  57.     elevation = -elevation
  58.     elevation = elevation * 100
  59.     GOSUB grid:
  60.     IF speed2 < 0 THEN speed2 = 0
  61.     IF speed2 > 500 THEN speed2 = 500
  62.     delay = 2 / speed2
  63.     IF delay < .002 THEN delay = .002
  64.     IF delay > .02 THEN delay = .02
  65.     _DELAY delay
  66.  
  67.  
  68. grid:
  69. LINE (0, 299 - e - tilt)-(800, 299 - e + tilt), _RGB32(0, 0, 150)
  70. PAINT (400, 2), _RGB32(0, 0, 150)
  71. LINE (0, 300 - e - tilt)-(800, 300 - e + tilt), _RGB32(0, 155, 0)
  72. PAINT (400, 599), _RGB32(0, 155, 0)
  73.  
  74. 'Calculate Compass
  75. tilt2 = tilt
  76. IF tilt2 < 0 THEN tilt2 = -tilt2
  77.  
  78. IF tilt < 0 THEN c = c - tilt2 / 314
  79. IF tilt > 0 THEN c = c + tilt2 / 314
  80. IF c > 359 THEN c = 0
  81. IF c < 0 THEN c = 359
  82. cc = INT(c)
  83. LOCATE 35, 1: PRINT "Compass:"; cc
  84.  
  85. 'Sun
  86. IF cc < 225 OR cc > 315 THEN til = 0: GOTO nosun:
  87. tilt3 = tilt / 50
  88. IF cc = 315 THEN sunx = 800
  89. IF cc = 225 THEN sunx = 0
  90. IF cc < 315 AND tilt < 0 AND tilt3 = oldtilt3 THEN sunx = sunx - 10: til = til - tilt3
  91. IF cc > 225 AND tilt > 0 AND tilt3 = oldtilt3 THEN sunx = sunx + 10: til = til + tilt3
  92. oldtilt3 = tilt3
  93. FOR sz = .25 TO 10 STEP .25
  94.     CIRCLE (sunx, til), sz, _RGB32(255, 255, 127)
  95. NEXT sz
  96. nosun:
  97.  
  98.  
  99. 'Left vertical lines.
  100. FOR x = 395 - e TO -300 STEP -xs - xx - e
  101.     xx = xx + 55
  102.     IF v > 7 + e THEN v = -7
  103.     IF v < -7 THEN v = 7 + e
  104.     IF vv > 300 THEN vv = 300
  105.     IF vv < -300 THEN vv = -300
  106.     FOR findy = 0 TO 600
  107.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy = findy: GOTO nex:
  108.     NEXT findy
  109.     nex:
  110.     IF POINT(x - xx + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy) = _RGB32(0, 0, 150) THEN GOTO skip:
  111.     LINE (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  112.     skip:
  113.  
  114. 'Right vertical lines.
  115. FOR x = 405 + e TO 1100 STEP xs + xx2 + e
  116.     xx2 = xx2 + 55
  117.     IF v > 7 + e THEN v = -7
  118.     IF v < -7 THEN v = 7 + e
  119.     IF vv > 300 THEN vv = 300
  120.     IF vv < -300 THEN vv = -300
  121.     FOR findy = 0 TO 600
  122.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy2 = findy: GOTO nex2:
  123.     NEXT findy
  124.     nex2:
  125.     IF POINT(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy2) = _RGB32(0, 0, 150) THEN GOTO skip2:
  126.     LINE (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  127.     skip2:
  128.  
  129. 'Horizontal lines.
  130. FOR hy = 0 TO 600 STEP xs + xx3 + e
  131.     xx3 = xx3 + 5
  132.     IF speed > 7 + e THEN speed = -7
  133.     IF speed < -7 THEN speed = 7 + e
  134.     FOR findx = 0 TO 800
  135.         IF POINT(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  136.             xx4 = findx
  137.         END IF
  138.     NEXT findx
  139.     FOR findx2 = 0 TO 800
  140.         IF POINT(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  141.             xx5 = findx2
  142.             LINE (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
  143.             GOTO nex3:
  144.         END IF
  145.     NEXT findx2
  146.     nex3:
  147. NEXT hy
  148. LOCATE 33, 1: PRINT "Altitude:"; elevation
  149. LOCATE 34, 1: PRINT "Airspeed:"; INT(speed2)
  150.  
  151. xx = 0: xx2 = 0: xx3 = 0
  152.  
  153.