Author Topic: Real Maze in 3D  (Read 4326 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Real Maze in 3D
« on: November 26, 2020, 04:46:02 pm »
Hi !
Do you still remember that?

https://www.qb64.org/forum/index.php?topic=2735.msg119572#msg119572

An algorithm that creates a maze in 2D. Then I wondered if I could simply increase the size of the array by one more dimension and rationally transform the operations, whether it was possible in 3D as well. I just tried it and it works.
At startup, you can specify the size of the matrix or the size of the maze. If you want, you can also save the created track in .OBJ. (I needed this for verification). Make an exit from the matrix and then place you at the farthest point from the exit. Control WASD + mouse. get out! Not recommended for claustrophobics ! :)
Control only works under QB64v1.3, I don't know why.



Code: QB64: [Select]
  1. DIM SHARED maze_x, maze_y, maze_z AS _UNSIGNED _BYTE
  2. '-------------------- REAL 3D MAZE --------- SETTINGS -------------------------------------only QB64v1.3
  3. maze_x = 7 'maze size X
  4. maze_y = 7 'maze size Y
  5. maze_z = 7 'maze size Z
  6. monx = 1024 'window size X
  7. mon_rat = 0 'window side ratio 0=16:9 ,1=4:3
  8. file_obj$ = "" 'write the track to .OBJ file - if file_obj$ is empty, then writting skip
  9. msenx = .05 'mouse sensitive XY
  10. msenz = .08 'mouse sensitive Z
  11.  
  12. '--------------- ADVANCED SETTINGS --------------------------------------------------------
  13. pre_calc = 5 'calculation for step multiplier impact test
  14. mouse_z_rot = 176 'Z-direction rotation angle of view in degrees
  15. stepping = .08 'movement speed
  16. texture_size = 140 'textures pixel size x,y
  17. texture_margin = 3 'black margin to textures pixel
  18. texture_grey = 50 'random colors  0:grey scale 100:very color
  19. texture_c1 = 130 'circle is the maximum color variation allowed on the texture
  20. texture_c2 = 70 'circle diameter as a percentage of the image
  21. textures_c = 60 'number of different colors
  22. boss_limit = 30 'display framefrate
  23. zoom_xy = 6 '_maptriangle multiplier XY
  24. zoom_distance = 11 'maptriangle multiplier Z (as large as fisheye optics)
  25. cong$ = "  CONGRATULATIONS !  " 'text to sky when you find exit
  26.  
  27. 'creating 3D MAZE -----------------------------------------------------------------------------------------------------------------------------------------
  28. RANDOMIZE TIMER: maze_x = maze_x + ((maze_x AND 1) XOR 1): maze_y = maze_y + ((maze_y AND 1) XOR 1): maze_z = maze_z + ((maze_z AND 1) XOR 1)
  29. REDIM maze(maze_x - 1, maze_y - 1, maze_z - 1) AS _UNSIGNED _BYTE '0-fal 1-ureg 2-lehetoseg
  30. REDIM d(5, 2) AS _BYTE: d(0, 2) = 1: d(1, 2) = -1: d(2, 1) = 1: d(3, 1) = -1: d(4, 0) = 1: d(5, 0) = -1
  31. FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: FOR tz = 0 TO maze_z - 1: k = 0
  32.             k = ABS((tx = 0 OR ty = 0 OR tz = 0) OR (tx = maze_x - 1 OR ty = maze_y - 1 OR tz = maze_z - 1)) * 3: IF tx AND 1 AND ty AND 1 AND tz AND 1 THEN k = 1
  33. maze(tx, ty, tz) = k: NEXT tz, ty, tx
  34. DO: sx = INT(maze_x * RND(1)): sy = INT(maze_y * RND(1)): sz = INT(maze_z * RND(1)): LOOP WHILE maze(sx, sy, sz) <> 1: maze(sx, sy, sz) = 4 'start
  35. DO: REDIM way(9999, 3): wdb = 0: FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: FOR tz = 0 TO maze_z - 1: IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
  36.                 FOR t = 0 TO 5
  37.                     vpx1 = tx + d(t, 0): vpy1 = ty + d(t, 1): vpz1 = tz + d(t, 2): vpx2 = tx + d(t, 0) * 2: vpy2 = ty + d(t, 1) * 2: vpz2 = tz + d(t, 2) * 2
  38.                     IF NOT ((vpx2 > maze_x - 1 OR vpx2 < 0) OR (vpy2 > maze_y - 1 OR vpy2 < 0) OR (vpz2 > maze_z - 1 OR vpz2 < 0)) THEN
  39.                         IF maze(vpx1, vpy1, vpz1) = 0 AND maze(vpx2, vpy2, vpz2) = 1 THEN
  40.                             FOR t2 = 0 TO 5: vpx3 = vpx2 + d(t2, 0): vpy3 = vpy2 + d(t2, 1): vpz3 = vpz2 + d(t2, 2): IF maze(vpx3, vpy3, vpz3) = 4 THEN GOTO kovi
  41.                     NEXT t2: maze(vpx1, vpy1, vpz1) = 2: way(wdb, 0) = tx: way(wdb, 1) = ty: way(wdb, 2) = tz: way(wdb, 3) = t: wdb = wdb + 1: END IF: END IF
  42.     kovi: NEXT t: NEXT tz, ty, tx: aw = INT(wdb * RND(1)): IF wdb = 0 THEN _CONTINUE
  43.     FOR t = 0 TO 2: hovax = way(aw, 0) + d(way(aw, 3), 0) * t: hovay = way(aw, 1) + d(way(aw, 3), 1) * t: hovaz = way(aw, 2) + d(way(aw, 3), 2) * t
  44.         IF (maze(hovax, hovay, hovaz) = 2) OR (maze(hovax, hovay, hovaz) = 1) THEN maze(hovax, hovay, hovaz) = 4
  45.         NEXT t: FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: FOR tz = 0 TO maze_z - 1: maze(tx, ty, tz) = (ABS(maze(tx, ty, tz) = 2) XOR 1) * maze(tx, ty, tz)
  46. NEXT tz, ty, tx: LOOP WHILE wdb
  47.  
  48. '1 entri points on the cube
  49. DO: sx = INT(maze_x * RND(1)): sy = INT(maze_y * RND(1)): sz = INT(maze_z * RND(1))
  50.     felt1 = ABS(sx = 0 OR sx = maze_x - 1) + ABS(sy = 0 OR sy = maze_y - 1) + ABS(sz = 0 OR sz = maze_z - 1) = 1
  51.     nex = ABS(sx = 0 OR sx = maze_x - 1) * -1 * SGN(sx): ney = ABS(sy = 0 OR sy = maze_y - 1) * -1 * SGN(sy): nez = ABS(sz = 0 OR sz = maze_z - 1) * -1 * SGN(sz)
  52. LOOP UNTIL felt1 AND maze(nex + sx, ney + sy, nez + sz) = 4: maze(sx, sy, sz) = 4: exit_x = sx: exit_y = sy: exit_z = sz
  53.  
  54. 'calculation real points coordinates ,points array index2:ena/disa ,x,y,z
  55. points = (maze_x + 1) * (maze_y + 1) * (maze_z + 1): DIM SHARED points(points - 1, 9): FOR tx = 0 TO maze_x: FOR ty = 0 TO maze_y: FOR tz = 0 TO maze_z
  56. points(sp, 1) = tx: points(sp, 2) = ty: points(sp, 3) = tz: sp = sp + 1: NEXT tz, ty, tx
  57.  
  58. 'creating textures
  59. DIM c(2) AS _UNSIGNED _BYTE: DIM SHARED actual_texture: 'textures number
  60. DIM SHARED textures(textures_c - 1): FOR t = 0 TO textures_c - 1: temp = _NEWIMAGE(texture_size, texture_size, 32): _DEST temp
  61.     c(0) = INT(256 * RND(1)): FOR t2 = 1 TO 2: c(t2) = c(0) + (256 / 100 * texture_grey * RND(1)) * ((t2 - 1) * 2 - 1)
  62.         IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
  63.     NEXT t2: FOR t2 = 0 TO 9: SWAP c(INT(3 * RND(1))), c(INT(3 * RND(1))): NEXT t2: CLS , _RGB32(0, 0, 0)
  64.     LINE (texture_margin, texture_margin)-(texture_size - texture_margin - 1, texture_size - texture_margin - 1), _RGB32(c(0), c(1), c(2)), BF
  65.     FOR t2 = 0 TO 2: c(t2) = INT(c(t2) * texture_c1 / 100): IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
  66.     NEXT t2: CIRCLE (texture_size / 2, texture_size / 2), texture_size * texture_c2 / 100 / 2, _RGB32(c(0), c(1), c(2))
  67. PAINT (texture_size / 2, texture_size / 2), _RGB32(c(0), c(1), c(2)), _RGB32(c(0), c(1), c(2)): textures(t) = _COPYIMAGE(temp, 33): NEXT t: _FREEIMAGE temp
  68.  
  69. 'creating triangles (triangles array index2:'ena/disa,point1,point2,point3)
  70. FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: FOR tz = 0 TO maze_z - 1: cube_sum = cube_sum + ABS(maze(tx, ty, tz) <> 4): NEXT tz, ty, tx
  71. DIM SHARED triangles(cube_sum * 12 - 1, 10), triangles
  72. FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: FOR tz = 0 TO maze_z - 1: IF maze(tx, ty, tz) = 4 THEN _CONTINUE
  73.             actual_texture = INT(textures_c * RND(1))
  74.             sq0 = sq(tx, ty, tz): sq1 = sq(tx + 1, ty, tz): sq2 = sq(tx, ty + 1, tz): sq3 = sq(tx + 1, ty + 1, tz)
  75.             sq4 = sq(tx, ty, tz + 1): sq5 = sq(tx + 1, ty, tz + 1): sq6 = sq(tx, ty + 1, tz + 1): sq7 = sq(tx + 1, ty + 1, tz + 1)
  76.             sq_add sq0, sq1, sq2, sq3: sq_add sq4, sq5, sq6, sq7: sq_add sq4, sq0, sq6, sq2
  77. sq_add sq5, sq1, sq7, sq3: sq_add sq0, sq1, sq4, sq5: sq_add sq2, sq3, sq6, sq7: NEXT tz, ty, tx
  78.  
  79. IF LEN(file_obj$) THEN 'write to .OBJ
  80.     OPEN "d:\x.obj" FOR OUTPUT AS 1: FOR t = 0 TO points - 1: PRINT #1, "v "; points(t, 1); " "; points(t, 2); " "; points(t, 3); " ": NEXT t: FOR t = 0 TO triangles - 1
  81.         IF triangles(t, 0) THEN PRINT #1, "f "; triangles(t, 1) + 1; " "; triangles(t, 2) + 1; " "; triangles(t, 3) + 1; " "
  82.  
  83. 'find the farthest place in the maze from the exit
  84. REDIM me(19): maxdis = -9999999: FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: FOR tz = 0 TO maze_z - 1: IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
  85.             dis = (exit_x - tx) ^ 2 + (exit_y - ty) ^ 2 + (exit_z - tz) ^ 2: IF dis > maxdis THEN maxdis = dis: start_x = tx: start_y = ty: start_z = tz
  86. NEXT tz, ty, tx: me(0) = start_x: me(1) = start_y: me(2) = start_z
  87.  
  88. '---------------- other tasks to be performed
  89. CONST pip180 = 3.141592 / 180: REDIM cam(19): IF mon_rat THEN mony = INT(monx / 4 * 3) ELSE mony = INT(monx / 16 * 9)
  90. mon = _NEWIMAGE(monx, mony, 32): _DEST mon: SCREEN mon: _FULLSCREEN _SQUAREPIXELS , _SMOOTH: _MOUSEHIDE
  91.  
  92. DO: _LIMIT boss_limit ' ------------ BOSS CYCLE
  93.  
  94.     'control
  95.     kw = _KEYDOWN(119): ks = _KEYDOWN(115): ka = _KEYDOWN(97): kd = _KEYDOWN(100): szog_xy_elt = -90 * ABS(ka) + 90 * ABS(kd): ir = ABS(ka OR kd OR kw) OR -ABS(ks)
  96.     szog_xy = me(10) + (szog_xy_elt) * pip180: szog_z = me(11) + pip180 * 90: irx = -SIN(szog_xy) * COS(szog_z): iry = -COS(szog_xy) * COS(szog_z): irz = SIN(szog_z)
  97.     ana_x = INT(me(0) + irx * stepping * ir * pre_calc): ana_y = INT(me(1) + iry * stepping * ir * pre_calc): ana_z = INT(me(2) + irz * stepping * ir * pre_calc)
  98.     kivul = ana_x < 0 OR ana_x > maze_x - 1 OR ana_y < 0 OR ana_y > maze_y - 1 OR ana_z < 0 OR ana_z > maze_z - 1
  99.     IF NOT kivul THEN IF maze(ana_x, ana_y, ana_z) <> 4 THEN ir = 0
  100.     me(0) = me(0) + irx * stepping * ir: me(1) = me(1) + iry * stepping * ir: me(2) = me(2) + irz * stepping * ir
  101.     mousex = 0: mousey = 0: lookzmax = (mouse_z_rot / 2 - 90) * pip180: lookzmin = (-mouse_z_rot / 2 - 90) * pip180
  102.     FOR t = 0 TO 100: makt = _MOUSEINPUT: IF makt THEN mousex = _MOUSEMOVEMENTX + mousex: mousey = _MOUSEMOVEMENTY + mousey: axis = axis + _MOUSEWHEEL
  103.     NEXT t: me(10) = me(10) + (mousex / 5 * msenx): me(11) = me(11) + (mousey / 7 * msenz): IF me(11) > lookzmax THEN me(11) = lookzmax
  104.     IF me(11) < lookzmin THEN me(11) = lookzmin
  105.  
  106.     'calculating points
  107.     cam(0) = me(0) - SIN(me(10) - 180 * pip180) * me(3) / 2: cam(1) = me(1) - COS(me(10) - 180 * pip180) * me(3) / 2
  108.     cam(2) = me(2) + me(5) / 4: cam(3) = me(10): cam(4) = me(11): cosrotz = COS(cam(3)): sinrotz = SIN(cam(3)): cosrotx = COS(cam(4)): sinrotx = SIN(cam(4))
  109.     FOR actual_point = 0 TO points - 1: IF points(actual_point, 0) THEN
  110.             px = points(actual_point, 1) - cam(0): py = points(actual_point, 2) - cam(1): pz2 = points(actual_point, 3) - cam(2)
  111.             px3 = px * cosrotz - py * sinrotz: py2 = px * sinrotz + py * cosrotz: py3 = py2 * cosrotx - pz2 * sinrotx: pz3 = py2 * sinrotx + pz2 * cosrotx
  112.     points(actual_point, 4) = -px3 * zoom_xy: points(actual_point, 5) = -py3 * zoom_xy: points(actual_point, 6) = -pz3 * zoom_distance: END IF: NEXT actual_point
  113.  
  114.     'drawing triangles
  115.     FOR actual_triangle = 0 TO triangles - 1: IF triangles(actual_triangle, 0) THEN
  116.             wx1 = points(triangles(actual_triangle, 1), 4): wy1 = points(triangles(actual_triangle, 1), 5): wz1 = points(triangles(actual_triangle, 1), 6)
  117.             wx2 = points(triangles(actual_triangle, 2), 4): wy2 = points(triangles(actual_triangle, 2), 5): wz2 = points(triangles(actual_triangle, 2), 6)
  118.             wx3 = points(triangles(actual_triangle, 3), 4): wy3 = points(triangles(actual_triangle, 3), 5): wz3 = points(triangles(actual_triangle, 3), 6)
  119.             sx1 = triangles(actual_triangle, 4): sy1 = triangles(actual_triangle, 5): sx2 = triangles(actual_triangle, 6): sy2 = triangles(actual_triangle, 7)
  120.             sx3 = triangles(actual_triangle, 8): sy3 = triangles(actual_triangle, 9)
  121.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy2)-(sx3, sy3), textures(triangles(actual_triangle, 10)) TO(wx1, wy1, wz1)-(wx2, wy2, wz2)-(wx3, wy3, wz3), , _SMOOTH
  122. END IF: NEXT actual_triangle: _DISPLAY: CLS: FOR t = 1 TO _WIDTH(monx) / 8 * _HEIGHT(mony) / 16 / LEN(cong$): PRINT cong$;: NEXT t: LOOP
  123.  
  124. FUNCTION sq (ax, ay, az): sq = ax * (maze_y + 1) * (maze_z + 1) + ay * (maze_z + 1) + az: END FUNCTION 'which point ?
  125. SUB sq_add (p0, p1, p2, p3): triangles(triangles, 0) = 1: triangles(triangles, 1) = p0: triangles(triangles, 2) = p1: triangles(triangles, 3) = p2
  126.     triangles(triangles + 1, 0) = 1: triangles(triangles + 1, 1) = p3: triangles(triangles + 1, 2) = p1: triangles(triangles + 1, 3) = p2
  127.     points(p0, 0) = 1: points(p1, 0) = 1: points(p2, 0) = 1: points(p3, 0) = 1: triangles(triangles, 10) = actual_texture
  128.     triangles(triangles + 1, 10) = triangles(triangles, 10): triangles(triangles, 6) = _WIDTH(textures(actual_texture)) - 1
  129.     triangles(triangles, 9) = _HEIGHT(textures(actual_texture)) - 1: triangles(triangles + 1, 6) = triangles(triangles, 6)
  130. triangles(triangles + 1, 9) = triangles(triangles, 9): triangles = triangles + 2: END SUB
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Real Maze in 3D
« Reply #1 on: November 26, 2020, 05:33:02 pm »
Wow! that is cool! nice one @MasterGy

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Real Maze in 3D
« Reply #2 on: November 26, 2020, 07:30:41 pm »
If you name was just Gy I would call you MasterGy anyway. Nice job!
You're not done when it works, you're done when it's right.

