Author Topic: _MAPTRIANGLE 3D -question  (Read 4215 times)

0 Members and 1 Guest are viewing this topic.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
_MAPTRIANGLE 3D -question
« on: December 03, 2020, 10:44:09 am »
Hi !
I would need to draw a picture with 3D _MAPTRIANGLE. Not on the screen, but on an image created with _NEWIMAGE, but not on the screen!
Unfortunately, it already fails there that if SCREEN is not equal to _maptriangle “destination” it will not draw.
How do I draw so that it does not appear on the screen but only on a background image?
Do you know any tricks to this?

It would also be a good solution to be able to open multiple windows on the screen.

Thanks !
« Last Edit: December 03, 2020, 10:46:35 am by MasterGy »

Marked as best answer by MasterGy on December 03, 2020, 07:20:31 pm

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #1 on: December 03, 2020, 03:03:43 pm »
Hi. In 3D you MUST copying HARDWARE images to HARDWARE images:

Code: QB64: [Select]
  1. virtual = _NEWIMAGE(800, 600, 32)
  2. HARDWARE_virtual = _COPYIMAGE(virtual, 33)
  3. _FREEIMAGE virtual 'software image is not need now
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. 'save something to unvisible image using 3D MAPTRIANGLE:
  7.  
  8. HARDWAREimg = _COPYIMAGE(img, 33)
  9.  
  10. _MAPTRIANGLE (0, 0)-(_DESKTOPWIDTH, 0)-(0, _DESKTOPHEIGHT), HARDWAREimg TO(-1, 1, -3)-(1, 1, -3)-(-1, -1, -3), HARDWARE_virtual, _SMOOTH 'copy triangle to virtual screen
  11.  
  12. PRINT "This is software screen. Press key..."
  13.  
  14. 'place it to your screen: (PUTIMAGE know do it with hardware images)
  15.     _PUTIMAGE (0, 0), HARDWARE_virtual
  16.     _DISPLAY
  17.  

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #2 on: December 04, 2020, 12:20:18 am »
Thank you with a grateful heart! I always thought that if an image is already in "33", so it's hardware, you can't change it anymore. You showed that another 33 can be placed on a 33 image with maptriangle3d! It is very good ! Thank you for showing me !!!

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #3 on: December 04, 2020, 10:50:59 am »
I put in my program, it does its job nicely, but after a while it crashes. If I end the cycle you write, it crashes with me after about half a minute. How could this be applied safely?

Code: QB64: [Select]
  1. virtual = _NEWIMAGE(800, 600, 32)
  2. HARDWARE_virtual = _COPYIMAGE(virtual, 33)
  3. _FREEIMAGE virtual 'software image is not need now
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. 'save something to unvisible image using 3D MAPTRIANGLE:
  7.  
  8.     img = _SCREENIMAGE
  9.     HARDWAREimg = _COPYIMAGE(img, 33)
  10.     _FREEIMAGE img
  11.  
  12.     _MAPTRIANGLE (0, 0)-(_DESKTOPWIDTH, 0)-(0, _DESKTOPHEIGHT), HARDWAREimg TO(-1, 1, -3)-(1, 1, -3)-(-1, -1, -3), HARDWARE_virtual, _SMOOTH 'copy triangle to virtual screen
  13.  
  14.  
  15.     'place it to your screen: (PUTIMAGE know do it with hardware images)
  16.  
  17.     _PUTIMAGE (0, 0), HARDWARE_virtual
  18.     _DISPLAY
  19.  
  20.  
  21.  
  22.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #4 on: December 04, 2020, 04:05:05 pm »
Hi. Try it so:

Code: QB64: [Select]
  1. virtual = _NEWIMAGE(800, 600, 32)
  2. HARDWARE_virtual = _COPYIMAGE(virtual, 33)
  3. _FREEIMAGE virtual 'software image is not need now
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. 'save something to unvisible image using 3D MAPTRIANGLE:
  7.  
  8. HARDWAREimg = _COPYIMAGE(img, 33)
  9. _MAPTRIANGLE (0, 0)-(_DESKTOPWIDTH, 0)-(0, _DESKTOPHEIGHT), HARDWAREimg TO(-1, 1, -3)-(1, 1, -3)-(-1, -1, -3), HARDWARE_virtual, _SMOOTH 'copy triangle to virtual screen
  10.  
  11.     'place it to your screen: (PUTIMAGE know do it with hardware images)
  12.  
  13.     _PUTIMAGE (0, 0), HARDWARE_virtual
  14.     _DISPLAY
  15.  

