3d surface images
#1
I've been trying to make this work but I'm stumped.

I messed around with a 3d points program by MasterGy and managed to get a sense of the space and coordinates.   There's something that I can't seem to grasp though...that's placing an image onto a surface (using _maptriangle).

In this program, I wanted to place an image on the 'floor'.   So I started by placing about 600 small tiles in a grid, exactly where I want to place the image.   But images always rotate towards the viewer.   Even the small tiles do this.   The grid of tiles (as a whole) doesn't do this - only each individual tile.   How to lay the image flat is what I'm trying to figure out.   

So if anyone here knows how this works....

I'll attach the image I'm trying to use but any 750x750 image will do.


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 = 2
            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

    ps = 500
    x = 500
    y = 500
    z = 30
    rotate_to_maptriangle x, y, z 'octo floor

    _MapTriangle (0, 0)-(750, 0)-(0, 750), floor2 To(x - ps, y - ps, z)-(x + ps, y - ps, z)-(x - ps, y + ps, z), , _Smooth
    _MapTriangle (750, 750)-(750, 0)-(0, 750), floor2 To(x + ps, y + ps, z)-(x + ps, y - ps, z)-(x - ps, y + ps, z), , _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


Attached Files Image(s)
   
Reply
#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
#3
Big Grin

This is exactly what I was looking for!

Thank you!
Reply
#4
(12-18-2022, 09:02 PM)james2464 Wrote: Big Grin

This is exactly what I was looking for!

Thank you!

calm me down please ! Smile do you understand the operation?
Reply
#5
Trying to understand... I was confused about how to communicate with 3d map triangle...

I think I'll get a better understanding now that I have a working example.  I will attempt to add walls and a ceiling.

This was the main part I needed:   

Code: (Select All)
    _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

And also this:

Code: (Select All)
    octo_size = 250 'half size

    x1 = -octo_size + 250
    y1 = -octo_size + 250
    z1 = 500
    rotate_to_maptriangle x1, y1, z1 'octo floor

    x2 = octo_size + 250
    y2 = -octo_size + 250
    z2 = 500
    rotate_to_maptriangle x2, y2, z2 'octo floor

    x3 = -octo_size + 250
    y3 = octo_size + 250
    z3 = 500
    rotate_to_maptriangle x3, y3, z3 'octo floor

    x4 = octo_size + 250
    y4 = octo_size + 250
    z4 = 500
    rotate_to_maptriangle x4, y4, z4 'octo floor

I didn't realize it needed to be done this way.   This is very helpful.

Thanks again, this should be a lot of fun.
Reply
#6
Now that I have an idea how to do it, here's a 3D room.   No attached images needed, everything is in the code.

The mouse is used to look around.   You can move with the mouse buttons or by using the W and S keys.

Thanks again, MasterGy!

Code: (Select All)
'3d Room - james2464 - Dec 18 2022

'Credit to 3D program and tutorial by MasterGy

Randomize Timer

Screen _NewImage(1000, 600, 32)


Dim Shared c(100) As Long

bgspace = _NewImage(1000, 600, 32)
Line (1, 1)-(1000, 600), _RGB(180, 180, 180), BF
_PutImage (1, 1)-(1000, 600), 0, bgspace, (1, 1)-(1000, 600)
Cls
floatingtiles = _NewImage(100, 100, 32)
Line (1, 1)-(100, 100), _RGB(250, 250, 250), BF
_PutImage (1, 1)-(100, 100), 0, floatingtiles, (1, 1)-(100, 100)


colour1

Dim Shared floor1, wall1

'create floor image
floor1 = _NewImage(500, 500, 32)
makefloor

'create wall image
wall1 = _NewImage(500, 100, 32)
makewall


bgspace2 = _CopyImage(bgspace, 33)
tile = _CopyImage(floatingtiles, 33)
floor2 = _CopyImage(floor1, 33)
wall2 = _CopyImage(wall1, 33)