FellippeHeitor

  • Guest
Re: Real Maze in 3D
« Reply #3 on: November 26, 2020, 07:47:05 pm »
Wow!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Real Maze in 3D
« Reply #4 on: November 26, 2020, 10:17:38 pm »
What a great little coded gem this is!   Saving it fast, and making a backup already.

Great work!

- Dav

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Real Maze in 3D
« Reply #5 on: November 27, 2020, 11:39:50 am »
Thank you for your answers !

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Real Maze in 3D
« Reply #6 on: November 27, 2020, 01:30:38 pm »
Quote
What a great little coded gem this is!   Saving it fast, and making a backup already.

Yes, it is great work. But first, take a good look at the code. It is condensed. Many commands separated by colons. This is not user - friendly source code.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Real Maze in 3D
« Reply #7 on: November 27, 2020, 02:05:23 pm »
The video looked impressive. Running the program, "compressed" and "expanded", did not work on my Linux box, Presented with a large image or discs within squares and the only keys that worked were "a" and "s" and the movement was only a few pixels.

Oh yes. I have had QB641.4 installed for quite some time. Could be the reason why it won't run. Line #2 "only QB64v1.3"

Code: QB64: [Select]
  1. DIM SHARED maze_x, maze_y, maze_z AS _UNSIGNED _BYTE
  2. '-------------------- REAL 3D MAZE --------- SETTINGS -------------------------------------only QB64v1.3
  3. maze_x = 7 'maze size X
  4. maze_y = 7 'maze size Y
  5. maze_z = 7 'maze size Z
  6. monx = 1024 'window size X
  7. mon_rat = 0 'window side ratio 0=16:9 ,1=4:3
  8. file_obj$ = "" 'write the track to .OBJ file - if file_obj$ is empty, then writting skip
  9. msenx = .05 'mouse sensitive XY
  10. msenz = .08 'mouse sensitive Z
  11.  
  12. '--------------- ADVANCED SETTINGS --------------------------------------------------------
  13. pre_calc = 5 'calculation for step multiplier impact test
  14. mouse_z_rot = 176 'Z-direction rotation angle of view in degrees
  15. stepping = .08 'movement speed
  16. texture_size = 140 'textures pixel size x,y
  17. texture_margin = 3 'black margin to textures pixel
  18. texture_grey = 50 'random colors  0:grey scale 100:very color
  19. texture_c1 = 130 'circle is the maximum color variation allowed on the texture
  20. texture_c2 = 70 'circle diameter as a percentage of the image
  21. textures_c = 60 'number of different colors
  22. boss_limit = 30 'display framefrate
  23. zoom_xy = 6 '_maptriangle multiplier XY
  24. zoom_distance = 11 'maptriangle multiplier Z (as large as fisheye optics)
  25. cong$ = "  CONGRATULATIONS !  " 'text to sky when you find exit
  26.  
  27. 'creating 3D MAZE -----------------------------------------------------------------------------------------------------------------------------------------
  28.  
  29.  
  30. maze_x = maze_x + ((maze_x AND 1) XOR 1)
  31. maze_y = maze_y + ((maze_y AND 1) XOR 1)
  32. maze_z = maze_z + ((maze_z AND 1) XOR 1)
  33.  
  34. REDIM maze(maze_x - 1, maze_y - 1, maze_z - 1) AS _UNSIGNED _BYTE '0-fal 1-ureg 2-lehetoseg
  35. REDIM d(5, 2) AS _BYTE
  36.  
  37. d(0, 2) = 1
  38. d(1, 2) = -1
  39. d(2, 1) = 1
  40. d(3, 1) = -1
  41. d(4, 0) = 1
  42. d(5, 0) = -1
  43. FOR tx = 0 TO maze_x - 1
  44.     FOR ty = 0 TO maze_y - 1
  45.         FOR tz = 0 TO maze_z - 1
  46.             k = 0
  47.             k = ABS((tx = 0 OR ty = 0 OR tz = 0) OR (tx = maze_x - 1 OR ty = maze_y - 1 OR tz = maze_z - 1)) * 3
  48.             IF tx AND 1 AND ty AND 1 AND tz AND 1 THEN k = 1
  49.             maze(tx, ty, tz) = k
  50. NEXT tz, ty, tx
  51.     sx = INT(maze_x * RND(1))
  52.     sy = INT(maze_y * RND(1))
  53.     sz = INT(maze_z * RND(1))
  54. LOOP WHILE maze(sx, sy, sz) <> 1
  55. maze(sx, sy, sz) = 4 'start
  56.     REDIM way(9999, 3)
  57.     wdb = 0
  58.     FOR tx = 0 TO maze_x - 1
  59.         FOR ty = 0 TO maze_y - 1
  60.             FOR tz = 0 TO maze_z - 1
  61.                 IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
  62.                 FOR t = 0 TO 5
  63.                     vpx1 = tx + d(t, 0)
  64.                     vpy1 = ty + d(t, 1)
  65.                     vpz1 = tz + d(t, 2)
  66.                     vpx2 = tx + d(t, 0) * 2
  67.                     vpy2 = ty + d(t, 1) * 2
  68.                     vpz2 = tz + d(t, 2) * 2
  69.                     IF NOT ((vpx2 > maze_x - 1 OR vpx2 < 0) OR (vpy2 > maze_y - 1 OR vpy2 < 0) OR (vpz2 > maze_z - 1 OR vpz2 < 0)) THEN
  70.                         IF maze(vpx1, vpy1, vpz1) = 0 AND maze(vpx2, vpy2, vpz2) = 1 THEN
  71.                             FOR t2 = 0 TO 5
  72.                                 vpx3 = vpx2 + d(t2, 0)
  73.                                 vpy3 = vpy2 + d(t2, 1)
  74.                                 vpz3 = vpz2 + d(t2, 2)
  75.                                 IF maze(vpx3, vpy3, vpz3) = 4 THEN GOTO kovi
  76.                             NEXT t2
  77.                             maze(vpx1, vpy1, vpz1) = 2
  78.                             way(wdb, 0) = tx
  79.                             way(wdb, 1) = ty
  80.                             way(wdb, 2) = tz
  81.                             way(wdb, 3) = t
  82.                             wdb = wdb + 1
  83.                         END IF
  84.                     END IF
  85.                     kovi:
  86.                 NEXT t
  87.     NEXT tz, ty, tx
  88.     aw = INT(wdb * RND(1))
  89.     IF wdb = 0 THEN _CONTINUE
  90.     FOR t = 0 TO 2
  91.         hovax = way(aw, 0) + d(way(aw, 3), 0) * t
  92.         hovay = way(aw, 1) + d(way(aw, 3), 1) * t
  93.         hovaz = way(aw, 2) + d(way(aw, 3), 2) * t
  94.         IF (maze(hovax, hovay, hovaz) = 2) OR (maze(hovax, hovay, hovaz) = 1) THEN maze(hovax, hovay, hovaz) = 4
  95.     NEXT t
  96.     FOR tx = 0 TO maze_x - 1
  97.         FOR ty = 0 TO maze_y - 1
  98.             FOR tz = 0 TO maze_z - 1
  99.                 maze(tx, ty, tz) = (ABS(maze(tx, ty, tz) = 2) XOR 1) * maze(tx, ty, tz)
  100.     NEXT tz, ty, tx
  101.  
  102. '1 entri points on the cube
  103.     sx = INT(maze_x * RND(1))
  104.     sy = INT(maze_y * RND(1))
  105.     sz = INT(maze_z * RND(1))
  106.     felt1 = ABS(sx = 0 OR sx = maze_x - 1) + ABS(sy = 0 OR sy = maze_y - 1) + ABS(sz = 0 OR sz = maze_z - 1) = 1
  107.     nex = ABS(sx = 0 OR sx = maze_x - 1) * -1 * SGN(sx)
  108.     ney = ABS(sy = 0 OR sy = maze_y - 1) * -1 * SGN(sy)
  109.     nez = ABS(sz = 0 OR sz = maze_z - 1) * -1 * SGN(sz)
  110. LOOP UNTIL felt1 AND maze(nex + sx, ney + sy, nez + sz) = 4
  111. maze(sx, sy, sz) = 4
  112. exit_x = sx
  113. exit_y = sy
  114. exit_z = sz
  115.  
  116. 'calculation real points coordinates ,points array index2:ena/disa ,x,y,z
  117. points = (maze_x + 1) * (maze_y + 1) * (maze_z + 1)
  118. DIM SHARED points(points - 1, 9)
  119. FOR tx = 0 TO maze_x
  120.     FOR ty = 0 TO maze_y
  121.         FOR tz = 0 TO maze_z
  122.             points(sp, 1) = tx
  123.             points(sp, 2) = ty
  124.             points(sp, 3) = tz
  125.             sp = sp + 1
  126. NEXT tz, ty, tx
  127.  
  128. 'creating textures
  129. DIM SHARED actual_texture
  130. 'textures number
  131. DIM SHARED textures(textures_c - 1)
  132. FOR t = 0 TO textures_c - 1
  133.     temp = _NEWIMAGE(texture_size, texture_size, 32)
  134.     _DEST temp
  135.     c(0) = INT(256 * RND(1))
  136.     FOR t2 = 1 TO 2
  137.         c(t2) = c(0) + (256 / 100 * texture_grey * RND(1)) * ((t2 - 1) * 2 - 1)
  138.         IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
  139.     NEXT t2
  140.     FOR t2 = 0 TO 9
  141.         SWAP c(INT(3 * RND(1))), c(INT(3 * RND(1)))
  142.     NEXT t2
  143.     CLS , _RGB32(0, 0, 0)
  144.     LINE (texture_margin, texture_margin)-(texture_size - texture_margin - 1, texture_size - texture_margin - 1), _RGB32(c(0), c(1), c(2)), BF
  145.     FOR t2 = 0 TO 2
  146.         c(t2) = INT(c(t2) * texture_c1 / 100)
  147.         IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
  148.     NEXT t2
  149.     CIRCLE (texture_size / 2, texture_size / 2), texture_size * texture_c2 / 100 / 2, _RGB32(c(0), c(1), c(2))
  150.     PAINT (texture_size / 2, texture_size / 2), _RGB32(c(0), c(1), c(2)), _RGB32(c(0), c(1), c(2))
  151.     textures(t) = _COPYIMAGE(temp, 33)
  152.  
  153. 'creating triangles (triangles array index2:'ena/disa,point1,point2,point3)
  154. FOR tx = 0 TO maze_x - 1
  155.     FOR ty = 0 TO maze_y - 1
  156.         FOR tz = 0 TO maze_z - 1
  157.             cube_sum = cube_sum + ABS(maze(tx, ty, tz) <> 4)
  158. NEXT tz, ty, tx
  159. DIM SHARED triangles(cube_sum * 12 - 1, 10), triangles
  160. FOR tx = 0 TO maze_x - 1
  161.     FOR ty = 0 TO maze_y - 1
  162.         FOR tz = 0 TO maze_z - 1
  163.             IF maze(tx, ty, tz) = 4 THEN _CONTINUE
  164.             actual_texture = INT(textures_c * RND(1))
  165.             sq0 = sq(tx, ty, tz)
  166.             sq1 = sq(tx + 1, ty, tz)
  167.             sq2 = sq(tx, ty + 1, tz)
  168.             sq3 = sq(tx + 1, ty + 1, tz)
  169.             sq4 = sq(tx, ty, tz + 1)
  170.             sq5 = sq(tx + 1, ty, tz + 1)
  171.             sq6 = sq(tx, ty + 1, tz + 1)
  172.             sq7 = sq(tx + 1, ty + 1, tz + 1)
  173.             sq_add sq0, sq1, sq2, sq3
  174.             sq_add sq4, sq5, sq6, sq7
  175.             sq_add sq4, sq0, sq6, sq2
  176.             sq_add sq5, sq1, sq7, sq3
  177.             sq_add sq0, sq1, sq4, sq5
  178.             sq_add sq2, sq3, sq6, sq7
  179. NEXT tz, ty, tx
  180.  
  181. IF LEN(file_obj$) THEN 'write to .OBJ
  182.     OPEN "d:\x.obj" FOR OUTPUT AS 1
  183.     FOR t = 0 TO points - 1
  184.         PRINT #1, "v "; points(t, 1); " "; points(t, 2); " "; points(t, 3); " "
  185.     NEXT t
  186.     FOR t = 0 TO triangles - 1
  187.         IF triangles(t, 0) THEN PRINT #1, "f "; triangles(t, 1) + 1; " "; triangles(t, 2) + 1; " "; triangles(t, 3) + 1; " "
  188.     NEXT t
  189.     CLOSE 1
  190.  
  191. 'find the farthest place in the maze from the exit
  192. REDIM me(19)
  193. maxdis = -9999999
  194. FOR tx = 0 TO maze_x - 1
  195.     FOR ty = 0 TO maze_y - 1
  196.         FOR tz = 0 TO maze_z - 1
  197.             IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
  198.             dis = (exit_x - tx) ^ 2 + (exit_y - ty) ^ 2 + (exit_z - tz) ^ 2
  199.             IF dis > maxdis THEN maxdis = dis
  200.             start_x = tx
  201.             start_y = ty
  202.             start_z = tz
  203. NEXT tz, ty, tx
  204. me(0) = start_x
  205. me(1) = start_y
  206. me(2) = start_z
  207.  
  208. '---------------- other tasks to be performed
  209. CONST pip180 = 3.141592 / 180
  210. REDIM cam(19)
  211. IF mon_rat THEN mony = INT(monx / 4 * 3) ELSE mony = INT(monx / 16 * 9)
  212. mon = _NEWIMAGE(monx, mony, 32)
  213. _DEST mon
  214. SCREEN mon
  215.  
  216.     _LIMIT boss_limit ' ------------ BOSS CYCLE
  217.  
  218.     'control
  219.     kw = _KEYDOWN(119)
  220.     ks = _KEYDOWN(115)
  221.     ka = _KEYDOWN(97)
  222.     kd = _KEYDOWN(100)
  223.     szog_xy_elt = -90 * ABS(ka) + 90 * ABS(kd)
  224.     ir = ABS(ka OR kd OR kw) OR -ABS(ks)
  225.     szog_xy = me(10) + (szog_xy_elt) * pip180
  226.     szog_z = me(11) + pip180 * 90
  227.     irx = -SIN(szog_xy) * COS(szog_z)
  228.     iry = -COS(szog_xy) * COS(szog_z)
  229.     irz = SIN(szog_z)
  230.     ana_x = INT(me(0) + irx * stepping * ir * pre_calc)
  231.     ana_y = INT(me(1) + iry * stepping * ir * pre_calc)
  232.     ana_z = INT(me(2) + irz * stepping * ir * pre_calc)
  233.     kivul = ana_x < 0 OR ana_x > maze_x - 1 OR ana_y < 0 OR ana_y > maze_y - 1 OR ana_z < 0 OR ana_z > maze_z - 1
  234.     IF NOT kivul THEN IF maze(ana_x, ana_y, ana_z) <> 4 THEN ir = 0
  235.     me(0) = me(0) + irx * stepping * ir
  236.     me(1) = me(1) + iry * stepping * ir
  237.     me(2) = me(2) + irz * stepping * ir
  238.     mousex = 0
  239.     mousey = 0
  240.     lookzmax = (mouse_z_rot / 2 - 90) * pip180
  241.     lookzmin = (-mouse_z_rot / 2 - 90) * pip180
  242.     FOR t = 0 TO 100
  243.         makt = _MOUSEINPUT
  244.         IF makt THEN mousex = _MOUSEMOVEMENTX + mousex
  245.         mousey = _MOUSEMOVEMENTY + mousey
  246.         axis = axis + _MOUSEWHEEL
  247.     NEXT t
  248.     me(10) = me(10) + (mousex / 5 * msenx)
  249.     me(11) = me(11) + (mousey / 7 * msenz)
  250.     IF me(11) > lookzmax THEN me(11) = lookzmax
  251.     IF me(11) < lookzmin THEN me(11) = lookzmin
  252.  
  253.     'calculating points
  254.     cam(0) = me(0) - SIN(me(10) - 180 * pip180) * me(3) / 2
  255.     cam(1) = me(1) - COS(me(10) - 180 * pip180) * me(3) / 2
  256.     cam(2) = me(2) + me(5) / 4
  257.     cam(3) = me(10)
  258.     cam(4) = me(11)
  259.     cosrotz = COS(cam(3))
  260.     sinrotz = SIN(cam(3))
  261.     cosrotx = COS(cam(4))
  262.     sinrotx = SIN(cam(4))
  263.     FOR actual_point = 0 TO points - 1
  264.         IF points(actual_point, 0) THEN
  265.             px = points(actual_point, 1) - cam(0)
  266.             py = points(actual_point, 2) - cam(1)
  267.             pz2 = points(actual_point, 3) - cam(2)
  268.             px3 = px * cosrotz - py * sinrotz
  269.             py2 = px * sinrotz + py * cosrotz
  270.             py3 = py2 * cosrotx - pz2 * sinrotx
  271.             pz3 = py2 * sinrotx + pz2 * cosrotx
  272.             points(actual_point, 4) = -px3 * zoom_xy
  273.             points(actual_point, 5) = -py3 * zoom_xy
  274.             points(actual_point, 6) = -pz3 * zoom_distance
  275.         END IF
  276.     NEXT actual_point
  277.  
  278.     'drawing triangles
  279.     FOR actual_triangle = 0 TO triangles - 1
  280.         IF triangles(actual_triangle, 0) THEN
  281.             wx1 = points(triangles(actual_triangle, 1), 4)
  282.             wy1 = points(triangles(actual_triangle, 1), 5)
  283.             wz1 = points(triangles(actual_triangle, 1), 6)
  284.             wx2 = points(triangles(actual_triangle, 2), 4)
  285.             wy2 = points(triangles(actual_triangle, 2), 5)
  286.             wz2 = points(triangles(actual_triangle, 2), 6)
  287.             wx3 = points(triangles(actual_triangle, 3), 4)
  288.             wy3 = points(triangles(actual_triangle, 3), 5)
  289.             wz3 = points(triangles(actual_triangle, 3), 6)
  290.             sx1 = triangles(actual_triangle, 4)
  291.             sy1 = triangles(actual_triangle, 5)
  292.             sx2 = triangles(actual_triangle, 6)
  293.             sy2 = triangles(actual_triangle, 7)
  294.             sx3 = triangles(actual_triangle, 8)
  295.             sy3 = triangles(actual_triangle, 9)
  296.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy2)-(sx3, sy3), textures(triangles(actual_triangle, 10)) TO(wx1, wy1, wz1)-(wx2, wy2, wz2)-(wx3, wy3, wz3), , _SMOOTH
  297.         END IF
  298.     NEXT actual_triangle
  299.     _DISPLAY
  300.     CLS
  301.     FOR t = 1 TO _WIDTH(monx) / 8 * _HEIGHT(mony) / 16 / LEN(cong$)
  302.         PRINT cong$;
  303.     NEXT t
  304.  
  305. FUNCTION sq (ax, ay, az)
  306.     sq = ax * (maze_y + 1) * (maze_z + 1) + ay * (maze_z + 1) + az
  307. END FUNCTION 'which point ?
  308.  
  309. SUB sq_add (p0, p1, p2, p3)
  310.     triangles(triangles, 0) = 1
  311.     triangles(triangles, 1) = p0
  312.     triangles(triangles, 2) = p1
  313.     triangles(triangles, 3) = p2
  314.     triangles(triangles + 1, 0) = 1
  315.     triangles(triangles + 1, 1) = p3
  316.     triangles(triangles + 1, 2) = p1
  317.     triangles(triangles + 1, 3) = p2
  318.     points(p0, 0) = 1
  319.     points(p1, 0) = 1
  320.     points(p2, 0) = 1
  321.     points(p3, 0) = 1
  322.     triangles(triangles, 10) = actual_texture
  323.     triangles(triangles + 1, 10) = triangles(triangles, 10)
  324.     triangles(triangles, 6) = _WIDTH(textures(actual_texture)) - 1
  325.     triangles(triangles, 9) = _HEIGHT(textures(actual_texture)) - 1
  326.     triangles(triangles + 1, 6) = triangles(triangles, 6)
  327.     triangles(triangles + 1, 9) = triangles(triangles, 9)
  328.     triangles = triangles + 2
  329.  
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Real Maze in 3D
« Reply #8 on: November 27, 2020, 02:13:30 pm »
Quote
Oh yes. I have had QB641.4 installed for quite some time. Could be the reason why it won't run. Line #2 "only QB64v1.3"

