### Author Topic: Real Maze in 3D  (Read 562 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.

#### MasterGy

• Forum Regular
• Posts: 125
• people lie, math never lies
##### 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.
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)
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.

#### bplus

• Forum Resident
• Posts: 5908
• B+ Knot again!
##### Re: Real Maze in 3D
« Reply #1 on: November 26, 2020, 05:33:02 PM »
Wow! that is cool! nice one @MasterGy

#### STxAxTIC

• Library Staff
• Forum Resident
• Posts: 980
• Savage
##### 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!
1) Get it to work.
2) Make the code beautiful.
3) Optimize.

#### FellippeHeitor

• QB64 Developer
• Forum Resident
• Posts: 2701
• LET IT = BE
##### Re: Real Maze in 3D
« Reply #3 on: November 26, 2020, 07:47:05 PM »
Wow!

#### Dav

• Seasoned Forum Regular
• Posts: 498
##### 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

#### MasterGy

• Forum Regular
• Posts: 125
• people lie, math never lies
##### Re: Real Maze in 3D
« Reply #5 on: November 27, 2020, 11:39:50 AM »

#### Petr

• Forum Resident
• Posts: 1536
• The best code is the DNA of the hops.
##### 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.

#### johnno56

• Forum Resident
• Posts: 970
• Live long and prosper.
##### 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.
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.                     kovi:
84.                 NEXT t
85.     NEXT tz, ty, tx
86.     aw = INT(wdb * RND(1))
87.     IF wdb = 0 THEN _CONTINUE
88.     FOR t = 0 TO 2
89.         hovax = way(aw, 0) + d(way(aw, 3), 0) * t
90.         hovay = way(aw, 1) + d(way(aw, 3), 1) * t
91.         hovaz = way(aw, 2) + d(way(aw, 3), 2) * t
92.         IF (maze(hovax, hovay, hovaz) = 2) OR (maze(hovax, hovay, hovaz) = 1) THEN maze(hovax, hovay, hovaz) = 4
93.     NEXT t
94.     FOR tx = 0 TO maze_x - 1
95.         FOR ty = 0 TO maze_y - 1
96.             FOR tz = 0 TO maze_z - 1
97.                 maze(tx, ty, tz) = (ABS(maze(tx, ty, tz) = 2) XOR 1) * maze(tx, ty, tz)
98.     NEXT tz, ty, tx
99.
100. '1 entri points on the cube
101.     sx = INT(maze_x * RND(1))
102.     sy = INT(maze_y * RND(1))
103.     sz = INT(maze_z * RND(1))
104.     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
105.     nex = ABS(sx = 0 OR sx = maze_x - 1) * -1 * SGN(sx)
106.     ney = ABS(sy = 0 OR sy = maze_y - 1) * -1 * SGN(sy)
107.     nez = ABS(sz = 0 OR sz = maze_z - 1) * -1 * SGN(sz)
108. LOOP UNTIL felt1 AND maze(nex + sx, ney + sy, nez + sz) = 4
109. maze(sx, sy, sz) = 4
110. exit_x = sx
111. exit_y = sy
112. exit_z = sz
113.
114. 'calculation real points coordinates ,points array index2:ena/disa ,x,y,z
115. points = (maze_x + 1) * (maze_y + 1) * (maze_z + 1)
116. DIM SHARED points(points - 1, 9)
117. FOR tx = 0 TO maze_x
118.     FOR ty = 0 TO maze_y
119.         FOR tz = 0 TO maze_z
120.             points(sp, 1) = tx
121.             points(sp, 2) = ty
122.             points(sp, 3) = tz
123.             sp = sp + 1
124. NEXT tz, ty, tx
125.
126. 'creating textures
127. DIM SHARED actual_texture
128. 'textures number
129. DIM SHARED textures(textures_c - 1)
130. FOR t = 0 TO textures_c - 1
131.     temp = _NEWIMAGE(texture_size, texture_size, 32)
132.     _DEST temp
133.     c(0) = INT(256 * RND(1))
134.     FOR t2 = 1 TO 2
135.         c(t2) = c(0) + (256 / 100 * texture_grey * RND(1)) * ((t2 - 1) * 2 - 1)
136.         IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
137.     NEXT t2
138.     FOR t2 = 0 TO 9
139.         SWAP c(INT(3 * RND(1))), c(INT(3 * RND(1)))
140.     NEXT t2
141.     CLS , _RGB32(0, 0, 0)
142.     LINE (texture_margin, texture_margin)-(texture_size - texture_margin - 1, texture_size - texture_margin - 1), _RGB32(c(0), c(1), c(2)), BF
143.     FOR t2 = 0 TO 2
144.         c(t2) = INT(c(t2) * texture_c1 / 100)
145.         IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
146.     NEXT t2
147.     CIRCLE (texture_size / 2, texture_size / 2), texture_size * texture_c2 / 100 / 2, _RGB32(c(0), c(1), c(2))
148.     PAINT (texture_size / 2, texture_size / 2), _RGB32(c(0), c(1), c(2)), _RGB32(c(0), c(1), c(2))
149.     textures(t) = _COPYIMAGE(temp, 33)
150.
151. 'creating triangles (triangles array index2:'ena/disa,point1,point2,point3)
152. FOR tx = 0 TO maze_x - 1
153.     FOR ty = 0 TO maze_y - 1
154.         FOR tz = 0 TO maze_z - 1
155.             cube_sum = cube_sum + ABS(maze(tx, ty, tz) <> 4)
156. NEXT tz, ty, tx
157. DIM SHARED triangles(cube_sum * 12 - 1, 10), triangles
158. FOR tx = 0 TO maze_x - 1
159.     FOR ty = 0 TO maze_y - 1
160.         FOR tz = 0 TO maze_z - 1
161.             IF maze(tx, ty, tz) = 4 THEN _CONTINUE
162.             actual_texture = INT(textures_c * RND(1))
163.             sq0 = sq(tx, ty, tz)
164.             sq1 = sq(tx + 1, ty, tz)
165.             sq2 = sq(tx, ty + 1, tz)
166.             sq3 = sq(tx + 1, ty + 1, tz)
167.             sq4 = sq(tx, ty, tz + 1)
168.             sq5 = sq(tx + 1, ty, tz + 1)
169.             sq6 = sq(tx, ty + 1, tz + 1)
170.             sq7 = sq(tx + 1, ty + 1, tz + 1)
171.             sq_add sq0, sq1, sq2, sq3
172.             sq_add sq4, sq5, sq6, sq7
173.             sq_add sq4, sq0, sq6, sq2
174.             sq_add sq5, sq1, sq7, sq3
175.             sq_add sq0, sq1, sq4, sq5
176.             sq_add sq2, sq3, sq6, sq7
177. NEXT tz, ty, tx
178.
179. IF LEN(file_obj\$) THEN 'write to .OBJ
180.     OPEN "d:\x.obj" FOR OUTPUT AS 1
181.     FOR t = 0 TO points - 1
182.         PRINT #1, "v "; points(t, 1); " "; points(t, 2); " "; points(t, 3); " "
183.     NEXT t
184.     FOR t = 0 TO triangles - 1
185.         IF triangles(t, 0) THEN PRINT #1, "f "; triangles(t, 1) + 1; " "; triangles(t, 2) + 1; " "; triangles(t, 3) + 1; " "
186.     NEXT t
187.
188. 'find the farthest place in the maze from the exit
189. REDIM me(19)
190. maxdis = -9999999
191. FOR tx = 0 TO maze_x - 1
192.     FOR ty = 0 TO maze_y - 1
193.         FOR tz = 0 TO maze_z - 1
194.             IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
195.             dis = (exit_x - tx) ^ 2 + (exit_y - ty) ^ 2 + (exit_z - tz) ^ 2
196.             IF dis > maxdis THEN maxdis = dis
197.             start_x = tx
198.             start_y = ty
199.             start_z = tz
200. NEXT tz, ty, tx
201. me(0) = start_x
202. me(1) = start_y
203. me(2) = start_z
204.
205. '---------------- other tasks to be performed
206. CONST pip180 = 3.141592 / 180
207. REDIM cam(19)
208. IF mon_rat THEN mony = INT(monx / 4 * 3) ELSE mony = INT(monx / 16 * 9)
209. mon = _NEWIMAGE(monx, mony, 32)
210. _DEST mon
211. SCREEN mon
212.
213.     _LIMIT boss_limit ' ------------ BOSS CYCLE
214.
215.     'control
216.     kw = _KEYDOWN(119)
217.     ks = _KEYDOWN(115)
218.     ka = _KEYDOWN(97)
219.     kd = _KEYDOWN(100)
220.     szog_xy_elt = -90 * ABS(ka) + 90 * ABS(kd)
221.     ir = ABS(ka OR kd OR kw) OR -ABS(ks)
222.     szog_xy = me(10) + (szog_xy_elt) * pip180
223.     szog_z = me(11) + pip180 * 90
224.     irx = -SIN(szog_xy) * COS(szog_z)
225.     iry = -COS(szog_xy) * COS(szog_z)
226.     irz = SIN(szog_z)
227.     ana_x = INT(me(0) + irx * stepping * ir * pre_calc)
228.     ana_y = INT(me(1) + iry * stepping * ir * pre_calc)
229.     ana_z = INT(me(2) + irz * stepping * ir * pre_calc)
230.     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
231.     IF NOT kivul THEN IF maze(ana_x, ana_y, ana_z) <> 4 THEN ir = 0
232.     me(0) = me(0) + irx * stepping * ir
233.     me(1) = me(1) + iry * stepping * ir
234.     me(2) = me(2) + irz * stepping * ir
235.     mousex = 0
236.     mousey = 0
237.     lookzmax = (mouse_z_rot / 2 - 90) * pip180
238.     lookzmin = (-mouse_z_rot / 2 - 90) * pip180
239.     FOR t = 0 TO 100
240.         makt = _MOUSEINPUT
241.         IF makt THEN mousex = _MOUSEMOVEMENTX + mousex
242.         mousey = _MOUSEMOVEMENTY + mousey
243.         axis = axis + _MOUSEWHEEL
244.     NEXT t
245.     me(10) = me(10) + (mousex / 5 * msenx)
246.     me(11) = me(11) + (mousey / 7 * msenz)
247.     IF me(11) > lookzmax THEN me(11) = lookzmax
248.     IF me(11) < lookzmin THEN me(11) = lookzmin
249.
250.     'calculating points
251.     cam(0) = me(0) - SIN(me(10) - 180 * pip180) * me(3) / 2
252.     cam(1) = me(1) - COS(me(10) - 180 * pip180) * me(3) / 2
253.     cam(2) = me(2) + me(5) / 4
254.     cam(3) = me(10)
255.     cam(4) = me(11)
256.     cosrotz = COS(cam(3))
257.     sinrotz = SIN(cam(3))
258.     cosrotx = COS(cam(4))
259.     sinrotx = SIN(cam(4))
260.     FOR actual_point = 0 TO points - 1
261.         IF points(actual_point, 0) THEN
262.             px = points(actual_point, 1) - cam(0)
263.             py = points(actual_point, 2) - cam(1)
264.             pz2 = points(actual_point, 3) - cam(2)
265.             px3 = px * cosrotz - py * sinrotz
266.             py2 = px * sinrotz + py * cosrotz
267.             py3 = py2 * cosrotx - pz2 * sinrotx
268.             pz3 = py2 * sinrotx + pz2 * cosrotx
269.             points(actual_point, 4) = -px3 * zoom_xy
270.             points(actual_point, 5) = -py3 * zoom_xy
271.             points(actual_point, 6) = -pz3 * zoom_distance
272.     NEXT actual_point
273.
274.     'drawing triangles
275.     FOR actual_triangle = 0 TO triangles - 1
276.         IF triangles(actual_triangle, 0) THEN
277.             wx1 = points(triangles(actual_triangle, 1), 4)
278.             wy1 = points(triangles(actual_triangle, 1), 5)
279.             wz1 = points(triangles(actual_triangle, 1), 6)
280.             wx2 = points(triangles(actual_triangle, 2), 4)
281.             wy2 = points(triangles(actual_triangle, 2), 5)
282.             wz2 = points(triangles(actual_triangle, 2), 6)
283.             wx3 = points(triangles(actual_triangle, 3), 4)
284.             wy3 = points(triangles(actual_triangle, 3), 5)
285.             wz3 = points(triangles(actual_triangle, 3), 6)
286.             sx1 = triangles(actual_triangle, 4)
287.             sy1 = triangles(actual_triangle, 5)
288.             sx2 = triangles(actual_triangle, 6)
289.             sy2 = triangles(actual_triangle, 7)
290.             sx3 = triangles(actual_triangle, 8)
291.             sy3 = triangles(actual_triangle, 9)
292.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy2)-(sx3, sy3), textures(triangles(actual_triangle, 10)) TO(wx1, wy1, wz1)-(wx2, wy2, wz2)-(wx3, wy3, wz3), , _SMOOTH
293.     NEXT actual_triangle
294.     FOR t = 1 TO _WIDTH(monx) / 8 * _HEIGHT(mony) / 16 / LEN(cong\$)
295.         PRINT cong\$;
296.     NEXT t
297.
298. FUNCTION sq (ax, ay, az)
299.     sq = ax * (maze_y + 1) * (maze_z + 1) + ay * (maze_z + 1) + az
300. END FUNCTION 'which point ?
301.
302. SUB sq_add (p0, p1, p2, p3)
303.     triangles(triangles, 0) = 1
304.     triangles(triangles, 1) = p0
305.     triangles(triangles, 2) = p1
306.     triangles(triangles, 3) = p2
307.     triangles(triangles + 1, 0) = 1
308.     triangles(triangles + 1, 1) = p3
309.     triangles(triangles + 1, 2) = p1
310.     triangles(triangles + 1, 3) = p2
311.     points(p0, 0) = 1
312.     points(p1, 0) = 1
313.     points(p2, 0) = 1
314.     points(p3, 0) = 1
315.     triangles(triangles, 10) = actual_texture
316.     triangles(triangles + 1, 10) = triangles(triangles, 10)
317.     triangles(triangles, 6) = _WIDTH(textures(actual_texture)) - 1
318.     triangles(triangles, 9) = _HEIGHT(textures(actual_texture)) - 1
319.     triangles(triangles + 1, 6) = triangles(triangles, 6)
320.     triangles(triangles + 1, 9) = triangles(triangles, 9)
321.     triangles = triangles + 2
322.
Logic is the beginning of wisdom.