'create spectator
Dim Shared sp(6)
sp(0) = 250
sp(1) = 250
sp(2) = 450
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), bgspace2 'background



    'draw floating 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 = 400
            rotate_to_maptriangle x, y, z 

            _MapTriangle (0, 0)-(100, 0)-(0, 100), tile To(x - ps, y - ps, z)-(x + ps, y - ps, z)-(x - ps, y + ps, z)
            _MapTriangle (100, 100)-(100, 0)-(0, 100), tile To(x + ps, y + ps, z)-(x + ps, y - ps, z)-(x - ps, y + ps, z)
        Next cty
    Next ctx




    'floor

    x1 = 0
    y1 = 0
    z1 = 500
    rotate_to_maptriangle x1, y1, z1 'floor

    x2 = 500
    y2 = 0
    z2 = 500
    rotate_to_maptriangle x2, y2, z2 'floor

    x3 = 0
    y3 = 500
    z3 = 500
    rotate_to_maptriangle x3, y3, z3 'floor

    x4 = 500
    y4 = 500
    z4 = 500
    rotate_to_maptriangle x4, y4, z4 'floor

    _MapTriangle (0, 0)-(500, 0)-(0, 500), floor2 To(x1, y1, z1)-(x2, y2, z2)-(x3, y3, z3), , _Smooth
    _MapTriangle (500, 500)-(500, 0)-(0, 500), floor2 To(x4, y4, z4)-(x2, y2, z2)-(x3, y3, z3), , _Smooth


    

    x1 = 0
    y1 = 0
    z1 = 400
    rotate_to_maptriangle x1, y1, z1 'wall

    x2 = 500
    y2 = 0
    z2 = 400
    rotate_to_maptriangle x2, y2, z2 'wall

    x3 = 0
    y3 = 0
    z3 = 500
    rotate_to_maptriangle x3, y3, z3 'wall

    x4 = 500
    y4 = 0
    z4 = 500
    rotate_to_maptriangle x4, y4, z4 'wall

    _MapTriangle (0, 0)-(500, 0)-(0, 100), wall2 To(x1, y1, z1)-(x2, y2, z2)-(x3, y3, z3), , _Smooth
    _MapTriangle (500, 100)-(500, 0)-(0, 100), wall2 To(x4, y4, z4)-(x2, y2, z2)-(x3, y3, z3), , _Smooth



    'brick wall 2

    x1 = 500
    y1 = 500
    z1 = 400
    rotate_to_maptriangle x1, y1, z1 'wall

    x2 = 0
    y2 = 500
    z2 = 400
    rotate_to_maptriangle x2, y2, z2 'wall

    x3 = 500
    y3 = 500
    z3 = 500
    rotate_to_maptriangle x3, y3, z3 'wall

    x4 = 0
    y4 = 500
    z4 = 500
    rotate_to_maptriangle x4, y4, z4 'wall

    _MapTriangle (0, 0)-(500, 0)-(0, 100), wall2 To(x1, y1, z1)-(x2, y2, z2)-(x3, y3, z3), , _Smooth
    _MapTriangle (500, 100)-(500, 0)-(0, 100), wall2 To(x4, y4, z4)-(x2, y2, z2)-(x3, y3, z3), , _Smooth



    'brick wall 3

    x1 = 0
    y1 = 500
    z1 = 400
    rotate_to_maptriangle x1, y1, z1 'wall

    x2 = 0
    y2 = 0
    z2 = 400
    rotate_to_maptriangle x2, y2, z2 'wall

    x3 = 0
    y3 = 500
    z3 = 500
    rotate_to_maptriangle x3, y3, z3 'wall

    x4 = 0
    y4 = 0
    z4 = 500
    rotate_to_maptriangle x4, y4, z4 'wall

    _MapTriangle (0, 0)-(500, 0)-(0, 100), wall2 To(x1, y1, z1)-(x2, y2, z2)-(x3, y3, z3), , _Smooth
    _MapTriangle (500, 100)-(500, 0)-(0, 100), wall2 To(x4, y4, z4)-(x2, y2, z2)-(x3, y3, z3), , _Smooth




    'brick wall 4

    x1 = 500
    y1 = 0
    z1 = 400
    rotate_to_maptriangle x1, y1, z1 'wall

    x2 = 500
    y2 = 500
    z2 = 400
    rotate_to_maptriangle x2, y2, z2 'wall

    x3 = 500
    y3 = 0
    z3 = 500
    rotate_to_maptriangle x3, y3, z3 'wall

    x4 = 500
    y4 = 500
    z4 = 500
    rotate_to_maptriangle x4, y4, z4 'wall

    _MapTriangle (0, 0)-(500, 0)-(0, 100), wall2 To(x1, y1, z1)-(x2, y2, z2)-(x3, y3, z3), , _Smooth
    _MapTriangle (500, 100)-(500, 0)-(0, 100), wall2 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 = .9 '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