I bet everyone who already wowed tested on QB64 v1.4 but not on Linux. ;) I know I did.

Maybe you removed a colon that shouldn't have been removed? Like after a THEN ?
« Last Edit: November 27, 2020, 02:16:59 pm by bplus »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Real Maze in 3D
« Reply #9 on: November 27, 2020, 06:07:42 pm »
Hi !
Thanks for the comment, I didn’t think the colon was a problem. i tend to compress it because if any part works, i like it to take up as little space as possible due to scrolling. if I have to deal with it for something, I will unpack it. it's easier for me to see through that too. I also try to express it with more complex logical operations instead of IF, because that saves a lot of unnecessary lines.

I changed the program, making the management easier. it does not get stuck on the wall, but chooses a different angle, and the turns-up feeling disappears with the turns as well. mouse forward, right mouse backward. Unfortunately, even though I expose it line by line, under qb1.4 the control is just as good. I stick to qb1.3 because it makes exe much faster than me.

I also wanted to do the essential parts (e.g. numbering, easier control) because there was an interesting thing about making the game. If a 2d maze builder can be turned into a 3d maze builder almost simply by adding another dimension to the array, then why shouldn’t there be more dimensions? I want an experiment to make a maze in 4d. Let X, Y, Z, A be the axes. Obviously, it’s also visually difficult to imagine the thing, even though the array would fix the roads in the right way. At least logically. What if a screen were divided into 4 and the read points from the 4d array were shown separately as follows: XYZ, XYA, XZA, YZA. So each would miss the fourth. When we move in one of the windows where only that 3 dimension exists, you would only see it. i wonder if i move in one window, walk around, how the other 3 windows change. I can pretty much imagine it. Do you think so? Couldn't that explain a lot of things? For example. The exit would be at 3,2,1,6 coordinate points. If you are in the wrong 4th dimension, there is no way out, even though the 3 coordinates of the world you know are all right.



