'-------------------- REAL 3D MAZE --------- SETTINGS -------------------------------------only QB64v1.3
maze_x = 9 'maze size X
maze_y = 7 'maze size Y
maze_z = 9 'maze size Z
monx = 1024 'window size X
mon_rat = 0 'window side ratio 0=16:9 ,1=4:3
file_obj$ = "" 'write the track to .OBJ file - if file_obj$ is empty, then writting skip
msenx = .05 'mouse sensitive XY
msenz = .08 'mouse sensitive Z
'--------------- ADVANCED SETTINGS --------------------------------------------------------
pre_calc = 2 'calculation for step multiplier impact test
mouse_z_rot = 176 'Z-direction rotation angle of view in degrees
stepping = .04 'movement speed
texture_size = 140 'textures pixel size x,y
texture_margin = 3 'black margin to textures pixel
texture_grey = 50 'random colors 0 grey scale 100 very color
texture_c1 = 130 'circle is the maximum color variation allowed on the texture
texture_c2 = 70 'circle diameter as a percentage of the image
texture_n = 1 'serial number to cube
boss_limit = 30 'display framefrate
zoom_xy = 6 '_maptriangle multiplier XY
zoom_distance = 20 'maptriangle multiplier Z (as large as fisheye optics)
me_dim = .2 'my dimensions
max_couch = 70 'correct angle of impact tolerance
cong$ = " CONGRATULATIONS ! " 'text to sky when you find exit
'creating 3D MAZE -----------------------------------------------------------------------------------------------------------------------------------------
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)d(0, 2) = 1
d(1, 2) = -1
d(2, 1) = 1
d(3, 1) = -1
d(4, 0) = 1
d(5, 0) = -1
k = 0
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 maze(tx, ty, tz) = k
maze(sx, sy, sz) = 4 'start
wdb = 0
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
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 IF maze
(vpx1
, vpy1
, vpz1
) = 0 AND maze
(vpx2
, vpy2
, vpz2
) = 1 THEN vpx3 = vpx2 + d(t2, 0)
vpy3 = vpy2 + d(t2, 1)
vpz3 = vpz2 + d(t2, 2)
maze(vpx1, vpy1, vpz1) = 2
way(wdb, 0) = tx
way(wdb, 1) = ty
way(wdb, 2) = tz
way(wdb, 3) = t
wdb = wdb + 1
kovi:
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
IF (maze
(hovax
, hovay
, hovaz
) = 2) OR (maze
(hovax
, hovay
, hovaz
) = 1) THEN maze
(hovax
, hovay
, hovaz
) = 4 maze
(tx
, ty
, tz
) = (ABS(maze
(tx
, ty
, tz
) = 2) XOR 1) * maze
(tx
, ty
, tz
)
'1 entri points on the cube
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 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
)maze(sx, sy, sz) = 4
exit_x = sx
exit_y = sy
exit_z = sz
'calculation real points coordinates ,points array index2
points = (maze_x + 1) * (maze_y + 1) * (maze_z + 1)
points(sp, 1) = tx
points(sp, 2) = ty
points(sp, 3) = tz
sp = sp + 1
'creating triangles (triangles array index2
'ena/disa,point1,point2,point3)
DIM SHARED textures
(maze_x
* maze_y
* maze_z
- 1) cube_sum
= cube_sum
+ ABS(maze
(tx
, ty
, tz
) <> 4)DIM SHARED triangles
(cube_sum
* 12 - 1, 10), triangles
'creating texture
temp
= _NEWIMAGE(texture_size
, texture_size
, 32) c
(t2
) = c
(0) + (256 / 100 * texture_grey
* RND(1)) * ((t2
- 1) * 2 - 1) CLS '_RGB32(255, 255, 255), _RGB32(0, 0, 0) LINE (texture_margin
, texture_margin
)-(texture_size
- texture_margin
- 1, texture_size
- texture_margin
- 1), _RGB32(c
(0), c
(1), c
(2)), BF
c
(t2
) = INT(c
(t2
) * texture_c1
/ 100) CIRCLE (texture_size
/ 2, texture_size
/ 2), texture_size
* texture_c2
/ 100 / 2, _RGB32(c
(0), c
(1), c
(2)) PAINT (texture_size
/ 2, texture_size
/ 2), _RGB32(c
(0), c
(1), c
(2)), _RGB32(c
(0), c
(1), c
(2)) LOCATE texture_size
/ 32 + 1, ((texture_size
/ 8) - LEN(num$
)) / 2 + 1 'creating cube
sq0 = sq(tx, ty, tz)
sq1 = sq(tx + 1, ty, tz)
sq2 = sq(tx, ty + 1, tz)
sq3 = sq(tx + 1, ty + 1, tz)
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)
sq_add sq1, sq0, sq3, sq2, 1
sq_add sq4, sq5, sq6, sq7, 1
sq_add sq2, sq0, sq6, sq4, 1
sq_add sq1, sq3, sq5, sq7, 1
sq_add sq0, sq1, sq4, sq5, 1
sq_add sq3, sq2, sq7, sq6, 1
serial = serial + 1
PRINT #1, "v "; points
(t
, 1);
" "; points
(t
, 2);
" "; points
(t
, 3);
" " FOR t
= 0 TO triangles
- 1 IF triangles
(t
, 0) THEN PRINT #1, "f "; triangles
(t
, 1) + 1;
" "; triangles
(t
, 2) + 1;
" "; triangles
(t
, 3) + 1;
" "
'find the farthest place in the maze from the exit
maxdis = -9999999
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
me(0) = start_x + .5
me(1) = start_y + .5
me(2) = start_z + .5
'---------------- other tasks to be performed
CONST pip180
= 3.141592 / 180
_LIMIT boss_limit
' ------------ BOSS CYCLE 'control
elt_xy
= SIN(elt2
* pip180
) * elt1
elt_z
= COS(elt2
* pip180
) * elt1
szog_xy_elt
= -90 * ABS(ka
) + 90 * ABS(kd
) szog_xy = me(10) + (szog_xy_elt + elt_xy) * pip180
szog_z = me(11) + pip180 * (90 + elt_z)
irx
= -SIN(szog_xy
) * COS(szog_z
) iry
= -COS(szog_xy
) * COS(szog_z
) ir = et_ir
multi = stepping * ir * pre_calc * 2
ana_x
= INT(me
(0) + irx
* multi
+ (elt_x
* 2 - 1) * me_dim
/ 2) ana_y
= INT(me
(1) + iry
* multi
+ (elt_y
* 2 - 1) * me_dim
/ 2) ana_z
= INT(me
(2) + irz
* multi
+ (elt_z
* 2 - 1) * me_dim
/ 2) 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 IF NOT kivul
THEN ir
= ir
* ABS(maze
(ana_x
, ana_y
, ana_z
) = 4) multi = stepping * ir / max_couch * (max_couch - elt1)
me(0) = me(0) + irx * multi
me(1) = me(1) + iry * multi
me(2) = me(2) + irz * multi
move_ready:
lookzmax = (mouse_z_rot / 2 - 90) * pip180
lookzmin = (-mouse_z_rot / 2 - 90) * pip180
mousex = 0
mousey = 0
mousex = mousex + mouseMovementX
mousey = mousey + mouseMovementy
me(11) = me(11) + mousey / 7 * msenz
me
(11) = me
(11) - 2 * _PI * ABS(me
(11) > 2 * _PI) me
(11) = me
(11) + 2 * _PI * ABS(me
(11) < 0) inv_me10 = 1
me(10) = me(10) + mousex / 5 * msenx * inv_me10
'calculating points
cam
(0) = me
(0) - SIN(me
(10) - 180 * pip180
) * me
(3) / 2 cam
(1) = me
(1) - COS(me
(10) - 180 * pip180
) * me
(3) / 2 cam(2) = me(2) + me(5) / 4
cam(3) = me(10)
cam(4) = me(11)
FOR actual_point
= 0 TO points
- 1 IF points
(actual_point
, 0) THEN px = points(actual_point, 1) - cam(0)
py = points(actual_point, 2) - cam(1)
pz2 = points(actual_point, 3) - cam(2)
px3 = px * cosrotz - py * sinrotz
py2 = px * sinrotz + py * cosrotz
py3 = py2 * cosrotx - pz2 * sinrotx
pz3 = py2 * sinrotx + pz2 * cosrotx
points(actual_point, 4) = -px3 * zoom_xy
points(actual_point, 5) = -py3 * zoom_xy
points(actual_point, 6) = -pz3 * zoom_distance
'drawing triangles
FOR actual_triangle
= 0 TO triangles
- 1 IF triangles
(actual_triangle
, 0) THEN wx1 = points(triangles(actual_triangle, 1), 4)
wy1 = points(triangles(actual_triangle, 1), 5)
wz1 = points(triangles(actual_triangle, 1), 6)
wx2 = points(triangles(actual_triangle, 2), 4)
wy2 = points(triangles(actual_triangle, 2), 5)
wz2 = points(triangles(actual_triangle, 2), 6)
wx3 = points(triangles(actual_triangle, 3), 4)
wy3 = points(triangles(actual_triangle, 3), 5)
wz3 = points(triangles(actual_triangle, 3), 6)
sx1 = triangles(actual_triangle, 4)
sy1 = triangles(actual_triangle, 5)
sx2 = triangles(actual_triangle, 6)
sy2 = triangles(actual_triangle, 7)
sx3 = triangles(actual_triangle, 8)
sy3 = triangles(actual_triangle, 9)
_MAPTRIANGLE (sx1
, sy1
)-(sx2
, sy2
)-(sx3
, sy3
), textures
(triangles
(actual_triangle
, 10)) TO(wx1
, wy1
, wz1
)-(wx2
, wy2
, wz2
)-(wx3
, wy3
, wz3
), , _SMOOTH
sq = ax * (maze_y + 1) * (maze_z + 1) + ay * (maze_z + 1) + az
SUB sq_add
(p0
, p1
, p2
, p3
, sk
) triangles(triangles, 0) = sk
triangles(triangles + 1, 0) = sk
triangles(triangles, 1) = p0
triangles(triangles, 2) = p1
triangles(triangles, 3) = p2
triangles(triangles + 1, 1) = p3
triangles(triangles + 1, 2) = p1
triangles(triangles + 1, 3) = p2
points(p0, 0) = 1
points(p1, 0) = 1
points(p2, 0) = 1
points(p3, 0) = 1
triangles(triangles, 10) = serial
triangles(triangles + 1, 10) = serial
triangles
(triangles
, 6) = _WIDTH(textures
(serial
)) - 1 triangles
(triangles
, 9) = _HEIGHT(textures
(serial
)) - 1 triangles
(triangles
+ 1, 6) = _WIDTH(textures
(serial
)) - 1 triangles
(triangles
+ 1, 9) = _HEIGHT(textures
(serial
)) - 1 triangles
(triangles
+ 1, 4) = _WIDTH(textures
(serial
)) - 1 triangles
(triangles
+ 1, 5) = _HEIGHT(textures
(serial
)) - 1 triangles = triangles + 2