QB64 Phoenix Edition
3D-ized 2D, a sort of challenge or a how to question... - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11)
+--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2)
+--- Thread: 3D-ized 2D, a sort of challenge or a how to question... (/showthread.php?tid=2556)

Pages: 1 2


RE: 3D-ized 2D, a sort of challenge or a how to question... - madscijr - 03-31-2024

(03-30-2024, 11:16 PM)Petr Wrote: To the question above - motion of the stars - here is the solution in the form of a hardware image - it shows how to get the motion into the hardware image.
I was able to modify your code to scroll the background vertically in pseudo 3d, and overlay the foreground over it. 
The only problem is everything displays too low on the screen - how would you make it top aligned? 

Code: (Select All)
Dim Image As Long
Dim ifg&
Dim ibg&
Dim xs As Long
Dim ys As Long
Dim h1 As Long
Dim w1 As Long

Image = _LoadImage("bg2.png", 32)
ibg& = _CopyImage(Image, 33)

'Image = _LoadImage("si3.png", 32)
'ifg& = _CopyImage(Image, 33)
ifg& = _LoadImage("si3.png", 32)

'Screen _NewImage(1000, 1000, 32)

'h1 = 479
'w1 = 639
h1 = 999
w1 = 999

_Dest Image
'Cls
'For s = 1 To 100
'    PSet (Rnd * 640, Rnd * 480)
'Next

'Virtual = _NewImage(640, 480, 32)
Virtual = _NewImage(1000, 2000, 32)

'Screen _NewImage(640, 480, 32)
Screen _NewImage(1000, 1000, 32)

Do Until _KeyHit = 27
    ys = ys + 1
    If ys > h1 Then ys = 0
    '_PUTIMAGE [STEP] [(dx1, dy1)-[STEP][(dx2, dy2)]][, sourceHandle&][, destHandle&][, ][STEP][(sx1, sy1)[-STEP][(sx2, sy2)]][, _SMOOTH]
    _PutImage (0, ys), Image, Virtual, (0, 0)-(w1, h1)
    _PutImage (0, -h1 + ys), Image, Virtual, (0, 0)-(w1, h1)
    _PutImage (0, 0), ifg&, Virtual, (0, 0)-(w1, h1)

    'newhandle& = _COPYIMAGE(imageHandle&[, mode%])
    'Mode 33 images are hardware accelerated in version 1.000 and up, and are created using _LOADIMAGE or _COPYIMAGE.
    ibg& = _CopyImage(Virtual, 33)

    _MapTriangle (0, 0)-(0, h1)-(w1, h1), ibg& To(-2, 2, -3)-(-2, -2, -1)-(2, -2, -1), 0
    _MapTriangle (0, 0)-(w1, h1)-(w1, 0), ibg& To(-2, 2, -3)-(2, -2, -1)-(2, 2, -3), 0
   
    _Display
   
    '_FreeImage ifg&
    _FreeImage ibg&
   
    _Limit 20
Loop
Thanks for your help BTW!


RE: 3D-ized 2D, a sort of challenge or a how to question... - TerryRitchie - 04-01-2024

Here's a little proof of concept. You'll need the si3.png image I included below. I had to resize it to 960x960 and convert to 32bit color.

Play around with the x,y coordinates in the secondary x,y,z coordinates of _MAPTRIANGLE to fit the image.

Code: (Select All)
DIM si3 AS LONG '        space invaders image
DIM bg2 AS LONG '        background image
DIM by AS INTEGER '      background y
DIM GameScreen AS LONG ' software screen to update
DIM HWScreen AS LONG '   hardware screen to display

si3 = _LOADIMAGE("si3.png", 32)
bg2 = _LOADIMAGE("bg2.png", 32)
GameScreen = _NEWIMAGE(960, 960, 32)
HWScreen = _COPYIMAGE(GameScreen, 33)

SCREEN _NEWIMAGE(960, 960, 32)
DO
    _LIMIT 60
    _DEST GameScreen
    CLS
    _PUTIMAGE (0, by), bg2
    _PUTIMAGE (0, 0), si3
    _DEST 0
    _FREEIMAGE HWScreen
    HWScreen = _COPYIMAGE(GameScreen, 33)
    _MAPTRIANGLE (0, 0)-(0, 959)-(959, 959), HWScreen TO(-1, 1, -3)-(-1, -1, -1)-(1, -1, -1), 0
    _MAPTRIANGLE (0, 0)-(959, 959)-(959, 0), HWScreen TO(-1, 1, -3)-(1, -1, -1)-(1, 1, -3), 0
    _DISPLAY
    by = by - 1
    IF by = -1040 THEN by = 0