#### bplus

• Forum Resident
• Posts: 5908
• B+ Knot again!
##### 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 »

#### MasterGy

• Forum Regular
• Posts: 125
• people lie, math never lies
##### 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.
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.                     kovi:
83.                 NEXT t
84.     NEXT tz, ty, tx
85.     aw = INT(wdb * RND(1))
86.     IF wdb = 0 THEN _CONTINUE
87.     FOR t = 0 TO 2
88.         hovax = way(aw, 0) + d(way(aw, 3), 0) * t
89.         hovay = way(aw, 1) + d(way(aw, 3), 1) * t
90.         hovaz = way(aw, 2) + d(way(aw, 3), 2) * t
91.         IF (maze(hovax, hovay, hovaz) = 2) OR (maze(hovax, hovay, hovaz) = 1) THEN maze(hovax, hovay, hovaz) = 4
92.     NEXT t
93.     FOR tx = 0 TO maze_x - 1
94.         FOR ty = 0 TO maze_y - 1
95.             FOR tz = 0 TO maze_z - 1
96.                 maze(tx, ty, tz) = (ABS(maze(tx, ty, tz) = 2) XOR 1) * maze(tx, ty, tz)
97.     NEXT tz, ty, tx
98.
99. '1 entri points on the cube
100.     sx = INT(maze_x * RND(1))
101.     sy = INT(maze_y * RND(1))
102.     sz = INT(maze_z * RND(1))
103.     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
104.     nex = ABS(sx = 0 OR sx = maze_x - 1) * -1 * SGN(sx)
105.     ney = ABS(sy = 0 OR sy = maze_y - 1) * -1 * SGN(sy)
106.     nez = ABS(sz = 0 OR sz = maze_z - 1) * -1 * SGN(sz)
107. LOOP UNTIL felt1 AND maze(nex + sx, ney + sy, nez + sz) = 4
108. maze(sx, sy, sz) = 4
109. exit_x = sx
110. exit_y = sy
111. exit_z = sz
112.
113. 'calculation real points coordinates ,points array index2
114.
115. points = (maze_x + 1) * (maze_y + 1) * (maze_z + 1)
116. DIM SHARED points(points - 1, 9)
117. FOR tx = 0 TO maze_x
118.     FOR ty = 0 TO maze_y
119.         FOR tz = 0 TO maze_z
120.             points(sp, 1) = tx
121.             points(sp, 2) = ty
122.             points(sp, 3) = tz
123.             sp = sp + 1
124. NEXT tz, ty, tx
125.
126.
127. 'creating triangles (triangles array index2
128. 'ena/disa,point1,point2,point3)
129. DIM SHARED serial
130. DIM SHARED textures(maze_x * maze_y * maze_z - 1)
131. FOR tx = 0 TO maze_x - 1
132.     FOR ty = 0 TO maze_y - 1
133.         FOR tz = 0 TO maze_z - 1
134.             cube_sum = cube_sum + ABS(maze(tx, ty, tz) <> 4)
135. NEXT tz, ty, tx
136. DIM SHARED triangles(cube_sum * 12 - 1, 10), triangles
137. FOR tx = 0 TO maze_x - 1
138.     FOR ty = 0 TO maze_y - 1
139.         FOR tz = 0 TO maze_z - 1
140.             IF maze(tx, ty, tz) = 4 THEN _CONTINUE
141.             'creating texture
142.             temp = _NEWIMAGE(texture_size, texture_size, 32)
143.             _DEST temp
144.             c(0) = INT(256 * RND(1))
145.             FOR t2 = 1 TO 2
146.                 c(t2) = c(0) + (256 / 100 * texture_grey * RND(1)) * ((t2 - 1) * 2 - 1)
147.                 IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
148.             NEXT t2
149.             FOR t2 = 0 TO 9
150.                 SWAP c(INT(3 * RND(1))), c(INT(3 * RND(1)))
151.             NEXT t2
152.             CLS '_RGB32(255, 255, 255), _RGB32(0, 0, 0)
153.             LINE (texture_margin, texture_margin)-(texture_size - texture_margin - 1, texture_size - texture_margin - 1), _RGB32(c(0), c(1), c(2)), BF
154.             FOR t2 = 0 TO 2
155.                 c(t2) = INT(c(t2) * texture_c1 / 100)
156.                 IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
157.             NEXT t2
158.             CIRCLE (texture_size / 2, texture_size / 2), texture_size * texture_c2 / 100 / 2, _RGB32(c(0), c(1), c(2))
159.             PAINT (texture_size / 2, texture_size / 2), _RGB32(c(0), c(1), c(2)), _RGB32(c(0), c(1), c(2))
160.             IF texture_n THEN num\$ = LTRIM\$(STR\$(serial))
161.             LOCATE texture_size / 32 + 1, ((texture_size / 8) - LEN(num\$)) / 2 + 1
162.             PRINT num\$;
163.             textures(serial) = _COPYIMAGE(temp, 33)
164.             _FREEIMAGE temp
165.             'creating cube
166.             sq0 = sq(tx, ty, tz)
167.             sq1 = sq(tx + 1, ty, tz)
168.             sq2 = sq(tx, ty + 1, tz)
169.             sq3 = sq(tx + 1, ty + 1, tz)
170.             sq4 = sq(tx, ty, tz + 1)
171.             sq5 = sq(tx + 1, ty, tz + 1)
172.             sq6 = sq(tx, ty + 1, tz + 1)
173.             sq7 = sq(tx + 1, ty + 1, tz + 1)
174.             sq_add sq1, sq0, sq3, sq2, 1
175.             sq_add sq4, sq5, sq6, sq7, 1
176.             sq_add sq2, sq0, sq6, sq4, 1
177.             sq_add sq1, sq3, sq5, sq7, 1
178.             sq_add sq0, sq1, sq4, sq5, 1
179.             sq_add sq3, sq2, sq7, sq6, 1
180.
181.             serial = serial + 1
182. NEXT tz, ty, tx
183.
184. IF LEN(file_obj\$) THEN 'write to .OBJ
185.     OPEN "d:\x.obj" FOR OUTPUT AS 1
186.     FOR t = 0 TO points - 1
187.         PRINT #1, "v "; points(t, 1); " "; points(t, 2); " "; points(t, 3); " "
188.     NEXT t
189.     FOR t = 0 TO triangles - 1
190.         IF triangles(t, 0) THEN PRINT #1, "f "; triangles(t, 1) + 1; " "; triangles(t, 2) + 1; " "; triangles(t, 3) + 1; " "
191.     NEXT t
192.
193. 'find the farthest place in the maze from the exit
194. REDIM me(19)
195. maxdis = -9999999
196. FOR tx = 0 TO maze_x - 1
197.     FOR ty = 0 TO maze_y - 1
198.         FOR tz = 0 TO maze_z - 1
199.             IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
200.             dis = (exit_x - tx) ^ 2 + (exit_y - ty) ^ 2 + (exit_z - tz) ^ 2
201.             IF dis > maxdis THEN maxdis = dis: start_x = tx: start_y = ty: start_z = tz
202. NEXT tz, ty, tx
203. me(0) = start_x + .5
204. me(1) = start_y + .5
205. me(2) = start_z + .5
206.
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.     'control
218.     kw = _KEYDOWN(119) OR _MOUSEBUTTON(1)
219.     ks = _KEYDOWN(115) OR _MOUSEBUTTON(2)
220.     ka = _KEYDOWN(97)
221.     et_ir = ABS(ka OR kd OR kw) OR -ABS(ks)
222.     kd = _KEYDOWN(100)
223.     FOR elt1 = 0 TO max_couch STEP 2
224.         FOR elt2 = 0 TO 360 STEP 12
225.             elt_xy = SIN(elt2 * pip180) * elt1
226.             elt_z = COS(elt2 * pip180) * elt1
227.             szog_xy_elt = -90 * ABS(ka) + 90 * ABS(kd)
228.             szog_xy = me(10) + (szog_xy_elt + elt_xy) * pip180
229.             szog_z = me(11) + pip180 * (90 + elt_z)
230.             irx = -SIN(szog_xy) * COS(szog_z)
231.             iry = -COS(szog_xy) * COS(szog_z)
232.             irz = SIN(szog_z)
233.             ir = et_ir
234.             multi = stepping * ir * pre_calc * 2
235.             FOR elt_x = 0 TO 1
236.                 FOR elt_y = 0 TO 1
237.                     FOR elt_z = 0 TO 1
238.                         ana_x = INT(me(0) + irx * multi + (elt_x * 2 - 1) * me_dim / 2)
239.                         ana_y = INT(me(1) + iry * multi + (elt_y * 2 - 1) * me_dim / 2)
240.                         ana_z = INT(me(2) + irz * multi + (elt_z * 2 - 1) * me_dim / 2)
241.                         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
242.                         IF NOT kivul THEN ir = ir * ABS(maze(ana_x, ana_y, ana_z) = 4)
243.             NEXT elt_z, elt_y, elt_x
244.             multi = stepping * ir / max_couch * (max_couch - elt1)
245.             me(0) = me(0) + irx * multi
246.             me(1) = me(1) + iry * multi
247.             me(2) = me(2) + irz * multi
248.             IF ir THEN GOTO move_ready
249.     NEXT elt2, elt1
251.
252.
253.     lookzmax = (mouse_z_rot / 2 - 90) * pip180
254.     lookzmin = (-mouse_z_rot / 2 - 90) * pip180
255.     mousex = 0
256.     mousey = 0
257.         mousex = mousex + _MOUSEMOVEMENTX
258.         mousey = mousey + _MOUSEMOVEMENTY
259.     me(11) = me(11) + mousey / 7 * msenz
260.     me(11) = me(11) - 2 * _PI * ABS(me(11) > 2 * _PI)
261.     me(11) = me(11) + 2 * _PI * ABS(me(11) < 0)
262.     inv_me10 = 1
263.     IF me(11) < _PI THEN inv_me10 = -1
264.     me(10) = me(10) + mousex / 5 * msenx * inv_me10
265.
266.     'calculating points
267.     cam(0) = me(0) - SIN(me(10) - 180 * pip180) * me(3) / 2
268.     cam(1) = me(1) - COS(me(10) - 180 * pip180) * me(3) / 2
269.     cam(2) = me(2) + me(5) / 4
270.     cam(3) = me(10)
271.     cam(4) = me(11)
272.     cosrotz = COS(cam(3))
273.     sinrotz = SIN(cam(3))
274.     cosrotx = COS(cam(4))
275.     sinrotx = SIN(cam(4))
276.     FOR actual_point = 0 TO points - 1
277.         IF points(actual_point, 0) THEN
278.             px = points(actual_point, 1) - cam(0)
279.             py = points(actual_point, 2) - cam(1)
280.             pz2 = points(actual_point, 3) - cam(2)
281.             px3 = px * cosrotz - py * sinrotz
282.             py2 = px * sinrotz + py * cosrotz
283.             py3 = py2 * cosrotx - pz2 * sinrotx
284.             pz3 = py2 * sinrotx + pz2 * cosrotx
285.             points(actual_point, 4) = -px3 * zoom_xy
286.             points(actual_point, 5) = -py3 * zoom_xy
287.             points(actual_point, 6) = -pz3 * zoom_distance
288.     NEXT actual_point
289.
290.     'drawing triangles
291.     FOR actual_triangle = 0 TO triangles - 1
292.         IF triangles(actual_triangle, 0) THEN
293.             wx1 = points(triangles(actual_triangle, 1), 4)
294.             wy1 = points(triangles(actual_triangle, 1), 5)
295.             wz1 = points(triangles(actual_triangle, 1), 6)
296.             wx2 = points(triangles(actual_triangle, 2), 4)
297.             wy2 = points(triangles(actual_triangle, 2), 5)
298.             wz2 = points(triangles(actual_triangle, 2), 6)
299.             wx3 = points(triangles(actual_triangle, 3), 4)
300.             wy3 = points(triangles(actual_triangle, 3), 5)
301.             wz3 = points(triangles(actual_triangle, 3), 6)
302.             sx1 = triangles(actual_triangle, 4)
303.             sy1 = triangles(actual_triangle, 5)
304.             sx2 = triangles(actual_triangle, 6)
305.             sy2 = triangles(actual_triangle, 7)
306.             sx3 = triangles(actual_triangle, 8)
307.             sy3 = triangles(actual_triangle, 9)
308.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy2)-(sx3, sy3), textures(triangles(actual_triangle, 10)) TO(wx1, wy1, wz1)-(wx2, wy2, wz2)-(wx3, wy3, wz3), , _SMOOTH
309.     NEXT actual_triangle
310.     FOR t = 1 TO _WIDTH(monx) / 8 * _HEIGHT(mony) / 16 / LEN(cong\$)
311.         PRINT cong\$;
312.     NEXT t
313.
314. FUNCTION sq (ax, ay, az)
315.     sq = ax * (maze_y + 1) * (maze_z + 1) + ay * (maze_z + 1) + az
316. END FUNCTION 'which point ?
317. SUB sq_add (p0, p1, p2, p3, sk)
318.     triangles(triangles, 0) = sk
319.     triangles(triangles + 1, 0) = sk
320.     triangles(triangles, 1) = p0
321.     triangles(triangles, 2) = p1
322.     triangles(triangles, 3) = p2
323.     triangles(triangles + 1, 1) = p3
324.     triangles(triangles + 1, 2) = p1
325.     triangles(triangles + 1, 3) = p2
326.     points(p0, 0) = 1
327.     points(p1, 0) = 1
328.     points(p2, 0) = 1
329.     points(p3, 0) = 1
330.     triangles(triangles, 10) = serial
331.     triangles(triangles + 1, 10) = serial
332.     triangles(triangles, 6) = _WIDTH(textures(serial)) - 1
333.     triangles(triangles, 9) = _HEIGHT(textures(serial)) - 1
334.     triangles(triangles + 1, 6) = _WIDTH(textures(serial)) - 1
335.     triangles(triangles + 1, 9) = _HEIGHT(textures(serial)) - 1
336.     triangles(triangles + 1, 4) = _WIDTH(textures(serial)) - 1
337.     triangles(triangles + 1, 5) = _HEIGHT(textures(serial)) - 1
338.     triangles = triangles + 2
339.