Code: QB64: [Select]
  1. DIM SHARED maze_x, maze_y, maze_z AS _UNSIGNED _BYTE
  2. '-------------------- REAL 3D MAZE --------- SETTINGS -------------------------------------only QB64v1.3
  3.  
  4. maze_x = 9 'maze size X
  5. maze_y = 7 'maze size Y
  6. maze_z = 9 'maze size Z
  7. monx = 1024 'window size X
  8. mon_rat = 0 'window side ratio 0=16:9 ,1=4:3
  9. file_obj$ = "" 'write the track to .OBJ file - if file_obj$ is empty, then writting skip
  10. msenx = .05 'mouse sensitive XY
  11. msenz = .08 'mouse sensitive Z
  12.  
  13. '--------------- ADVANCED SETTINGS --------------------------------------------------------
  14. pre_calc = 2 'calculation for step multiplier impact test
  15. mouse_z_rot = 176 'Z-direction rotation angle of view in degrees
  16. stepping = .04 'movement speed
  17. texture_size = 140 'textures pixel size x,y
  18. texture_margin = 3 'black margin to textures pixel
  19. texture_grey = 50 'random colors  0 grey scale 100 very color
  20. texture_c1 = 130 'circle is the maximum color variation allowed on the texture
  21. texture_c2 = 70 'circle diameter as a percentage of the image
  22. texture_n = 1 'serial number to cube
  23. boss_limit = 30 'display framefrate
  24. zoom_xy = 6 '_maptriangle multiplier XY
  25. zoom_distance = 20 'maptriangle multiplier Z (as large as fisheye optics)
  26. me_dim = .2 'my dimensions
  27. max_couch = 70 'correct angle of impact tolerance
  28. cong$ = "  CONGRATULATIONS !  " 'text to sky when you find exit
  29.  
  30. 'creating 3D MAZE -----------------------------------------------------------------------------------------------------------------------------------------
  31. maze_x = maze_x + ((maze_x AND 1) XOR 1)
  32. maze_y = maze_y + ((maze_y AND 1) XOR 1)
  33. maze_z = maze_z + ((maze_z AND 1) XOR 1)
  34. REDIM maze(maze_x - 1, maze_y - 1, maze_z - 1) AS _UNSIGNED _BYTE '0-fal 1-ureg 2-lehetoseg
  35. REDIM d(5, 2) AS _BYTE
  36. d(0, 2) = 1
  37. d(1, 2) = -1
  38. d(2, 1) = 1
  39. d(3, 1) = -1
  40. d(4, 0) = 1
  41. d(5, 0) = -1
  42. FOR tx = 0 TO maze_x - 1
  43.     FOR ty = 0 TO maze_y - 1
  44.         FOR tz = 0 TO maze_z - 1
  45.             k = 0
  46.             k = ABS((tx = 0 OR ty = 0 OR tz = 0) OR (tx = maze_x - 1 OR ty = maze_y - 1 OR tz = maze_z - 1)) * 3
  47.             IF tx AND 1 AND ty AND 1 AND tz AND 1 THEN k = 1
  48.             maze(tx, ty, tz) = k
  49. NEXT tz, ty, tx
  50.     sx = INT(maze_x * RND(1))
  51.     sy = INT(maze_y * RND(1))
  52.     sz = INT(maze_z * RND(1))
  53. LOOP WHILE maze(sx, sy, sz) <> 1
  54. maze(sx, sy, sz) = 4 'start
  55.     REDIM way(9999, 3)
  56.     wdb = 0
  57.     FOR tx = 0 TO maze_x - 1
  58.         FOR ty = 0 TO maze_y - 1
  59.             FOR tz = 0 TO maze_z - 1
  60.                 IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
  61.                 FOR t = 0 TO 5
  62.                     vpx1 = tx + d(t, 0)
  63.                     vpy1 = ty + d(t, 1)
  64.                     vpz1 = tz + d(t, 2)
  65.                     vpx2 = tx + d(t, 0) * 2
  66.                     vpy2 = ty + d(t, 1) * 2
  67.                     vpz2 = tz + d(t, 2) * 2
  68.                     IF NOT ((vpx2 > maze_x - 1 OR vpx2 < 0) OR (vpy2 > maze_y - 1 OR vpy2 < 0) OR (vpz2 > maze_z - 1 OR vpz2 < 0)) THEN
  69.                         IF maze(vpx1, vpy1, vpz1) = 0 AND maze(vpx2, vpy2, vpz2) = 1 THEN
  70.                             FOR t2 = 0 TO 5
  71.                                 vpx3 = vpx2 + d(t2, 0)
  72.                                 vpy3 = vpy2 + d(t2, 1)
  73.                                 vpz3 = vpz2 + d(t2, 2)
  74.                                 IF maze(vpx3, vpy3, vpz3) = 4 THEN GOTO kovi
  75.                             NEXT t2
  76.                             maze(vpx1, vpy1, vpz1) = 2
  77.                             way(wdb, 0) = tx
  78.                             way(wdb, 1) = ty
  79.                             way(wdb, 2) = tz
  80.                             way(wdb, 3) = t
  81.                             wdb = wdb + 1
  82.                         END IF
  83.                     END IF
  84.                     kovi:
  85.                 NEXT t
  86.     NEXT tz, ty, tx
  87.     aw = INT(wdb * RND(1))
  88.     IF wdb = 0 THEN _CONTINUE
  89.     FOR t = 0 TO 2
  90.         hovax = way(aw, 0) + d(way(aw, 3), 0) * t
  91.         hovay = way(aw, 1) + d(way(aw, 3), 1) * t
  92.         hovaz = way(aw, 2) + d(way(aw, 3), 2) * t
  93.         IF (maze(hovax, hovay, hovaz) = 2) OR (maze(hovax, hovay, hovaz) = 1) THEN maze(hovax, hovay, hovaz) = 4
  94.     NEXT t
  95.     FOR tx = 0 TO maze_x - 1
  96.         FOR ty = 0 TO maze_y - 1
  97.             FOR tz = 0 TO maze_z - 1
  98.                 maze(tx, ty, tz) = (ABS(maze(tx, ty, tz) = 2) XOR 1) * maze(tx, ty, tz)
  99.     NEXT tz, ty, tx
  100.  
  101. '1 entri points on the cube
  102.     sx = INT(maze_x * RND(1))
  103.     sy = INT(maze_y * RND(1))
  104.     sz = INT(maze_z * RND(1))
  105.     felt1 = ABS(sx = 0 OR sx = maze_x - 1) + ABS(sy = 0 OR sy = maze_y - 1) + ABS(sz = 0 OR sz = maze_z - 1) = 1
  106.     nex = ABS(sx = 0 OR sx = maze_x - 1) * -1 * SGN(sx)
  107.     ney = ABS(sy = 0 OR sy = maze_y - 1) * -1 * SGN(sy)
  108.     nez = ABS(sz = 0 OR sz = maze_z - 1) * -1 * SGN(sz)
  109. LOOP UNTIL felt1 AND maze(nex + sx, ney + sy, nez + sz) = 4
  110. maze(sx, sy, sz) = 4
  111. exit_x = sx
  112. exit_y = sy
  113. exit_z = sz
  114.  
  115. 'calculation real points coordinates ,points array index2
  116.  
  117. points = (maze_x + 1) * (maze_y + 1) * (maze_z + 1)
  118. DIM SHARED points(points - 1, 9)
  119. FOR tx = 0 TO maze_x
  120.     FOR ty = 0 TO maze_y
  121.         FOR tz = 0 TO maze_z
  122.             points(sp, 1) = tx
  123.             points(sp, 2) = ty
  124.             points(sp, 3) = tz
  125.             sp = sp + 1
  126. NEXT tz, ty, tx
  127.  
  128.  
  129. 'creating triangles (triangles array index2
  130. 'ena/disa,point1,point2,point3)
  131. DIM SHARED serial
  132. DIM SHARED textures(maze_x * maze_y * maze_z - 1)
  133. FOR tx = 0 TO maze_x - 1
  134.     FOR ty = 0 TO maze_y - 1
  135.         FOR tz = 0 TO maze_z - 1
  136.             cube_sum = cube_sum + ABS(maze(tx, ty, tz) <> 4)
  137. NEXT tz, ty, tx
  138. DIM SHARED triangles(cube_sum * 12 - 1, 10), triangles
  139. FOR tx = 0 TO maze_x - 1
  140.     FOR ty = 0 TO maze_y - 1
  141.         FOR tz = 0 TO maze_z - 1
  142.             IF maze(tx, ty, tz) = 4 THEN _CONTINUE
  143.             'creating texture
  144.             temp = _NEWIMAGE(texture_size, texture_size, 32)
  145.             _DEST temp
  146.             c(0) = INT(256 * RND(1))
  147.             FOR t2 = 1 TO 2
  148.                 c(t2) = c(0) + (256 / 100 * texture_grey * RND(1)) * ((t2 - 1) * 2 - 1)
  149.                 IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
  150.             NEXT t2
  151.             FOR t2 = 0 TO 9
  152.                 SWAP c(INT(3 * RND(1))), c(INT(3 * RND(1)))
  153.             NEXT t2
  154.             CLS '_RGB32(255, 255, 255), _RGB32(0, 0, 0)
  155.             LINE (texture_margin, texture_margin)-(texture_size - texture_margin - 1, texture_size - texture_margin - 1), _RGB32(c(0), c(1), c(2)), BF
  156.             FOR t2 = 0 TO 2
  157.                 c(t2) = INT(c(t2) * texture_c1 / 100)
  158.                 IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
  159.             NEXT t2
  160.             CIRCLE (texture_size / 2, texture_size / 2), texture_size * texture_c2 / 100 / 2, _RGB32(c(0), c(1), c(2))
  161.             PAINT (texture_size / 2, texture_size / 2), _RGB32(c(0), c(1), c(2)), _RGB32(c(0), c(1), c(2))
  162.             IF texture_n THEN num$ = LTRIM$(STR$(serial))
  163.             LOCATE texture_size / 32 + 1, ((texture_size / 8) - LEN(num$)) / 2 + 1
  164.             PRINT num$;
  165.             textures(serial) = _COPYIMAGE(temp, 33)
  166.             _FREEIMAGE temp
  167.             'creating cube
  168.             sq0 = sq(tx, ty, tz)
  169.             sq1 = sq(tx + 1, ty, tz)
  170.             sq2 = sq(tx, ty + 1, tz)
  171.             sq3 = sq(tx + 1, ty + 1, tz)
  172.             sq4 = sq(tx, ty, tz + 1)
  173.             sq5 = sq(tx + 1, ty, tz + 1)
  174.             sq6 = sq(tx, ty + 1, tz + 1)
  175.             sq7 = sq(tx + 1, ty + 1, tz + 1)
  176.             sq_add sq1, sq0, sq3, sq2, 1
  177.             sq_add sq4, sq5, sq6, sq7, 1
  178.             sq_add sq2, sq0, sq6, sq4, 1
  179.             sq_add sq1, sq3, sq5, sq7, 1
  180.             sq_add sq0, sq1, sq4, sq5, 1
  181.             sq_add sq3, sq2, sq7, sq6, 1
  182.  
  183.             serial = serial + 1
  184. NEXT tz, ty, tx
  185.  
  186. IF LEN(file_obj$) THEN 'write to .OBJ
  187.     OPEN "d:\x.obj" FOR OUTPUT AS 1
  188.     FOR t = 0 TO points - 1
  189.         PRINT #1, "v "; points(t, 1); " "; points(t, 2); " "; points(t, 3); " "
  190.     NEXT t
  191.     FOR t = 0 TO triangles - 1
  192.         IF triangles(t, 0) THEN PRINT #1, "f "; triangles(t, 1) + 1; " "; triangles(t, 2) + 1; " "; triangles(t, 3) + 1; " "
  193.     NEXT t
  194.     CLOSE 1
  195.  
  196. 'find the farthest place in the maze from the exit
  197. REDIM me(19)
  198. maxdis = -9999999
  199. FOR tx = 0 TO maze_x - 1
  200.     FOR ty = 0 TO maze_y - 1
  201.         FOR tz = 0 TO maze_z - 1
  202.             IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
  203.             dis = (exit_x - tx) ^ 2 + (exit_y - ty) ^ 2 + (exit_z - tz) ^ 2
  204.             IF dis > maxdis THEN maxdis = dis: start_x = tx: start_y = ty: start_z = tz
  205. NEXT tz, ty, tx
  206. me(0) = start_x + .5
  207. me(1) = start_y + .5
  208. me(2) = start_z + .5
  209.  
  210.  
  211. '---------------- other tasks to be performed
  212. CONST pip180 = 3.141592 / 180
  213. REDIM cam(19)
  214. IF mon_rat THEN mony = INT(monx / 4 * 3) ELSE mony = INT(monx / 16 * 9)
  215. mon = _NEWIMAGE(monx, mony, 32)
  216. _DEST mon
  217. SCREEN mon
  218.  
  219.     _LIMIT boss_limit ' ------------ BOSS CYCLE
  220.     'control
  221.     kw = _KEYDOWN(119) OR _MOUSEBUTTON(1)
  222.     ks = _KEYDOWN(115) OR _MOUSEBUTTON(2)
  223.     ka = _KEYDOWN(97)
  224.     et_ir = ABS(ka OR kd OR kw) OR -ABS(ks)
  225.     kd = _KEYDOWN(100)
  226.     FOR elt1 = 0 TO max_couch STEP 2
  227.         FOR elt2 = 0 TO 360 STEP 12
  228.             elt_xy = SIN(elt2 * pip180) * elt1
  229.             elt_z = COS(elt2 * pip180) * elt1
  230.             szog_xy_elt = -90 * ABS(ka) + 90 * ABS(kd)
  231.             szog_xy = me(10) + (szog_xy_elt + elt_xy) * pip180
  232.             szog_z = me(11) + pip180 * (90 + elt_z)
  233.             irx = -SIN(szog_xy) * COS(szog_z)
  234.             iry = -COS(szog_xy) * COS(szog_z)
  235.             irz = SIN(szog_z)
  236.             ir = et_ir
  237.             multi = stepping * ir * pre_calc * 2
  238.             FOR elt_x = 0 TO 1
  239.                 FOR elt_y = 0 TO 1
  240.                     FOR elt_z = 0 TO 1
  241.                         ana_x = INT(me(0) + irx * multi + (elt_x * 2 - 1) * me_dim / 2)
  242.                         ana_y = INT(me(1) + iry * multi + (elt_y * 2 - 1) * me_dim / 2)
  243.                         ana_z = INT(me(2) + irz * multi + (elt_z * 2 - 1) * me_dim / 2)
  244.                         kivul = ana_x < 0 OR ana_x > maze_x - 1 OR ana_y < 0 OR ana_y > maze_y - 1 OR ana_z < 0 OR ana_z > maze_z - 1
  245.                         IF NOT kivul THEN ir = ir * ABS(maze(ana_x, ana_y, ana_z) = 4)
  246.             NEXT elt_z, elt_y, elt_x
  247.             multi = stepping * ir / max_couch * (max_couch - elt1)
  248.             me(0) = me(0) + irx * multi
  249.             me(1) = me(1) + iry * multi
  250.             me(2) = me(2) + irz * multi
  251.             IF ir THEN GOTO move_ready
  252.     NEXT elt2, elt1
  253.     move_ready:
  254.  
  255.  
  256.     lookzmax = (mouse_z_rot / 2 - 90) * pip180
  257.     lookzmin = (-mouse_z_rot / 2 - 90) * pip180
  258.     mousex = 0
  259.     mousey = 0
  260.         mousex = mousex + _MOUSEMOVEMENTX
  261.         mousey = mousey + _MOUSEMOVEMENTY
  262.     WEND
  263.     me(11) = me(11) + mousey / 7 * msenz
  264.     me(11) = me(11) - 2 * _PI * ABS(me(11) > 2 * _PI)
  265.     me(11) = me(11) + 2 * _PI * ABS(me(11) < 0)
  266.     inv_me10 = 1
  267.     IF me(11) < _PI THEN inv_me10 = -1
  268.     me(10) = me(10) + mousex / 5 * msenx * inv_me10
  269.  
  270.     'calculating points
  271.     cam(0) = me(0) - SIN(me(10) - 180 * pip180) * me(3) / 2
  272.     cam(1) = me(1) - COS(me(10) - 180 * pip180) * me(3) / 2
  273.     cam(2) = me(2) + me(5) / 4
  274.     cam(3) = me(10)
  275.     cam(4) = me(11)
  276.     cosrotz = COS(cam(3))
  277.     sinrotz = SIN(cam(3))
  278.     cosrotx = COS(cam(4))
  279.     sinrotx = SIN(cam(4))
  280.     FOR actual_point = 0 TO points - 1
  281.         IF points(actual_point, 0) THEN
  282.             px = points(actual_point, 1) - cam(0)
  283.             py = points(actual_point, 2) - cam(1)
  284.             pz2 = points(actual_point, 3) - cam(2)
  285.             px3 = px * cosrotz - py * sinrotz
  286.             py2 = px * sinrotz + py * cosrotz
  287.             py3 = py2 * cosrotx - pz2 * sinrotx
  288.             pz3 = py2 * sinrotx + pz2 * cosrotx
  289.             points(actual_point, 4) = -px3 * zoom_xy
  290.             points(actual_point, 5) = -py3 * zoom_xy
  291.             points(actual_point, 6) = -pz3 * zoom_distance
  292.         END IF
  293.     NEXT actual_point
  294.  
  295.     'drawing triangles
  296.     FOR actual_triangle = 0 TO triangles - 1
  297.         IF triangles(actual_triangle, 0) THEN
  298.             wx1 = points(triangles(actual_triangle, 1), 4)
  299.             wy1 = points(triangles(actual_triangle, 1), 5)
  300.             wz1 = points(triangles(actual_triangle, 1), 6)
  301.             wx2 = points(triangles(actual_triangle, 2), 4)
  302.             wy2 = points(triangles(actual_triangle, 2), 5)
  303.             wz2 = points(triangles(actual_triangle, 2), 6)
  304.             wx3 = points(triangles(actual_triangle, 3), 4)
  305.             wy3 = points(triangles(actual_triangle, 3), 5)
  306.             wz3 = points(triangles(actual_triangle, 3), 6)
  307.             sx1 = triangles(actual_triangle, 4)
  308.             sy1 = triangles(actual_triangle, 5)
  309.             sx2 = triangles(actual_triangle, 6)
  310.             sy2 = triangles(actual_triangle, 7)
  311.             sx3 = triangles(actual_triangle, 8)
  312.             sy3 = triangles(actual_triangle, 9)
  313.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy2)-(sx3, sy3), textures(triangles(actual_triangle, 10)) TO(wx1, wy1, wz1)-(wx2, wy2, wz2)-(wx3, wy3, wz3), , _SMOOTH
  314.         END IF
  315.     NEXT actual_triangle
  316.     _DISPLAY
  317.     CLS
  318.     FOR t = 1 TO _WIDTH(monx) / 8 * _HEIGHT(mony) / 16 / LEN(cong$)
  319.         PRINT cong$;
  320.     NEXT t
  321.  
  322. FUNCTION sq (ax, ay, az)
  323.     sq = ax * (maze_y + 1) * (maze_z + 1) + ay * (maze_z + 1) + az
  324. END FUNCTION 'which point ?
  325. SUB sq_add (p0, p1, p2, p3, sk)
  326.     triangles(triangles, 0) = sk
  327.     triangles(triangles + 1, 0) = sk
  328.     triangles(triangles, 1) = p0
  329.     triangles(triangles, 2) = p1
  330.     triangles(triangles, 3) = p2
  331.     triangles(triangles + 1, 1) = p3
  332.     triangles(triangles + 1, 2) = p1
  333.     triangles(triangles + 1, 3) = p2
  334.     points(p0, 0) = 1
  335.     points(p1, 0) = 1
  336.     points(p2, 0) = 1
  337.     points(p3, 0) = 1
  338.     triangles(triangles, 10) = serial
  339.     triangles(triangles + 1, 10) = serial
  340.     triangles(triangles, 6) = _WIDTH(textures(serial)) - 1
  341.     triangles(triangles, 9) = _HEIGHT(textures(serial)) - 1
  342.     triangles(triangles + 1, 6) = _WIDTH(textures(serial)) - 1
  343.     triangles(triangles + 1, 9) = _HEIGHT(textures(serial)) - 1
  344.     triangles(triangles + 1, 4) = _WIDTH(textures(serial)) - 1
  345.     triangles(triangles + 1, 5) = _HEIGHT(textures(serial)) - 1
  346.     triangles = triangles + 2
  347.  