LOOP UNTIL _KEYHIT = 27
SYSTEM



RE: 3D-ized 2D, a sort of challenge or a how to question... - madscijr - 04-01-2024

(04-01-2024, 03:57 PM)TerryRitchie Wrote: Here's a little proof of concept. You'll need the si3.png image I included below. I had to resize it to 960x960 and convert to 32bit color.
Play around with the x,y coordinates in the secondary x,y,z coordinates of _MAPTRIANGLE to fit the image.
Thanks... I tried playing around with the x,y coordinates in the secondary x,y,z of _MAPTRIANGLE but it seems that whatever I try, it just mangles the screen. 
I'm at my wits end with that part of things... 

Here's the latest code along with the latest images (tweaked the background image so it wraps around smoothly, and changed scrolling direction to down). 

Code: (Select All)
' 3D-ized 2D
' https://qb64phoenix.com/forum/showthread.php?tid=2556

Dim fg As Long '         foreground image (sprites, text)
Dim bg As Long '         background image (for scrolling)
Dim by As Integer '      background y
Dim GameScreen As Long ' software screen to update
Dim HWScreen As Long '   hardware screen to display

_ScreenMove 0, 0
'_SCREENMOVE _MIDDLE

fg = _LoadImage("fg6.png", 32)
bg = _LoadImage("bg6.png", 32)
GameScreen = _NewImage(960, 960, 32)

'newhandle& = _COPYIMAGE(imageHandle&[, mode%])
'Mode 33 images are hardware accelerated in version 1.000 and up, and are created using _LOADIMAGE or _COPYIMAGE.
HWScreen = _CopyImage(GameScreen, 33)

Screen _NewImage(960, 960, 32)

by = -2000
Do
    _Limit 60
    _Dest GameScreen
    Cls

    '_PUTIMAGE [STEP] [(dx1, dy1)-[STEP][(dx2, dy2)]][, sourceHandle&][, destHandle&][, ][STEP][(sx1, sy1)[-STEP][(sx2, sy2)]][, _SMOOTH]
    _PutImage (0, by), bg
    _PutImage (0, 0), fg

    _Dest 0
    _FreeImage HWScreen
    HWScreen = _CopyImage(GameScreen, 33)

    '2D drawing
    '_MAPTRIANGLE [{_SEAMLESS}] (sx1, sy1)-(sx2, sy2)-(sx3, sy3), source& TO (dx1, dy1)-(dx2, dy2)-(dx3, dy3)[, destination&][{_SMOOTH|_SMOOTHSHRUNK|_SMOOTHSTRETCHED}]]

    '3D drawing (hardware images only)
    '_MAPTRIANGLE [{_CLOCKWISE|_ANTICLOCKWISE}] [{_SEAMLESS}] (sx1, sy1)-(sx2, sy2)-(sx3, sy3), source& TO (dx1, dy1, dz1)-(dx2, dy2, dz2)-(dx3, dy3, dz3)[, destination&][{_SMOOTH|_SMOOTHSHRUNK|_SMOOTHSTRETCHED}]]

    '_MapTriangle (0, 0)-(0, 959)-(959, 959), HWScreen To(-1, 1, -3)-(-1, -1, -1)-(1, -1, -1), 0
    '_MapTriangle (0, 0)-(959, 959)-(959, 0), HWScreen To(-1, 1, -3)-(1, -1, -1)-(1, 1, -3), 0

    '>>The only problem is everything displays too low on the screen - how would you make it top aligned?
    '>Play around with the x,y coordinates in the secondary x,y,z coordinates of _MAPTRIANGLE to fit the image.
    'Not working, any ideas?:
    _MapTriangle (0, 0)-(0, 959)-(959, 959), HWScreen To(-1, 1, -3)-(-1, -1, -1)-(1, -1, -1), 0
    _MapTriangle (0, 0)-(959, 959)-(959, 0), HWScreen To(-1, 1, -3)-(1, -1, -1)-(1, 1, -3), 0

    _Display

    by = by + 1: If by = 0 Then by = -2000 ' SCROLL FORWARDS

Loop Until _KeyHit = 27
System