Why is in neverending loop in your program created SCREENIMAGE, placed to virtual hardware image and then viewed?

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #5 on: December 04, 2020, 04:11:40 pm »
I set the example because I need it. 4 continuously changing images created from 3d maptriangles should be displayed on 1 screen.

"HARDWARE_virtual" always changes in my case.

it’s like making a 3d game, but I want to see the space in real time in 4 different views.
« Last Edit: December 04, 2020, 04:16:04 pm by MasterGy »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #6 on: December 04, 2020, 05:00:37 pm »
I see! So it is also possible to do so. You will take four hardware pictures. You have to keep in mind that they are not overwritted so as software images, so it is optimal to always draw everyone from the beginning to update them. After drawing and displaying, you release it from the memory with the FREEIMAGE command, but before that you copy the result to the next image, which will be displayed during the update of the original one. I read it badly before, so I wrote you a sample with 2D to 3D. But you want 3D to 3D. Good. I'll try it too ... So first I add  2D images to 3D, I'll bounce back from it and rewrite it to 3D to 3D.


2D to 3D
Code: QB64: [Select]
  1. DIM SHARED imageA, imageB, imageC, imageD
  2.  
  3. imageA = _NEWIMAGE(320, 240, 32)
  4. imageB = _NEWIMAGE(320, 240, 32)
  5. imageC = _NEWIMAGE(320, 240, 32)
  6. imageD = _NEWIMAGE(320, 240, 32)
  7. _DEST imageB
  8. CLS , &HFFFFFF00
  9. _DEST imageC
  10. CLS , &HFF111111
  11. _DEST imageD
  12. CLS , &HFFAAAAAA
  13.  
  14.  
  15.  
  16. my = _NEWIMAGE(1024, 768, 32)
  17.     DrawA
  18.     DrawB
  19.     drawC
  20.     drawD
  21.     _DEST my
  22.  
  23.     place3D -5, -2, -7, -3, -2, -9, -5, 0, -7, -3, 0, -9, imageA
  24.     place3D 1, -2, -7, 3, -2, -4, 1, 0, -7, 3, 0, -4, imageB
  25.     place3D 1, 1, -7, 3, 1, -4, 1, 3, -7, 3, 3, -4, imageC
  26.     place3D -5, 3, -7, -3, 3, -9, -5, 1, -7, -3, 1, -9, imageD
  27.  
  28.     _DISPLAY
  29.     _LIMIT 30
  30.  
  31.  
  32. SUB place3D (x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, source)
  33.     i = _COPYIMAGE(source, 33)
  34.     _MAPTRIANGLE (0, 0)-(319, 0)-(0, 239), i TO(x1, y1, z1)-(x2, y2, z2)-(x3, y3, z3), 0
  35.     _MAPTRIANGLE (319, 0)-(0, 239)-(319, 239), i TO(x2, y2, z2)-(x3, y3, z3)-(x4, y4, z4), 0
  36.     _FREEIMAGE i
  37.  
  38. SUB DrawA
  39.     _DEST imageA
  40.     x = 320 * RND
  41.     y = 240 * RND
  42.     r = 50 * RND
  43.     c = RND * 255
  44.     CIRCLE (x, y), r, _RGB32(c)
  45.  
  46. SUB DrawB
  47.     STATIC xl, yl
  48.     _DEST imageB
  49.     xl = 320 * RND
  50.     yl = 240 * RND
  51.     r = 50 * RND
  52.     c = RND * 255
  53.     LINE -(xl, yl), _RGB32(c)
  54.  
  55. SUB drawC
  56.     _DEST imageC
  57.     x = 320 * RND
  58.     y = 240 * RND
  59.     r = 50 * RND
  60.     c = RND * 255
  61.     PSET (x, y), _RGB32(c)
  62.  
  63.  
  64. SUB drawD
  65.     _DEST imageD
  66.     LOCATE 1
  67.     PRINT TIME$
  68.  

