Back in the days of [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] (ah, this seems an eternity ago!) I wrote a program which displayed balls in stereoscopic 3D. In the stereo imaging used, the viewer could actually "see" near objects coming right out of the screen and far object set back from the screen. The method used was to alternate red and blue images offset in x- by a stereo angle amount. The program was able to give the stereoscopic behaviour when using Red/Blue 3D glasses.
The method of alternating red and blue images made the viewed image jittery. I tried to synchronise the alternation with screen refresh rate, but nothing I tried would allow the removal of the jitteriness. The project was abandoned incomplete.
What I really wanted to do was to display both the red and the blue images together without the second image overwriting the first. A method to do this is _MEM processing (thanks again to Steve McNeill for his tutorials) where you can simultaneously alter the _RED, _GREEN, _BLUE and _ALHPA parameters of each image picture element.
The program here implements the _MEM method accordingly. There are 10 images of a disc, each of which moves in the x-, y- and z- directions. The displacement of the red and blue (green is not used) images is linearly dependent upon the z- position, and this gives the stereoscopic behaviour. _MAPTRIANGLE(3D) is used to map each image and this handles all the perspective effects (I say, once again, what a marvellous, marvellous QB64 function this is).
If you run this program with Red/Blue 3D glasses (Blue over the right eye), you will see all the normal behaviour of _MAPTRIANGLE(3D), but in addition the discs will appear to move in and out of the screen. Without the glasses you will see red and blue images overlapping (and giving magenta) with red/blue poking out sideways dependent upon z- position.
I realise that this program will have very limited interest: the number of QB64 members is not large, members who have red/blue glasses and who have an interest in such graphics will be a very select group. For this reason I leave the program as a curiosity here in this state (there could be improvements which I will not attempt). The 10 images are formed as separate software objects which are then individually _MEM processed, those images are copied to hardware and then those images displayed and then image-freed. There will be a method to directly address the screen pixels, but this is a skill level beyond my limited ability. It works anyway!
'3D Stereo Discs Graphics Program v1 by Qwerkey 10/02/20
'
CONST False
= 0, True
= NOT False
, XScreen%
= 1100, YScreen%
= 800, PiConst!
= 4 * ATN(1), ZOffset%
= -620 CONST Xst%%
= 5, Stereo!
= (5 * 2) / YScreen%
, Rad%%
= 50, Zf!
= 1 'All perspective behaviour handled by _maptriangle(3D), stereo effect x-separation linear with z-
'Software Images (for _MEM processing). Hardware images for display
Balls!
(K%%
, 0) = RND * XScreen%
/ 2 Balls!
(K%%
, 1) = RND * YScreen%
/ 2 Balls!
(K%%
, 2) = RND * YScreen%
/ 2 Balls!
(K%%
, 3) = 2 * PiConst!
* (RND - 0.5) Balls!
(K%%
, 4) = 2 * PiConst!
* (RND - 0.5) Balls!
(K%%
, 5) = 2 * PiConst!
* (RND - 0.5) Balls!
(K%%
, 6) = 0.007 + RND * 0.02 IF RND > 0.5 THEN Balls!
(K%%
, 6) = -Balls!
(K%%
, 6) Balls!
(K%%
, 7) = 0.007 + RND * 0.02 IF RND > 0.5 THEN Balls!
(K%%
, 7) = -Balls!
(K%%
, 7) Balls!
(K%%
, 8) = 0.007 + RND * 0.02 IF RND > 0.5 THEN Balls!
(K%%
, 8) = -Balls!
(K%%
, 8) Balls!
(K%%
, 9) = Stereo!
* Balls!
(K%%
, 2) * SIN(Balls!
(K%%
, 5)) SoftImg&
(K%%
) = _NEWIMAGE(2 * (Rad%%
+ Xst%%
) + 1, 2 * Rad%%
+ 1, 32) FOR N%
= 0 TO 2 * (Rad%%
+ Xst%%
) COff = 4 * (N% + M% * 2 * (Rad%% + Xst%%) + 1) + CMem(K%%).OFFSET
'Screen (Hardware Only)
'Checking off in fully working
Balls!(K%%, 3) = PiBand!(Balls!(K%%, 3) + Balls!(K%%, 6))
Balls!(K%%, 4) = PiBand!(Balls!(K%%, 4) + Balls!(K%%, 7))
Balls!(K%%, 5) = PiBand!(Balls!(K%%, 5) + Balls!(K%%, 8))
Balls!
(K%%
, 9) = Stereo!
* Balls!
(K%%
, 2) * SIN(Balls!
(K%%
, 5)) FOR N%
= 0 TO 2 * (Rad%%
+ Xst%%
) COff = 4 * (N% + M% * (2 * (Rad%% + Xst%%) + 1)) + CMem(K%%).OFFSET
Q0% = N% - (Rad%% + Xst%% + Balls!(K%%, 9))
Q1% = M% - Rad%%
Q0% = N% - (Rad%% + Xst%% - Balls!(K%%, 9))
Zpos!
= Balls!
(K%%
, 2) * SIN(Balls!
(K%%
, 5)) * Zf!
+ ZOffset%
X1!
= Balls!
(K%%
, 0) * SIN(Balls!
(K%%
, 3)) + Rad%%
+ Xst%%
X0!
= Balls!
(K%%
, 0) * SIN(Balls!
(K%%
, 3)) - (Rad%%
+ Xst%%
) Y1!
= Balls!
(K%%
, 1) * SIN(Balls!
(K%%
, 4)) - Rad%%
Y0!
= Balls!
(K%%
, 1) * SIN(Balls!
(K%%
, 4)) + Rad%%
_MAPTRIANGLE (0, 0)-(2 * (Rad%%
+ Xst%%
), 0)-(0, 2 * Rad%%
), HardImg&
(K%%
) TO(X0!
, Y0!
, Zpos!
)-(X1!
, Y0!
, Zpos!
)-(X0!
, Y1!
, Zpos!
) _MAPTRIANGLE (2 * (Rad%%
+ Xst%%
), 2 * Rad%%
)-(0, 2 * Rad%%
)-(2 * (Rad%%
+ Xst%%
), 0), HardImg&
(K%%
) TO(X1!
, Y1!
, Zpos!
)-(X0!
, Y1!
, Zpos!
)-(X1!
, Y0!
, Zpos!
)
PiBand!
= PiAngle!
+ _PI(2) PiBand!
= PiAngle!
- _PI(2) PiBand! = PiAngle!