12-18-2022, 05:13 PM
unfortunately, I can't explain it well because of the translation, but I drew it
the point is that every point that appears on the screen must be calculated
the point is that every point that appears on the screen must be calculated
Code: (Select All)
'Modified 3d points program by MasterGy
Screen _NewImage(1000, 600, 32)
whitewall = _NewImage(1000, 600, 32)
Line (1, 1)-(1000, 600), _RGB(180, 180, 180), BF
_PutImage (1, 1)-(1000, 600), 0, whitewall, (1, 1)-(1000, 600)
Cls
bluewall = _NewImage(100, 100, 32)
Line (1, 1)-(100, 100), _RGB(10, 10, 20), BF
_PutImage (1, 1)-(100, 100), 0, bluewall, (1, 1)-(100, 100)
octo = _LoadImage("octo.png", 32)
wall2 = _CopyImage(whitewall, 33)
floor = _CopyImage(bluewall, 33)
floor2 = _CopyImage(octo, 33)
'create spectator
Dim Shared sp(6)
sp(0) = 500
sp(1) = 1500
sp(2) = 400
sp(3) = 0 'looking in the direction of the observer XZ
sp(4) = 0 'looking in the direction of the observer YZ
sp(5) = 1 'multiplier X-Y see
sp(6) = 1 'multiplier Z see
'create screen
scr = _NewImage(1000, 1000 / _DesktopWidth * _DesktopHeight, 32)
Screen scr
_MouseHide
_FullScreen
_Dest scr
_DisplayOrder _Hardware , _Software
Do
_Limit 40
_PutImage (1, 1), wall2
'draw floor tiles
For ctx = 1 To 500 Step 20
For cty = 1 To 500 Step 20
ps = 1
x = 0 + ps * ctx
y = 0 + ps * cty
z = 530
rotate_to_maptriangle x, y, z 'position of floor tiles from the point of view of the observer
_MapTriangle (0, 0)-(100, 0)-(0, 100), floor To(x - ps, y - ps, z)-(x + ps, y - ps, z)-(x - ps, y + ps, z)
_MapTriangle (100, 100)-(100, 0)-(0, 100), floor To(x + ps, y + ps, z)-(x + ps, y - ps, z)-(x - ps, y + ps, z)
Next cty
Next ctx
'draw octo floor
octo_size = 250 'half size
x1 = -octo_size + 250
y1 = -octo_size + 250
z1 = 530
rotate_to_maptriangle x1, y1, z1 'octo floor
x2 = octo_size + 250
y2 = -octo_size + 250
z2 = 530
rotate_to_maptriangle x2, y2, z2 'octo floor
x3 = -octo_size + 250
y3 = octo_size + 250
z3 = 530
rotate_to_maptriangle x3, y3, z3 'octo floor
x4 = octo_size + 250
y4 = octo_size + 250
z4 = 530
rotate_to_maptriangle x4, y4, z4 'octo floor
_MapTriangle (0, 0)-(750, 0)-(0, 750), floor2 To(x1, y1, z1)-(x2, y2, z2)-(x3, y3, z3), , _Smooth
_MapTriangle (750, 750)-(750, 0)-(0, 750), floor2 To(x4, y4, z4)-(x2, y2, z2)-(x3, y3, z3), , _Smooth
_Display
'mouse input axis movement and mousewheel
mousex = mousex * .6
mousey = mousey * .6
mw = 0
While _MouseInput: mousex = mousex + _MouseMovementX: mousey = mousey + _MouseMovementY: mw = mw + _MouseWheel: Wend 'movement data read
'control spectator
mouse_sens = .001 'mouse rotating sensitive
sp(3) = sp(3) - mousex * mouse_sens
sp(4) = sp(4) + mousey * mouse_sens
If Abs(sp(4)) > _Pi / 2 Then sp(4) = _Pi / 2 * Sgn(sp(4))
vec_x = (Sin(sp(3)) * (Cos(sp(4) + _Pi)))
vec_y = (Cos(sp(3)) * (Cos(sp(4) + _Pi)))
vec_z = -Sin(sp(4) + _Pi)
speed = 40 'moving speed
moving = Abs(_MouseButton(1) Or _KeyDown(Asc("w"))) * speed - Abs(_MouseButton(2) Or _KeyDown(Asc("s"))) * speed
sp(0) = sp(0) + vec_x * moving
sp(1) = sp(1) + vec_y * moving
sp(2) = sp(2) + vec_z * moving
Loop Until _KeyDown(27)
Sub rotate_to_maptriangle (x, y, z)
x2 = x - sp(0)
y2 = y - sp(1)
z2 = z - sp(2)
rotate_2d x2, y2, sp(3)
rotate_2d y2, z2, sp(4) + _Pi / 2
x = x2 * sp(5)
y = y2 * sp(5)
z = z2 * sp(6)
End Sub
Sub rotate_2d (x, y, ang)
x1 = x * Cos(ang) - y * Sin(ang)
y1 = x * Sin(ang) + y * Cos(ang)
x = x1: y = y1
End Sub