wait, writing 3D to 3D...

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #7 on: December 04, 2020, 06:01:52 pm »
So I converted the 2D images to 3D, then copied them to another hardware image using MAPTRIANGLE and displayed it. It works, there is a problem with the text and it does not update. The graphics are being updated. I'll try something else, but not until later.

Code: QB64: [Select]
  1. DIM SHARED imageA, imageB, imageC, imageD, HFull_Image
  2.  
  3. imageA = _NEWIMAGE(320, 240, 32)
  4. imageB = _NEWIMAGE(320, 240, 32)
  5. imageC = _NEWIMAGE(320, 240, 32)
  6. imageD = _NEWIMAGE(320, 240, 32)
  7. FullImage = _NEWIMAGE(1024, 768, 32)
  8. _DEST FullImage
  9. HFull_Image = _COPYIMAGE(FullImage, 33) '  create new EMPTY hardware image
  10. _FREEIMAGE FullImage
  11.  
  12. _DEST imageB
  13. CLS , &H00FFFF00
  14. _DEST imageC
  15. CLS , &H00111111
  16. _DEST imageD
  17. CLS , &H00AAAAAA
  18.  
  19.  
  20.  
  21. my = _NEWIMAGE(1024, 768, 32)
  22. ON TIMER(10) GOSUB clearIT
  23.  
  24.     drawD
  25.     drawC
  26.     DrawB
  27.     DrawA
  28.  
  29.     place3D -5, -2, -7, -3, -2, -9, -5, 0, -7, -3, 0, -9, imageA
  30.     place3D 1, -2, -7, 3, -2, -4, 1, 0, -7, 3, 0, -4, imageB
  31.     place3D 1, 1, -7, 3, 1, -4, 1, 3, -7, 3, 3, -4, imageC
  32.     place3D -5, 3, -7, -3, 3, -9, -5, 1, -7, -3, 1, -9, imageD
  33.  
  34.     _PUTIMAGE (0, 0), HFull_Image
  35.     _DISPLAY
  36.     _LIMIT 30
  37.  
  38. clearIT:
  39. _FREEIMAGE HFull_Image
  40. _FREEIMAGE imageA
  41. _FREEIMAGE imageB
  42. _FREEIMAGE imageC
  43. _FREEIMAGE imageD
  44. HFull_Image = _COPYIMAGE(FullImage, 33) '  create new EMPTY hardware image
  45. imageA = _NEWIMAGE(320, 240, 32)
  46. imageB = _NEWIMAGE(320, 240, 32)
  47. imageC = _NEWIMAGE(320, 240, 32)
  48. imageD = _NEWIMAGE(320, 240, 32)
  49.  
  50.  
  51. SUB place3D (x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, source)
  52.     i = _COPYIMAGE(source, 33)
  53.     _MAPTRIANGLE (0, 0)-(319, 0)-(0, 239), i TO(x1, y1, z1)-(x2, y2, z2)-(x3, y3, z3), HFull_Image, _SMOOTH 'copy HARDWARE content to new empty HARDWARE image
  54.     _MAPTRIANGLE (319, 0)-(0, 239)-(319, 239), i TO(x2, y2, z2)-(x3, y3, z3)-(x4, y4, z4), HFull_Image, _SMOOTH
  55.     _FREEIMAGE i
  56.  
  57. SUB DrawA
  58.     _DEST imageA
  59.     x = 320 * RND
  60.     y = 240 * RND
  61.     r = 50 * RND
  62.     c = RND * 255
  63.     CIRCLE (x, y), r, _RGB32(c)
  64.  
  65. SUB DrawB
  66.     STATIC xl, yl
  67.     _DEST imageB
  68.     xl = 320 * RND
  69.     yl = 240 * RND
  70.     r = 50 * RND
  71.     c = RND * 255
  72.     LINE -(xl, yl), _RGB32(c)
  73.  
  74. SUB drawC
  75.     _DEST imageC
  76.     LINE (0, 0)-(319, 239), , B
  77.     x = 320 * RND
  78.     y = 240 * RND
  79.     r = 50 * RND
  80.     c = RND * 255
  81.     PSET (x, y), _RGB32(c)
  82.  
  83. SUB drawD
  84.     _DEST imageD
  85.     LOCATE 1
  86.     PRINT TIME$
  87.  