Sub colour1
    c(0) = _RGB(0, 0, 0)
    c(1) = _RGB(255, 255, 255)
    c(2) = _RGB(85, 45, 0)
    c(3) = _RGB(0, 45, 85)
    c(4) = _RGB(40, 60, 0)
    c(5) = _RGB(0, 25, 75)
    c(6) = _RGB(75, 25, 0)
    c(7) = _RGB(150, 130, 0)
    c(8) = _RGB(150, 150, 250)
    c(9) = _RGB(250, 150, 150)
    c(10) = _RGB(150, 250, 150)
    c(11) = _RGB(150, 150, 255)
    c(12) = _RGB(40, 30, 0)
    c(13) = _RGB(255, 0, 0)
    c(14) = _RGB(50, 150, 50)
    c(15) = _RGB(155, 155, 155)
    c(16) = _RGB(165, 165, 165)
    c(17) = _RGB(175, 175, 175)
End Sub


Sub makefloor
    Cls
    Line (0, 0)-(500, 500), c(12), BF 'floor background

    Line (0, 0)-(50, 50), c(4), BF
    Line (450, 0)-(500, 50), c(5), BF
    Line (450, 450)-(500, 500), c(6), BF
    Line (0, 450)-(50, 500), c(7), BF


    For t = 1 To 6000
        x1 = Int(Rnd * 500)
        y1 = Int(Rnd * 500)
        PSet (x1, y1), c(0)
        x1 = Int(Rnd * 500)
        y1 = Int(Rnd * 500)
        PSet (x1, y1), c(2)
        x1 = Int(Rnd * 500)
        y1 = Int(Rnd * 500)
        PSet (x1, y1), c(3)
    Next t


    _Display

    _PutImage (1, 1)-(500, 500), 0, floor1, (1, 1)-(500, 500)

    'Sleep

End Sub



Sub makewall
    Cls
    Line (0, 0)-(500, 100), c(15), BF 'wall background

    Line (0, 0)-(20, 20), c(4), BF
    Line (480, 0)-(500, 20), c(5), BF
    Line (480, 80)-(500, 100), c(6), BF
    Line (0, 80)-(20, 100), c(7), BF


    For t = 1 To 6000
        x1 = Int(Rnd * 500)
        y1 = Int(Rnd * 100)
        PSet (x1, y1), c(16)
        x1 = Int(Rnd * 500)
        y1 = Int(Rnd * 100)
        PSet (x1, y1), c(17)
    Next t

    Locate 4, 28
    Color c(4), c(0)
    Print "QB64PE"

    _Display

    _PutImage (1, 1)-(500, 100), 0, wall1, (1, 1)-(500, 100)
    _ClearColor c(0), wall1
    'Sleep

End Sub
Reply
#7
Thumbs Up 
Nice @james2464! I move mouse left and room swings left, vice versa for right, as it should be! IMHO

I may get into 3D yet ;-)) MasterGy may be genius but I want to vomit when I move mouse in his programs (sorry about my bodily reactions MasterGy).
b = b + ...
Reply
#8
Thanks Bplus!  QB64 is amazing, and 3D seems like a lot of fun.   Hoping to learn some more.

Glad you enjoyed this without much trouble.   Cheers!
Reply
#9
I tried to make some kind of empty office building.   Also condensed the code a bit.

This allows walking, not floating.   And you can't go through the walls.  (or comment/delete lines 146-149)
Code: (Select All)
'3d Room - james2464 - Dec 18 2022

'Credit to 3D program and tutorial by MasterGy

Randomize Timer

Screen _NewImage(1000, 600, 32)


Dim Shared c(100) As Long

bgspace = _NewImage(1000, 600, 32)
Line (1, 1)-(1000, 600), _RGB(120, 120, 180), BF
_PutImage (1, 1)-(1000, 600), 0, bgspace, (1, 1)-(1000, 600)

Cls


colour1

Dim Shared floor1, wall1, wall2, ceiling1, ground1

'create floor image
floor1 = _NewImage(500, 500, 32)
makefloor

'create wall1 image
wall1 = _NewImage(500, 100, 32)
makewall

'create wall2 image
wall2 = _NewImage(500, 100, 32)
makewall2

'create ceiling image
ceiling1 = _NewImage(500, 500, 32)
makeceiling

'create ground image
ground1 = _NewImage(500, 500, 32)
makeground