#### FellippeHeitor

• QB64 Developer
• Forum Resident
• Posts: 2701
• LET IT = BE
##### 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, 08:26:52 PM

#### FellippeHeitor

• QB64 Developer
• Forum Resident
• Posts: 2701
• LET IT = BE
##### Re: Real Maze in 3D
« Reply #11 on: November 27, 2020, 06:19:26 PM »

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.
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.                     kovi:
83.                 NEXT t
84.     NEXT tz, ty, tx
85.     aw = INT(wdb * RND(1))
86.     IF wdb = 0 THEN _CONTINUE
87.     FOR t = 0 TO 2
88.         hovax = way(aw, 0) + d(way(aw, 3), 0) * t
89.         hovay = way(aw, 1) + d(way(aw, 3), 1) * t
90.         hovaz = way(aw, 2) + d(way(aw, 3), 2) * t
91.         IF (maze(hovax, hovay, hovaz) = 2) OR (maze(hovax, hovay, hovaz) = 1) THEN maze(hovax, hovay, hovaz) = 4
92.     NEXT t
93.     FOR tx = 0 TO maze_x - 1
94.         FOR ty = 0 TO maze_y - 1
95.             FOR tz = 0 TO maze_z - 1
96.                 maze(tx, ty, tz) = (ABS(maze(tx, ty, tz) = 2) XOR 1) * maze(tx, ty, tz)
97.     NEXT tz, ty, tx
98.
99. '1 entri points on the cube
100.     sx = INT(maze_x * RND(1))
101.     sy = INT(maze_y * RND(1))
102.     sz = INT(maze_z * RND(1))
103.     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
104.     nex = ABS(sx = 0 OR sx = maze_x - 1) * -1 * SGN(sx)
105.     ney = ABS(sy = 0 OR sy = maze_y - 1) * -1 * SGN(sy)
106.     nez = ABS(sz = 0 OR sz = maze_z - 1) * -1 * SGN(sz)
107. LOOP UNTIL felt1 AND maze(nex + sx, ney + sy, nez + sz) = 4
108. maze(sx, sy, sz) = 4
109. exit_x = sx
110. exit_y = sy
111. exit_z = sz
112.
113. 'calculation real points coordinates ,points array index2
114.
115. points = (maze_x + 1) * (maze_y + 1) * (maze_z + 1)
116. DIM SHARED points(points - 1, 9)
117. FOR tx = 0 TO maze_x
118.     FOR ty = 0 TO maze_y
119.         FOR tz = 0 TO maze_z
120.             points(sp, 1) = tx
121.             points(sp, 2) = ty
122.             points(sp, 3) = tz
123.             sp = sp + 1
124. NEXT tz, ty, tx
125.
126.
127. 'creating triangles (triangles array index2
128. 'ena/disa,point1,point2,point3)
129. DIM SHARED serial
130. DIM SHARED textures(maze_x * maze_y * maze_z - 1)
131. FOR tx = 0 TO maze_x - 1
132.     FOR ty = 0 TO maze_y - 1
133.         FOR tz = 0 TO maze_z - 1
134.             cube_sum = cube_sum + ABS(maze(tx, ty, tz) <> 4)
135. NEXT tz, ty, tx
136. DIM SHARED triangles(cube_sum * 12 - 1, 10), triangles
137. FOR tx = 0 TO maze_x - 1
138.     FOR ty = 0 TO maze_y - 1
139.         FOR tz = 0 TO maze_z - 1
140.             IF maze(tx, ty, tz) = 4 THEN _CONTINUE
141.             'creating texture
142.             temp = _NEWIMAGE(texture_size, texture_size, 32)
143.             _DEST temp
144.             c(0) = INT(256 * RND(1))
145.             FOR t2 = 1 TO 2
146.                 c(t2) = c(0) + (256 / 100 * texture_grey * RND(1)) * ((t2 - 1) * 2 - 1)
147.                 IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
148.             NEXT t2
149.             FOR t2 = 0 TO 9
150.                 SWAP c(INT(3 * RND(1))), c(INT(3 * RND(1)))
151.             NEXT t2
152.             CLS '_RGB32(255, 255, 255), _RGB32(0, 0, 0)
153.             LINE (texture_margin, texture_margin)-(texture_size - texture_margin - 1, texture_size - texture_margin - 1), _RGB32(c(0), c(1), c(2)), BF
154.             FOR t2 = 0 TO 2
155.                 c(t2) = INT(c(t2) * texture_c1 / 100)
156.                 IF c(t2) < 0 THEN c(t2) = 0 ELSE IF c(t2) > 255 THEN c(t2) = 255
157.             NEXT t2
158.             CIRCLE (texture_size / 2, texture_size / 2), texture_size * texture_c2 / 100 / 2, _RGB32(c(0), c(1), c(2))
159.             PAINT (texture_size / 2, texture_size / 2), _RGB32(c(0), c(1), c(2)), _RGB32(c(0), c(1), c(2))
160.             IF texture_n THEN num\$ = LTRIM\$(STR\$(serial))
161.             LOCATE texture_size / 32 + 1, ((texture_size / 8) - LEN(num\$)) / 2 + 1
162.             PRINT num\$;
163.             textures(serial) = _COPYIMAGE(temp, 33)
164.             _FREEIMAGE temp
165.             'creating cube
166.             sq0 = sq(tx, ty, tz)
167.             sq1 = sq(tx + 1, ty, tz)
168.             sq2 = sq(tx, ty + 1, tz)
169.             sq3 = sq(tx + 1, ty + 1, tz)
170.             sq4 = sq(tx, ty, tz + 1)
171.             sq5 = sq(tx + 1, ty, tz + 1)
172.             sq6 = sq(tx, ty + 1, tz + 1)
173.             sq7 = sq(tx + 1, ty + 1, tz + 1)
174.             sq_add sq1, sq0, sq3, sq2, 1
175.             sq_add sq4, sq5, sq6, sq7, 1
176.             sq_add sq2, sq0, sq6, sq4, 1
177.             sq_add sq1, sq3, sq5, sq7, 1
178.             sq_add sq0, sq1, sq4, sq5, 1
179.             sq_add sq3, sq2, sq7, sq6, 1
180.
181.             serial = serial + 1
182. NEXT tz, ty, tx
183.
184. IF LEN(file_obj\$) THEN 'write to .OBJ
185.     OPEN "d:\x.obj" FOR OUTPUT AS 1
186.     FOR t = 0 TO points - 1
187.         PRINT #1, "v "; points(t, 1); " "; points(t, 2); " "; points(t, 3); " "
188.     NEXT t
189.     FOR t = 0 TO triangles - 1
190.         IF triangles(t, 0) THEN PRINT #1, "f "; triangles(t, 1) + 1; " "; triangles(t, 2) + 1; " "; triangles(t, 3) + 1; " "
191.     NEXT t
192.
193. 'find the farthest place in the maze from the exit
194. REDIM me(19)
195. maxdis = -9999999
196. FOR tx = 0 TO maze_x - 1
197.     FOR ty = 0 TO maze_y - 1
198.         FOR tz = 0 TO maze_z - 1
199.             IF maze(tx, ty, tz) <> 4 THEN _CONTINUE
200.             dis = (exit_x - tx) ^ 2 + (exit_y - ty) ^ 2 + (exit_z - tz) ^ 2
201.             IF dis > maxdis THEN maxdis = dis: start_x = tx: start_y = ty: start_z = tz
202. NEXT tz, ty, tx
203. me(0) = start_x + .5
204. me(1) = start_y + .5
205. me(2) = start_z + .5
206.
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.     'control
218.     kw = _KEYDOWN(119) OR _MOUSEBUTTON(1)
219.     ks = _KEYDOWN(115) OR _MOUSEBUTTON(2)
220.     ka = _KEYDOWN(97)
221.     et_ir = ABS(ka OR kd OR kw) OR -ABS(ks)
222.     kd = _KEYDOWN(100)
223.     FOR elt1 = 0 TO max_couch STEP 2
224.         FOR elt2 = 0 TO 360 STEP 12
225.             elt_xy = SIN(elt2 * pip180) * elt1
226.             elt_z = COS(elt2 * pip180) * elt1
227.             szog_xy_elt = -90 * ABS(ka) + 90 * ABS(kd)
228.             szog_xy = me(10) + (szog_xy_elt + elt_xy) * pip180
229.             szog_z = me(11) + pip180 * (90 + elt_z)
230.             irx = -SIN(szog_xy) * COS(szog_z)
231.             iry = -COS(szog_xy) * COS(szog_z)
232.             irz = SIN(szog_z)
233.             ir = et_ir
234.             multi = stepping * ir * pre_calc * 2
235.             FOR elt_x = 0 TO 1
236.                 FOR elt_y = 0 TO 1
237.                     FOR elt_z = 0 TO 1
238.                         ana_x = INT(me(0) + irx * multi + (elt_x * 2 - 1) * me_dim / 2)
239.                         ana_y = INT(me(1) + iry * multi + (elt_y * 2 - 1) * me_dim / 2)
240.                         ana_z = INT(me(2) + irz * multi + (elt_z * 2 - 1) * me_dim / 2)
241.                         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
242.                         IF NOT kivul THEN ir = ir * ABS(maze(ana_x, ana_y, ana_z) = 4)
243.             NEXT elt_z, elt_y, elt_x
244.             multi = stepping * ir / max_couch * (max_couch - elt1)
245.             me(0) = me(0) + irx * multi
246.             me(1) = me(1) + iry * multi
247.             me(2) = me(2) + irz * multi
248.             IF ir THEN GOTO move_ready
249.     NEXT elt2, elt1
251.
252.
253.     lookzmax = (mouse_z_rot / 2 - 90) * pip180
254.     lookzmin = (-mouse_z_rot / 2 - 90) * pip180
255.     mousex = 0
256.     mousey = 0
257.         mousex = mousex + mouseMovementX
258.         mousey = mousey + mouseMovementy
259.     me(11) = me(11) + mousey / 7 * msenz
260.     me(11) = me(11) - 2 * _PI * ABS(me(11) > 2 * _PI)
261.     me(11) = me(11) + 2 * _PI * ABS(me(11) < 0)
262.     inv_me10 = 1
263.     IF me(11) < _PI THEN inv_me10 = -1
264.     me(10) = me(10) + mousex / 5 * msenx * inv_me10
265.
266.     'calculating points
267.     cam(0) = me(0) - SIN(me(10) - 180 * pip180) * me(3) / 2
268.     cam(1) = me(1) - COS(me(10) - 180 * pip180) * me(3) / 2
269.     cam(2) = me(2) + me(5) / 4
270.     cam(3) = me(10)
271.     cam(4) = me(11)
272.     cosrotz = COS(cam(3))
273.     sinrotz = SIN(cam(3))
274.     cosrotx = COS(cam(4))
275.     sinrotx = SIN(cam(4))
276.     FOR actual_point = 0 TO points - 1
277.         IF points(actual_point, 0) THEN
278.             px = points(actual_point, 1) - cam(0)
279.             py = points(actual_point, 2) - cam(1)
280.             pz2 = points(actual_point, 3) - cam(2)
281.             px3 = px * cosrotz - py * sinrotz
282.             py2 = px * sinrotz + py * cosrotz
283.             py3 = py2 * cosrotx - pz2 * sinrotx
284.             pz3 = py2 * sinrotx + pz2 * cosrotx
285.             points(actual_point, 4) = -px3 * zoom_xy
286.             points(actual_point, 5) = -py3 * zoom_xy
287.             points(actual_point, 6) = -pz3 * zoom_distance
288.     NEXT actual_point
289.
290.     'drawing triangles
291.     FOR actual_triangle = 0 TO triangles - 1
292.         IF triangles(actual_triangle, 0) THEN
293.             wx1 = points(triangles(actual_triangle, 1), 4)
294.             wy1 = points(triangles(actual_triangle, 1), 5)
295.             wz1 = points(triangles(actual_triangle, 1), 6)
296.             wx2 = points(triangles(actual_triangle, 2), 4)
297.             wy2 = points(triangles(actual_triangle, 2), 5)
298.             wz2 = points(triangles(actual_triangle, 2), 6)
299.             wx3 = points(triangles(actual_triangle, 3), 4)
300.             wy3 = points(triangles(actual_triangle, 3), 5)
301.             wz3 = points(triangles(actual_triangle, 3), 6)
302.             sx1 = triangles(actual_triangle, 4)
303.             sy1 = triangles(actual_triangle, 5)
304.             sx2 = triangles(actual_triangle, 6)
305.             sy2 = triangles(actual_triangle, 7)
306.             sx3 = triangles(actual_triangle, 8)
307.             sy3 = triangles(actual_triangle, 9)
308.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy2)-(sx3, sy3), textures(triangles(actual_triangle, 10)) TO(wx1, wy1, wz1)-(wx2, wy2, wz2)-(wx3, wy3, wz3), , _SMOOTH
309.     NEXT actual_triangle
310.     FOR t = 1 TO _WIDTH(monx) / 8 * _HEIGHT(mony) / 16 / LEN(cong\$)
311.         PRINT cong\$;
312.     NEXT t
313.
314. FUNCTION sq (ax, ay, az)
315.     sq = ax * (maze_y + 1) * (maze_z + 1) + ay * (maze_z + 1) + az
316. END FUNCTION 'which point ?
317. SUB sq_add (p0, p1, p2, p3, sk)
318.     triangles(triangles, 0) = sk
319.     triangles(triangles + 1, 0) = sk
320.     triangles(triangles, 1) = p0
321.     triangles(triangles, 2) = p1
322.     triangles(triangles, 3) = p2
323.     triangles(triangles + 1, 1) = p3
324.     triangles(triangles + 1, 2) = p1
325.     triangles(triangles + 1, 3) = p2
326.     points(p0, 0) = 1
327.     points(p1, 0) = 1
328.     points(p2, 0) = 1
329.     points(p3, 0) = 1
330.     triangles(triangles, 10) = serial
331.     triangles(triangles + 1, 10) = serial
332.     triangles(triangles, 6) = _WIDTH(textures(serial)) - 1
333.     triangles(triangles, 9) = _HEIGHT(textures(serial)) - 1
334.     triangles(triangles + 1, 6) = _WIDTH(textures(serial)) - 1
335.     triangles(triangles + 1, 9) = _HEIGHT(textures(serial)) - 1
336.     triangles(triangles + 1, 4) = _WIDTH(textures(serial)) - 1
337.     triangles(triangles + 1, 5) = _HEIGHT(textures(serial)) - 1
338.     triangles = triangles + 2
339.
340. FUNCTION mouseMovementX
341.     STATIC lastX
342.     mouseMovementX = _MOUSEX - lastX
343.     lastX = _MOUSEX
344.
345. FUNCTION mouseMovementy
346.     STATIC lastY
347.     mouseMovementy = _MOUSEY - lastY
348.     lastY = _MOUSEY
349.
« Last Edit: November 27, 2020, 06:21:04 PM by FellippeHeitor »

#### MasterGy

• Forum Regular
• Posts: 125
• people lie, math never lies
##### 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.

#### MasterGy

• Forum Regular
• Posts: 125
• people lie, math never lies
##### 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

• QB64 Developer
• Forum Resident
• Posts: 2701
• LET IT = BE
##### 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.