FellippeHeitor

  • Guest
Re: Real Maze in 3D
« Reply #10 on: November 27, 2020, 06:08:36 pm »
That's so much better to look at, thank you.

Marked as best answer by MasterGy on November 27, 2020, 01:26:52 pm

FellippeHeitor

  • Guest
Re: Real Maze in 3D
« Reply #11 on: November 27, 2020, 06:19:26 pm »
With these changes it'll work in the latest version of QB64:

Code: QB64: [Select]
  1. DIM SHARED maze_x, maze_y, maze_z AS _UNSIGNED _BYTE
  2. '-------------------- REAL 3D MAZE --------- SETTINGS -------------------------------------only QB64v1.3
  3.  
  4. maze_x = 9 'maze size X
  5. maze_y = 7 'maze size Y
  6. maze_z = 9 'maze size Z
  7. monx = 1024 'window size X
  8. mon_rat = 0 'window side ratio 0=16:9 ,1=4:3
  9. file_obj$ = "" 'write the track to .OBJ file - if file_obj$ is empty, then writting skip
  10. msenx = .05 'mouse sensitive XY
  11. msenz = .08 'mouse sensitive Z
  12.  
  13. '--------------- ADVANCED SETTINGS --------------------------------------------------------
  14. pre_calc = 2 'calculation for step multiplier impact test
  15. mouse_z_rot = 176 'Z-direction rotation angle of view in degrees
  16. stepping = .04 'movement speed
  17. texture_size = 140 'textures pixel size x,y
  18. texture_margin = 3 'black margin to textures pixel
  19. texture_grey = 50 'random colors  0 grey scale 100 very color
  20. texture_c1 = 130 'circle is the maximum color variation allowed on the texture
  21. texture_c2 = 70 'circle diameter as a percentage of the image
  22. texture_n = 1 'serial number to cube
  23. boss_limit = 30 'display framefrate
  24. zoom_xy = 6 '_maptriangle multiplier XY
  25. zoom_distance = 20 'maptriangle multiplier Z (as large as fisheye optics)
  26. me_dim = .2 'my dimensions
  27. max_couch = 70 'correct angle of impact tolerance
  28. cong$ = "  CONGRATULATIONS !  " 'text to sky when you find exit
  29.  
  30. 'creating 3D MAZE -----------------------------------------------------------------------------------------------------------------------------------------
  31. maze_x = maze_x + ((maze_x AND 1) XOR 1)
  32. maze_y = maze_y + ((maze_y AND 1) XOR 1)
  33. maze_z = maze_z + ((maze_z AND 1) XOR 1)
  34. REDIM maze(maze_x - 1, maze_y - 1, maze_z - 1) AS _UNSIGNED _BYTE '0-fal 1-ureg 2-lehetoseg
  35. REDIM d(5, 2) AS _BYTE
  36. d(0, 2) = 1
  37. d(1, 2) = -1
  38. d(2, 1) = 1
  39. d(3, 1) = -1
  40. d(4, 0) = 1
  41. d(5, 0) = -1
  42. FOR tx = 0 TO maze_x - 1
  43.     FOR ty = 0 TO maze_y - 1
  44.         FOR tz = 0 TO maze_z - 1
  45.             k = 0
  46.             k = ABS((tx = 0 OR ty = 0 OR tz = 0) OR (tx = maze_x - 1 OR ty = maze_y - 1 OR tz = maze_z - 1)) * 3
  47.             IF tx AND 1 AND ty AND 1 AND tz AND 1 THEN k = 1
  48.             maze(tx, ty, tz) = k
  49. NEXT tz, ty, tx
  50.     sx = INT(maze_x * RND(1))
  51.     sy = INT(maze_y * RND(1))
  52.     sz = INT(maze_z * RND(1))
  53. LOOP WHILE maze(sx, sy, sz) <> 1
  54. maze(sx, sy, sz) = 4 'start
  55.     REDIM way(9999, 3)
  56.     wdb = 0
  57.     FOR tx = 0 TO maze_x - 1
  58.         FOR ty = 0 TO maze_y - 1
  59.             FOR tz = 0 TO maze_z - 1
  60.                 IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
  61.                 FOR t = 0 TO 5
  62.                     vpx1 = tx + d(t, 0)
  63.                     vpy1 = ty + d(t, 1)
  64.                     vpz1 = tz + d(t, 2)
  65.                     vpx2 = tx + d(t, 0) * 2
  66.                     vpy2 = ty + d(t, 1) * 2
  67.                     vpz2 = tz + d(t, 2) * 2
  68.                     IF NOT ((vpx2 > maze_x - 1 OR vpx2 < 0) OR (vpy2 > maze_y - 1 OR vpy2 < 0) OR (vpz2 > maze_z - 1 OR vpz2 < 0)) THEN
  69.                         IF maze(vpx1, vpy1, vpz1) = 0 AND maze(vpx2, vpy2, vpz2) = 1 THEN
  70.                             FOR t2 = 0 TO 5
  71.                                 vpx3 = vpx2 + d(t2, 0)
  72.                                 vpy3 = vpy2 + d(t2, 1)
  73.                                 vpz3 = vpz2 + d(t2, 2)
  74.                                 IF maze(vpx3, vpy3, vpz3) = 4 THEN GOTO kovi
  75.                             NEXT t2
  76.                             maze(vpx1, vpy1, vpz1) = 2
  77.                             way(wdb, 0) = tx
  78.                             way(wdb, 1) = ty
  79.                             way(wdb, 2) = tz
  80.                             way(wdb, 3) = t
  81.                             wdb = wdb + 1
  82.                         END IF
  83.                     END IF
  84.                     kovi:
  85.                 NEXT t
  86.     NEXT tz, ty, tx
  87.     aw = INT(wdb * RND(1))
  88.     IF wdb = 0 THEN _CONTINUE
  89.     FOR t = 0 TO 2
  90.         hovax = way(aw, 0) + d(way(aw, 3), 0) * t
  91.         hovay = way(aw, 1) + d(way(aw, 3), 1) * t
  92.         hovaz = way(aw, 2) + d(way(aw, 3), 2) * t
  93.         IF (maze(hovax, hovay, hovaz) = 2) OR (maze(hovax, hovay, hovaz) = 1) THEN maze(hovax, hovay, hovaz) = 4
  94.     NEXT t
  95.     FOR tx = 0 TO maze_x - 1
  96.         FOR ty = 0 TO maze_y - 1
  97.             FOR tz = 0 TO maze_z - 1
  98.                 maze(tx, ty, tz) = (ABS(maze(tx, ty, tz) = 2) XOR 1) * maze(tx, ty, tz)
  99.     NEXT tz, ty, tx
  100.  
  101. '1 entri points on the cube
  102.     sx = INT(maze_x * RND(1))
  103.     sy = INT(maze_y * RND(1))
  104.     sz = INT(maze_z * RND(1))
  105.     felt1 = ABS(sx = 0 OR sx = maze_x - 1) + ABS(sy = 0 OR sy = maze_y - 1) + ABS(sz = 0 OR sz = maze_z - 1) = 1
  106.     nex = ABS(sx = 0 OR sx = maze_x - 1) * -1 * SGN(sx)
  107.     ney = ABS(sy = 0 OR sy = maze_y - 1) * -1 * SGN(sy)
  108.     nez = ABS(sz = 0 OR sz = maze_z - 1) * -1 * SGN(sz)
  109. LOOP UNTIL felt1 AND maze(nex + sx, ney + sy, nez + sz) = 4
  110. maze(sx, sy, sz) = 4
  111. exit_x = sx
  112. exit_y = sy
  113. exit_z = sz
  114.  
  115. 'calculation real points coordinates ,points array index2
  116.  
  117. points = (maze_x + 1) * (maze_y + 1) * (maze_z + 1)
  118. DIM SHARED points(points - 1, 9)
  119. FOR tx = 0 TO maze_x
  120.     FOR ty = 0 TO maze_y
  121.         FOR tz = 0 TO maze_z
  122.             points(sp, 1) = tx
  123.             points(sp, 2) = ty
  124.             points(sp, 3) = tz
  125.             sp = sp + 1
  126. NEXT tz, ty, tx
  127.  
  128.  
  129. 'creating triangles (triangles array index2
  130. 'ena/disa,point1,point2,point3)
  131. DIM SHARED serial
  132. DIM SHARED textures(maze_x * maze_y * maze_z - 1)
  133. FOR tx = 0 TO maze_x - 1
  134.     FOR ty = 0 TO maze_y - 1
  135.         FOR tz = 0 TO maze_z - 1
  136.             cube_sum = cube_sum + ABS(maze(tx, ty, tz) <> 4)
  137. NEXT tz, ty, tx
  138. DIM SHARED triangles(cube_sum * 12 - 1, 10), triangles
  139. FOR tx = 0 TO maze_x - 1
  140.     FOR ty = 0 TO maze_y - 1
  141.         FOR tz = 0 TO maze_z - 1
  142.             IF maze(tx, ty, tz) = 4 THEN _CONTINUE
  143.             'creating texture
  144.             temp = _NEWIMAGE(texture_size, texture_size, 32)
  145.             _DEST temp
  146.             c(0) = INT(256 * RND(1))
  147.             FOR t2 = 1 TO 2
  148.                 c(t2) = c(0) + (256 / 100 * texture_grey * RND(1)) * ((t2 - 1) * 2 - 1)
  149.                 IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
  150.             NEXT t2
  151.             FOR t2 = 0 TO 9
  152.                 SWAP c(INT(3 * RND(1))), c(INT(3 * RND(1)))
  153.             NEXT t2
  154.             CLS '_RGB32(255, 255, 255), _RGB32(0, 0, 0)
  155.             LINE (texture_margin, texture_margin)-(texture_size - texture_margin - 1, texture_size - texture_margin - 1), _RGB32(c(0), c(1), c(2)), BF
  156.             FOR t2 = 0 TO 2
  157.                 c(t2) = INT(c(t2) * texture_c1 / 100)
  158.                 IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
  159.             NEXT t2
  160.             CIRCLE (texture_size / 2, texture_size / 2), texture_size * texture_c2 / 100 / 2, _RGB32(c(0), c(1), c(2))
  161.             PAINT (texture_size / 2, texture_size / 2), _RGB32(c(0), c(1), c(2)), _RGB32(c(0), c(1), c(2))
  162.             IF texture_n THEN num$ = LTRIM$(STR$(serial))
  163.             LOCATE texture_size / 32 + 1, ((texture_size / 8) - LEN(num$)) / 2 + 1
  164.             PRINT num$;
  165.             textures(serial) = _COPYIMAGE(temp, 33)
  166.             _FREEIMAGE temp
  167.             'creating cube
  168.             sq0 = sq(tx, ty, tz)
  169.             sq1 = sq(tx + 1, ty, tz)
  170.             sq2 = sq(tx, ty + 1, tz)
  171.             sq3 = sq(tx + 1, ty + 1, tz)
  172.             sq4 = sq(tx, ty, tz + 1)
  173.             sq5 = sq(tx + 1, ty, tz + 1)
  174.             sq6 = sq(tx, ty + 1, tz + 1)
  175.             sq7 = sq(tx + 1, ty + 1, tz + 1)
  176.             sq_add sq1, sq0, sq3, sq2, 1
  177.             sq_add sq4, sq5, sq6, sq7, 1
  178.             sq_add sq2, sq0, sq6, sq4, 1
  179.             sq_add sq1, sq3, sq5, sq7, 1
  180.             sq_add sq0, sq1, sq4, sq5, 1
  181.             sq_add sq3, sq2, sq7, sq6, 1
  182.  
  183.             serial = serial + 1
  184. NEXT tz, ty, tx
  185.  
  186. IF LEN(file_obj$) THEN 'write to .OBJ
  187.     OPEN "d:\x.obj" FOR OUTPUT AS 1
  188.     FOR t = 0 TO points - 1
  189.         PRINT #1, "v "; points(t, 1); " "; points(t, 2); " "; points(t, 3); " "
  190.     NEXT t
  191.     FOR t = 0 TO triangles - 1
  192.         IF triangles(t, 0) THEN PRINT #1, "f "; triangles(t, 1) + 1; " "; triangles(t, 2) + 1; " "; triangles(t, 3) + 1; " "
  193.     NEXT t
  194.     CLOSE 1
  195.  
  196. 'find the farthest place in the maze from the exit
  197. REDIM me(19)
  198. maxdis = -9999999
  199. FOR tx = 0 TO maze_x - 1
  200.     FOR ty = 0 TO maze_y - 1
  201.         FOR tz = 0 TO maze_z - 1
  202.             IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
  203.             dis = (exit_x - tx) ^ 2 + (exit_y - ty) ^ 2 + (exit_z - tz) ^ 2
  204.             IF dis > maxdis THEN maxdis = dis: start_x = tx: start_y = ty: start_z = tz
  205. NEXT tz, ty, tx
  206. me(0) = start_x + .5
  207. me(1) = start_y + .5
  208. me(2) = start_z + .5
  209.  
  210.  
  211. '---------------- other tasks to be performed
  212. CONST pip180 = 3.141592 / 180
  213. REDIM cam(19)
  214. IF mon_rat THEN mony = INT(monx / 4 * 3) ELSE mony = INT(monx / 16 * 9)
  215. mon = _NEWIMAGE(monx, mony, 32)
  216. _DEST mon
  217. SCREEN mon
  218.  
  219.     _LIMIT boss_limit ' ------------ BOSS CYCLE
  220.     'control
  221.     kw = _KEYDOWN(119) OR _MOUSEBUTTON(1)
  222.     ks = _KEYDOWN(115) OR _MOUSEBUTTON(2)
  223.     ka = _KEYDOWN(97)
  224.     et_ir = ABS(ka OR kd OR kw) OR -ABS(ks)
  225.     kd = _KEYDOWN(100)
  226.     FOR elt1 = 0 TO max_couch STEP 2
  227.         FOR elt2 = 0 TO 360 STEP 12
  228.             elt_xy = SIN(elt2 * pip180) * elt1
  229.             elt_z = COS(elt2 * pip180) * elt1
  230.             szog_xy_elt = -90 * ABS(ka) + 90 * ABS(kd)
  231.             szog_xy = me(10) + (szog_xy_elt + elt_xy) * pip180
  232.             szog_z = me(11) + pip180 * (90 + elt_z)
  233.             irx = -SIN(szog_xy) * COS(szog_z)
  234.             iry = -COS(szog_xy) * COS(szog_z)
  235.             irz = SIN(szog_z)
  236.             ir = et_ir
  237.             multi = stepping * ir * pre_calc * 2
  238.             FOR elt_x = 0 TO 1
  239.                 FOR elt_y = 0 TO 1
  240.                     FOR elt_z = 0 TO 1
  241.                         ana_x = INT(me(0) + irx * multi + (elt_x * 2 - 1) * me_dim / 2)
  242.                         ana_y = INT(me(1) + iry * multi + (elt_y * 2 - 1) * me_dim / 2)
  243.                         ana_z = INT(me(2) + irz * multi + (elt_z * 2 - 1) * me_dim / 2)
  244.                         kivul = ana_x < 0 OR ana_x > maze_x - 1 OR ana_y < 0 OR ana_y > maze_y - 1 OR ana_z < 0 OR ana_z > maze_z - 1
  245.                         IF NOT kivul THEN ir = ir * ABS(maze(ana_x, ana_y, ana_z) = 4)
  246.             NEXT elt_z, elt_y, elt_x
  247.             multi = stepping * ir / max_couch * (max_couch - elt1)
  248.             me(0) = me(0) + irx * multi
  249.             me(1) = me(1) + iry * multi
  250.             me(2) = me(2) + irz * multi
  251.             IF ir THEN GOTO move_ready
  252.     NEXT elt2, elt1
  253.     move_ready:
  254.  
  255.  
  256.     lookzmax = (mouse_z_rot / 2 - 90) * pip180
  257.     lookzmin = (-mouse_z_rot / 2 - 90) * pip180
  258.     mousex = 0
  259.     mousey = 0
  260.         mousex = mousex + mouseMovementX
  261.         mousey = mousey + mouseMovementy
  262.     WEND
  263.     me(11) = me(11) + mousey / 7 * msenz
  264.     me(11) = me(11) - 2 * _PI * ABS(me(11) > 2 * _PI)
  265.     me(11) = me(11) + 2 * _PI * ABS(me(11) < 0)
  266.     inv_me10 = 1
  267.     IF me(11) < _PI THEN inv_me10 = -1
  268.     me(10) = me(10) + mousex / 5 * msenx * inv_me10
  269.  
  270.     'calculating points
  271.     cam(0) = me(0) - SIN(me(10) - 180 * pip180) * me(3) / 2
  272.     cam(1) = me(1) - COS(me(10) - 180 * pip180) * me(3) / 2
  273.     cam(2) = me(2) + me(5) / 4
  274.     cam(3) = me(10)
  275.     cam(4) = me(11)
  276.     cosrotz = COS(cam(3))
  277.     sinrotz = SIN(cam(3))
  278.     cosrotx = COS(cam(4))
  279.     sinrotx = SIN(cam(4))
  280.     FOR actual_point = 0 TO points - 1
  281.         IF points(actual_point, 0) THEN
  282.             px = points(actual_point, 1) - cam(0)
  283.             py = points(actual_point, 2) - cam(1)
  284.             pz2 = points(actual_point, 3) - cam(2)
  285.             px3 = px * cosrotz - py * sinrotz
  286.             py2 = px * sinrotz + py * cosrotz
  287.             py3 = py2 * cosrotx - pz2 * sinrotx
  288.             pz3 = py2 * sinrotx + pz2 * cosrotx
  289.             points(actual_point, 4) = -px3 * zoom_xy
  290.             points(actual_point, 5) = -py3 * zoom_xy
  291.             points(actual_point, 6) = -pz3 * zoom_distance
  292.         END IF
  293.     NEXT actual_point
  294.  
  295.     'drawing triangles
  296.     FOR actual_triangle = 0 TO triangles - 1
  297.         IF triangles(actual_triangle, 0) THEN
  298.             wx1 = points(triangles(actual_triangle, 1), 4)
  299.             wy1 = points(triangles(actual_triangle, 1), 5)
  300.             wz1 = points(triangles(actual_triangle, 1), 6)
  301.             wx2 = points(triangles(actual_triangle, 2), 4)
  302.             wy2 = points(triangles(actual_triangle, 2), 5)
  303.             wz2 = points(triangles(actual_triangle, 2), 6)
  304.             wx3 = points(triangles(actual_triangle, 3), 4)
  305.             wy3 = points(triangles(actual_triangle, 3), 5)
  306.             wz3 = points(triangles(actual_triangle, 3), 6)
  307.             sx1 = triangles(actual_triangle, 4)
  308.             sy1 = triangles(actual_triangle, 5)
  309.             sx2 = triangles(actual_triangle, 6)
  310.             sy2 = triangles(actual_triangle, 7)
  311.             sx3 = triangles(actual_triangle, 8)
  312.             sy3 = triangles(actual_triangle, 9)
  313.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy2)-(sx3, sy3), textures(triangles(actual_triangle, 10)) TO(wx1, wy1, wz1)-(wx2, wy2, wz2)-(wx3, wy3, wz3), , _SMOOTH
  314.         END IF
  315.     NEXT actual_triangle
  316.     _DISPLAY
  317.     CLS
  318.     FOR t = 1 TO _WIDTH(monx) / 8 * _HEIGHT(mony) / 16 / LEN(cong$)
  319.         PRINT cong$;
  320.     NEXT t
  321.  
  322. FUNCTION sq (ax, ay, az)
  323.     sq = ax * (maze_y + 1) * (maze_z + 1) + ay * (maze_z + 1) + az
  324. END FUNCTION 'which point ?
  325. SUB sq_add (p0, p1, p2, p3, sk)
  326.     triangles(triangles, 0) = sk
  327.     triangles(triangles + 1, 0) = sk
  328.     triangles(triangles, 1) = p0
  329.     triangles(triangles, 2) = p1
  330.     triangles(triangles, 3) = p2
  331.     triangles(triangles + 1, 1) = p3
  332.     triangles(triangles + 1, 2) = p1
  333.     triangles(triangles + 1, 3) = p2
  334.     points(p0, 0) = 1
  335.     points(p1, 0) = 1
  336.     points(p2, 0) = 1
  337.     points(p3, 0) = 1
  338.     triangles(triangles, 10) = serial
  339.     triangles(triangles + 1, 10) = serial
  340.     triangles(triangles, 6) = _WIDTH(textures(serial)) - 1
  341.     triangles(triangles, 9) = _HEIGHT(textures(serial)) - 1
  342.     triangles(triangles + 1, 6) = _WIDTH(textures(serial)) - 1
  343.     triangles(triangles + 1, 9) = _HEIGHT(textures(serial)) - 1
  344.     triangles(triangles + 1, 4) = _WIDTH(textures(serial)) - 1
  345.     triangles(triangles + 1, 5) = _HEIGHT(textures(serial)) - 1
  346.     triangles = triangles + 2
  347.  
  348. FUNCTION mouseMovementX
  349.     STATIC lastX
  350.     mouseMovementX = _MOUSEX - lastX
  351.     lastX = _MOUSEX
  352.  
  353. FUNCTION mouseMovementy
  354.     STATIC lastY
  355.     mouseMovementy = _MOUSEY - lastY
  356.     lastY = _MOUSEY
  357.  
« Last Edit: November 27, 2020, 06:21:04 pm by FellippeHeitor »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Real Maze in 3D
« Reply #12 on: November 27, 2020, 06:25:47 pm »
Thank you very much !! I'll put this away! From now on, I will incorporate this.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Real Maze in 3D
« Reply #13 on: November 27, 2020, 06:30:48 pm »


now I understand ... I did this _MOUSEX-oldmousex thing. The trouble with this is that if the mouse goes off the screen, it will not move.

FellippeHeitor

  • Guest
Re: Real Maze in 3D
« Reply #14 on: November 27, 2020, 06:32:05 pm »
Ah, true. On macOS the mouse keeps registering movement even outside the window's borders.