3d surface images
#2
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


[Image: ok2.jpg]



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
Reply


Messages In This Thread
3d surface images - by james2464 - 11-20-2022, 04:58 AM
RE: 3d surface images - by MasterGy - 12-18-2022, 05:13 PM
RE: 3d surface images - by james2464 - 12-18-2022, 09:02 PM
RE: 3d surface images - by MasterGy - 12-18-2022, 09:19 PM
RE: 3d surface images - by james2464 - 12-18-2022, 09:52 PM
RE: 3d surface images - by james2464 - 12-19-2022, 12:16 AM
RE: 3d surface images - by bplus - 12-19-2022, 01:12 AM
RE: 3d surface images - by mnrvovrfc - 12-19-2022, 10:27 AM
RE: 3d surface images - by james2464 - 12-19-2022, 02:26 AM
RE: 3d surface images - by james2464 - 12-19-2022, 06:01 AM
RE: 3d surface images - by MasterGy - 12-19-2022, 01:16 PM
RE: 3d surface images - by james2464 - 12-19-2022, 09:09 PM
RE: 3d surface images - by MasterGy - 12-19-2022, 09:20 PM
RE: 3d surface images - by james2464 - 12-19-2022, 09:44 PM
RE: 3d surface images - by MasterGy - 12-19-2022, 09:59 PM
RE: 3d surface images - by james2464 - 12-19-2022, 10:13 PM
RE: 3d surface images - by james2464 - 12-20-2022, 12:33 PM
RE: 3d surface images - by MasterGy - 12-20-2022, 01:52 PM
RE: 3d surface images - by james2464 - 12-20-2022, 03:52 PM
RE: 3d surface images - by MasterGy - 12-20-2022, 01:58 PM
RE: 3d surface images - by SMcNeill - 12-20-2022, 03:37 PM
RE: 3d surface images - by james2464 - 12-20-2022, 04:26 PM
RE: 3d surface images - by MasterGy - 12-20-2022, 07:33 PM
RE: 3d surface images - by mnrvovrfc - 12-20-2022, 11:22 PM
RE: 3d surface images - by SMcNeill - 12-20-2022, 11:39 PM
RE: 3d surface images - by james2464 - 12-20-2022, 06:02 PM
RE: 3d surface images - by MasterGy - 12-20-2022, 07:18 PM
RE: 3d surface images - by james2464 - 12-20-2022, 07:42 PM
RE: 3d surface images - by james2464 - 12-21-2022, 04:49 AM
RE: 3d surface images - by james2464 - 12-21-2022, 07:45 PM
RE: 3d surface images - by james2464 - 12-23-2022, 08:28 PM
RE: 3d surface images - by mnrvovrfc - 12-23-2022, 09:09 PM
RE: 3d surface images - by MasterGy - 12-24-2022, 01:39 PM
RE: 3d surface images - by MasterGy - 12-24-2022, 01:55 PM
RE: 3d surface images - by james2464 - 12-24-2022, 05:56 PM
RE: 3d surface images - by james2464 - 12-24-2022, 05:58 PM
RE: 3d surface images - by bplus - 12-24-2022, 06:34 PM
RE: 3d surface images - by james2464 - 12-24-2022, 07:40 PM
RE: 3d surface images - by MasterGy - 12-24-2022, 07:20 PM
RE: 3d surface images - by james2464 - 12-24-2022, 07:39 PM
RE: 3d surface images - by OldMoses - 12-25-2022, 12:25 AM
RE: 3d surface images - by james2464 - 12-26-2022, 05:13 PM
RE: 3d surface images - by james2464 - 12-26-2022, 05:19 PM
RE: 3d surface images - by MasterGy - 12-27-2022, 10:46 AM
RE: 3d surface images - by james2464 - 12-27-2022, 09:17 PM
RE: 3d surface images - by MasterGy - 12-27-2022, 10:53 AM



Users browsing this thread: 19 Guest(s)