bgspace2 = _CopyImage(bgspace, 33)
tile = _CopyImage(floatingtiles, 33)
floor1b = _CopyImage(floor1, 33)
wall1b = _CopyImage(wall1, 33)
wall2b = _CopyImage(wall2, 33)
ceiling1b = _CopyImage(ceiling1, 33)
ground1b = _CopyImage(ground1, 33)

'create spectator
Dim Shared sp(6)
sp(0) = 250 'X position
sp(1) = 250 'Y
sp(2) = 450 'Z
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), bgspace2 'background

    'floor
    x1 = 0: y1 = 0: z1 = 500: r2m x1, y1, z1: x2 = 500: y2 = 0: z2 = 500: r2m x2, y2, z2
    x3 = 0: y3 = 500: z3 = 500: r2m x3, y3, z3: x4 = 500: y4 = 500: z4 = 500: r2m x4, y4, z4
    maptexture floor1b, 500, 500, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4

    'wall 1
    x1 = 0: y1 = 0: z1 = 400: r2m x1, y1, z1: x2 = 500: y2 = 0: z2 = 400: r2m x2, y2, z2
    x3 = 0: y3 = 0: z3 = 500: r2m x3, y3, z3: x4 = 500: y4 = 0: z4 = 500: r2m x4, y4, z4
    maptexture wall2b, 500, 100, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4

    'wall 2
    x1 = 500: y1 = 500: z1 = 400: r2m x1, y1, z1: x2 = 0: y2 = 500: z2 = 400: r2m x2, y2, z2
    x3 = 500: y3 = 500: z3 = 500: r2m x3, y3, z3: x4 = 0: y4 = 500: z4 = 500: r2m x4, y4, z4
    maptexture wall2b, 500, 100, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4

    'wall 3
    x1 = 500: y1 = 0: z1 = 400: r2m x1, y1, z1: x2 = 500: y2 = 500: z2 = 400: r2m x2, y2, z2
    x3 = 500: y3 = 0: z3 = 500: r2m x3, y3, z3: x4 = 500: y4 = 500: z4 = 500: r2m x4, y4, z4
    maptexture wall1b, 500, 100, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4

    'wall 4
    x1 = 0: y1 = 500: z1 = 400: r2m x1, y1, z1: x2 = 0: y2 = 0: z2 = 400: r2m x2, y2, z2
    x3 = 0: y3 = 500: z3 = 500: r2m x3, y3, z3: x4 = 0: y4 = 0: z4 = 500: r2m x4, y4, z4
    maptexture wall1b, 500, 100, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4

    'ceiling
    x1 = 0: y1 = 0: z1 = 400: r2m x1, y1, z1: x2 = 500: y2 = 0: z2 = 400: r2m x2, y2, z2
    x3 = 0: y3 = 500: z3 = 400: r2m x3, y3, z3: x4 = 500: y4 = 500: z4 = 400: r2m x4, y4, z4
    maptexture ceiling1b, 500, 500, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4

    'ground
    x1 = -1500: y1 = -1500: z1 = 502: r2m x1, y1, z1: x2 = 2000: y2 = -1500: z2 = 502: r2m x2, y2, z2
    x3 = -1500: y3 = 2000: z3 = 502: r2m x3, y3, z3: x4 = 2000: y4 = 2000: z4 = 502: r2m x4, y4, z4
    maptexture ground1b, 500, 500, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4



    _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 = .0007 '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 = 2 '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
    If sp(0) > 465 Then sp(0) = 465
    If sp(1) > 465 Then sp(1) = 465
    If sp(0) < 35 Then sp(0) = 35
    If sp(1) < 35 Then sp(1) = 35

Loop Until _KeyDown(27)



'=============================================================================================================
'=============================================================================================================
'=============================================================================================================
'=============================================================================================================