I also found (I didn't realize that) that when I copied a hardware image to a hardware image, the original content in the target would be credited (so the original won't be deleted, but a new one will be drawn over it). Therefore, the target hardware image will always have to be discarded and a new one created, because there is no such thing as CLS for hardware images. And if I'm wrong, I'm asking anyone to correct me.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #8 on: December 05, 2020, 03:39:46 am »
MasterGy, I've been thinking about your request and come up with the following. I don't think you need a copy of the hardware image to create 4 independent 3D views! What you really need are 4 independent drawings that differ in the angle of rotation of the model! This will create 4 3D images, which you will then place. Would that be a solution to your request?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #9 on: December 05, 2020, 04:12:46 am »
I now made a quick adjustment to my program with a cube that has animation on the surface, stretched X axis so that it was not symmetrical, and made two views rotated 90 degrees. It is possible to continue in the same way for the view during the Z / Y rotation, only it is necessary to add the already performed Z / X rotation. I added the program to this thread:

https://www.qb64.org/forum/index.php?topic=3325.msg126224#msg126224

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #10 on: December 05, 2020, 10:05:43 am »
It is very kind of you to spend so much time on the problem.
It would be important to draw in separate windows. I'm experimenting with the maze program.
If you wanted to draw this all at once, it wouldn’t be perfect. Because I don’t want to look at something from the outside, it’s the whole inside view. It’s ugly to cut off the excess points because valuable triangles would be missing as well.
In the meantime, I came up with a solution, I also tried to have 2 open qb programs communicate with each other through a common RANDOM file. The signal transmission is immediate.
So there would be a “BOSS” program that, if launched, would launch 4 “3d viewer” programs, and in the RANDOM file, BOSS would give the viewers only the necessary coordinates in real time.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #11 on: December 05, 2020, 12:38:20 pm »
The point of the experiment, which I really want to see, is that:
Suppose the position of each point in the world is determined not by 3 but by 4 coordinate points. In vain 4, we can only perceive and see the projections of 3 planes.
The program creates a 4d maze. It doesn't matter what we fill the space with, I thought the maze was an ideal terrain. It could have been a building plan, anything.
Since four values ​​define 1 point, but we can only perceive a cross section of 3 values ​​visually, I wondered what it would be like to see the plot in real time from multiple perspectives. Each window is a cross section of a possible projection.
So we have the X, Y, Z, A planes. They record every point. We can see the XYZ projection from one window, but it is possible to jump to “hyperspace” by moving the A value. We see the same from another window, but from the projection of the X, Y, A planes. In this window, moving in the Z plane means a “hyperspace jump”. And so on.
Window 1: natural projection: XYZ, hyper-plane: A

Window 2: natural projection: XYA, hyper-plane: Z

Window 3: natural projection: XZA, hyper-plane: Y

Window 1: natural projection: YZA, hype-rplane: X

The interesting thing is:
Suppose we make a hyper-space jump in one of the windows. It looks like we’re going through a simple hallway in another window. And vice versa….
I want to see my 4 dimensional motion in real time in 4 different projections.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #12 on: December 05, 2020, 01:00:29 pm »
the video shows what I want.

Only the wall collision and the 4 windows thing are missing from the program. I already really want to see in 4 windows as I move from one plane to another.
One-window shows what's going on, but unfortunately qb64 doesn't want this 3D image re-editing.

The video shows me bouncing in the hyperspace of the current window and changing the perspective



Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: _MAPTRIANGLE 3D -question
« Reply #13 on: December 05, 2020, 04:22:20 pm »
MASTER Gy!

I'm trying to imagine what you want, and the only thing I've accomplished here is a big headache. But, definitely, 3D in four windows must be possible to do. The question is how to display 4 dimensions using three coordinates ... Then the images will never agree, because one dimension always missing.