Sub r2m (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


Sub colour1
    c(0) = _RGB(0, 0, 0)
    c(1) = _RGB(255, 255, 255)
    c(2) = _RGB(85, 45, 0)
    c(3) = _RGB(0, 45, 85)
    c(4) = _RGB(40, 60, 0)
    c(5) = _RGB(0, 25, 75)
    c(6) = _RGB(75, 25, 0)
    c(7) = _RGB(150, 130, 0)
    c(8) = _RGB(150, 150, 250)
    c(9) = _RGB(250, 150, 150)
    c(10) = _RGB(150, 250, 150)
    c(11) = _RGB(150, 150, 255)
    c(12) = _RGB(40, 30, 0)
    c(13) = _RGB(255, 0, 0)
    c(14) = _RGB(50, 150, 50)
    c(15) = _RGB(155, 155, 155)
    c(16) = _RGB(165, 165, 165)
    c(17) = _RGB(175, 175, 175)
    c(18) = _RGB(100, 100, 100)
    c(20) = _RGB(40, 40, 10)


End Sub


Sub makefloor
    Cls
    Line (0, 0)-(500, 500), c(18), BF 'floor background

    For t = 1 To 6000
        x1 = Int(Rnd * 500): y1 = Int(Rnd * 500): PSet (x1, y1), c(0)
        x1 = Int(Rnd * 500): y1 = Int(Rnd * 500): PSet (x1, y1), c(2)
        x1 = Int(Rnd * 500): y1 = Int(Rnd * 500): PSet (x1, y1), c(3)
    Next t

    _Display

    _PutImage (0, 0)-(500, 500), 0, floor1, (0, 0)-(500, 500)

    'Sleep

End Sub



Sub makewall
    Cls
    Line (0, 0)-(500, 100), c(15), BF 'wall background


    For t = 1 To 6000
        x1 = Int(Rnd * 500): y1 = Int(Rnd * 100): PSet (x1, y1), c(16)
        x1 = Int(Rnd * 500): y1 = Int(Rnd * 100): PSet (x1, y1), c(17)
    Next t


    _Display

    _PutImage (0, 0)-(500, 100), 0, wall1, (0, 0)-(500, 100)
    _ClearColor c(0), wall1
    'Sleep

End Sub


Sub makewall2
    Cls
    Line (0, 0)-(500, 100), c(15), BF 'wall2 background

    For t = 1 To 6000
        x1 = Int(Rnd * 500): y1 = Int(Rnd * 100): PSet (x1, y1), c(16)
        x1 = Int(Rnd * 500): y1 = Int(Rnd * 100): PSet (x1, y1), c(17)
    Next t

    Line (70, 25)-(150, 75), c(0), BF
    Line (210, 25)-(290, 75), c(0), BF
    Line (350, 25)-(430, 75), c(0), BF


    _Display

    _PutImage (0, 0)-(500, 100), 0, wall2, (0, 0)-(500, 100)
    _ClearColor c(0), wall2
    'Sleep

End Sub




Sub makeceiling
    Cls
    Line (0, 0)-(500, 500), c(18), BF 'ceiling background
    Line (2, 2)-(498, 498), c(17), BF 'ceiling light background

    For t = 26 To 540 Step 32
        Line (t - 1, 0)-(t, 500), c(18), BF
        Line (0, t - 1)-(500, t), c(18), BF
    Next t


    _Display

    _PutImage (0, 0)-(500, 500), 0, ceiling1, (0, 0)-(500, 500)
    _ClearColor c(0), ceiling1
    'Sleep

End Sub



Sub makeground
    Cls
    Line (0, 0)-(500, 500), c(20), BF 'ground background

    For t = 1 To 6000
        x1 = Int(Rnd * 500): y1 = Int(Rnd * 500): PSet (x1, y1), c(0)
        x1 = Int(Rnd * 500): y1 = Int(Rnd * 500): PSet (x1, y1), c(2)
        x1 = Int(Rnd * 500): y1 = Int(Rnd * 500): PSet (x1, y1), c(3)
    Next t

    _Display

    _PutImage (0, 0)-(500, 500), 0, ground1, (0, 0)-(500, 500)

    'Sleep

End Sub




Sub maptexture (image1, x, y, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
    _MapTriangle (0, 0)-(x, 0)-(0, y), image1 To(x1, y1, z1)-(x2, y2, z2)-(x3, y3, z3), , _Smooth
    _MapTriangle (x, y)-(x, 0)-(0, y), image1 To(x4, y4, z4)-(x2, y2, z2)-(x3, y3, z3), , _Smooth
End Sub
Reply
#10
(12-19-2022, 01:12 AM)bplus Wrote: I may get into 3D yet ;-))  MasterGy may be genius but I want to vomit when I move mouse in his programs (sorry about my bodily reactions MasterGy).

Have you ever played MMORPG? If not, keep it that way or you would ruin your stomach and intestines.

The way the mouse is handled in MasterGY's programs is considered normal in MMORPG where the player is also expected to use a wide range of keys from the keyboard, at least the "function" keys before they had to do double-duty on laptops. :/
Reply




Users browsing this thread: 9 Guest(s)