Author Topic: Pi-in-the-Sky Graphics Demonstration Program (with 3D)  (Read 8234 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« on: December 10, 2019, 09:44:13 am »
This is a program which demonstrates the amazing graphics capabilities of QB64, using simple coding techniques and without resorting to the complexities of Open_GL.  Impressive 3D effects can be obtained using the QB64 _MAPTRIANGLE statement: the 3D _MAPTRIANGLE method gives a convincing 3D display along with perspective.

The program features a number of animations (some 2D and some 3D) enhanced with accompanying audio.  In order to run this program you will need to download the zip file from the URL.  Extract the folder "pi in the sky" and place that folder in your QB64 folder – be careful not to create and extra folder layer.  Load the "pi in the sky" bas file and run (QB64v2 or higher).  You will need to have the Run Option "Output EXE to Source Folder" checked.  The program uses quite a bit of processor power (up to nearly 2 CPU's-worth at times on my Core i5 machine) and a lot of memory, so you'll need a modern machine.  At program start there is a delay while the disk files are read and loaded into memory (and there are image manipulations being carried out).

The display shows a landscape within which a variety of animations will occur.  It takes approximately 10 mins to run through all of the animation sequences.  There are earthly animations and celestial animations.  During the celestial animations, there are ghostly appearances in the terrestrial graveyard and related sounds.

In the blue text I give details of the program coding methods, descriptions of the animations and background information.  You do not need to read the blue text to run and enjoy (well, maybe!) the program.

Download:
https://www.dropbox.com/s/goekmtjtmt0n7m1/pi%20in%20the%20sky.zip?dl=1

I started this project purely because the phrase "pi in the sky" popped into my head, and so started coding to produce a pi symbol randomly rotating about three axes in 3D.  The obvious QB64 method is _MAPTRIANGLE(3D).  All you have to do is plug in the mathematics of rotations of a rectangle about the three Cartesian co-ordinates and place the resulting corner positions into _MAPTRIANGLE(3D).  The surface of the image is everywhere flat, but its corners move freely in the 3D space of _MAPTRIANGLE(3D), and as (vanishing point) perspective is coded into the _MAPTRIANGLE(3D) method, a very good-looking 3D display is produced.  I must emphasise that this QB64 method is so well produced that it can be used by novice and low-skill coders.  In the Skill Range Venn Diagram, I sit in the low-skill sector, and I cannot do the real-3D (SUB _GL) stuff of our competent members.

To do this project I have had to go back to school-level calculus, geometry & algebra; oh, happy days!  Having got the pi animation working, I then set about adding other features to demonstrate what can done with QB64 graphics.  The final project uses both software and hardware imaging, and for the hardware images both _MAPTRIANGLE(2D) and _MAPTRIANGLE(3D).  The program is designed to show how such images will interact.  The program also uses a load of _MEM object processing in order to manipulate images, both at initiation and on-the-fly in real time.

Background Image
The graphical animations take place in front of a background image.  This background (a landscape with added features) is software (,32 type image) and has a single _PUTIMAGE directly after creating the 32-bit screen.  This image stays displayed despite the running loop executing a _DISPLAY at each cycle (30 fps).  All other images are hardware (,33 type) and are placed in front of the background (naturally!).

pi Animation
In order to change colour as the pi moves around, real-time editing of the image file is required.  This is achieved by _MEM object manipulation at each display cycle.  _MEM processing can only be achieved with software images, whereas the pi image is hardware.  So, firstly a software image is created at initiation and a _MEM object of the software image is taken.  Then at each cycle that object is manipulated and the software image is copied to hardware and that image is displayed.  The hardware image is freed each cycle at the earliest opportunity.  This method is repeated for all other real-time image manipulations.

Earthly and Celestial Animations
There are both earth-bound and celestial animations.  The earth-bound animations (along with clouds and some rain) are continuous, whereas the celestial animations cycle in a random manner.

Earthly Animations

Beehive
Bees emerge and swarm from a suspended beehive in the foreground.  The bees fly in the 3D space of _MAPTRIANGLE(3D) and both the hive and the bee images (QB64 bee logo) are hardware (3D: ,33 image type).  After emerging in an outward direction the bees turn and fly in the opposite direction away from the viewer "into" the screen.  Bees in front of the hive occlude it, and behind the hive they are occluded by it.  As the hive image is a flat object, a bee moving from directly in front of to directly behind the hive travels right through it.  The bees all appear to move to the right as they move away, but this is just the perspective.  All the bees return to the hive after their flight out.  In order to achieve such paths, the bees are flying in parabolic curves in the 3D space.  There is the sound of humming bees, the more bees that are out the louder they sound.

Fountain
A fountain squirts droplets of water into the pond.  There are 500 droplets of water each moving under gravity in the _MAPTRIANGLE(3D) space.  Although as many droplets are sent behind the fountain as in the front, it looks as if they only fall at the front.  This is just an artefact of the perspective.

Windmill
The moving windmill sails clearly show the 3D and perspective effects  of _MAPTRIANGLE(3D).  The sails appear to move in and out as they rotate and are smaller the further away they are.  As the bees, fountain droplets and windmill sails are _MAPTRIANGLE(3D) images, they occlude each other dependent upon which is further away.  The windmill itself is not a 3D object but part of the software background.  The industrious Miller Heitor looks out from the windmill.

Clouds and Rain
Clouds pass above.  They are slightly transparent so that objects behind can still be seen.  One of the clouds is rain-bearing and a shower of 500 raindrops passes along.  The clouds and raindrops are not 3D, and occlusions occur based upon order in which the _PUTIMAGE functions occur.

Flower Growth
As the rain passes, flowers can spring up in the earth.  Flower images are 2D.

Rainbow
When the rain is in just the right place, a rainbow appears.  The rainbow is a _MAPTRIANGLE(3D) image and occlusions with other such objects are dependent upon distance into the screen.

Graveyard
Ghostly images appear in the graveyard when certain celestial events take place.  The gravestones themselves are part of the background 2D image.

Celestial Animations
At times, celestial animations occur.  When a celestial animation takes place, there are accompanying ghostly images in the graveyard.  There is accompanying related audio.

Concorde
Fly-past of a supersonic passenger aircraft.  The Concorde image is 2D.  The aircraft creates a sonic boom.  A ghostly image of Douglas Bader appears in the graveyard.  Eventually the graveyard image gradually disappears into thin air.  This graphic effect is achieved, again, by _MEM object real-time processing (in this case changing alpha sequentially).  Images here are 2D.

ET
A silhouette from a well-known science fiction film travels across the sky.  The image is 2D.  A ghostly film director appears in the graveyard.

Star Trek
The spacecraft from a well-known science-fiction television series moves through the _MAPTRIANGLE(3D) space coming from the far distance.  Members of the crew appear in the graveyard.  Because the graveyard images are small and transparent, it is rather difficult to recognise who they are.  From left to right they are McCoy, Uhura, Kirk, Sulu and Spock.

ISS
The 2D International Space Station passes overhead.  The sound is that of Sputnik 1.  Cosmonaut Yuri Gagarin appears in the graveyard.

Meteors
A 3D meteor shower occurs while Galileo looks on from the grave.

Transit
A transit of Venus occurs.  This is a very rare event, the last occurring in 2012 and the next due in 2117, so we are very privileged.  The goddess appears in the graveyard.  She is The Bringer of Peace and has her appropriate accompanying music.

Thunderbirds
A bomb falls onto the windmill.  Call for action from a well-known science-fiction television series.  Help arrives and the bomb is safely removed.  All images are 2D.  The graveyard crew are Alan, Scott, Virgil, Gordon and John.

Zodiac
The signs of the Zodiac circle in the heavens.  The image is the surface of an open-ended cylinder.  This is the only non-flat 3D image in this program, and the real-3D effect requires multiple _MAPTRIANGLE(3D) processes.  The Zodiac sign at the front is brightened, and this effect is, again, produced by real-time _MEM processing.  Zodiac symbols of the prominent sign appear in the graveyard.  The music is appropriately mystical.
For you I see a romantic liaison with a coach party of ageing workers from the shoe-making industry.  Astrology – what a load of old cobblers!

UFO
An alien spacecraft arrives and settles for a moment, and after probing the environment it lifts off and flies away.  The image is _MAPTRIANGLE(3D) and occlusions with the windmill sails are correct.  In order to make the landing, the spacecraft follows a helical path (circular x-, z- path and linear y- path).  The arrival of this alien craft arouses the interest of two FBI special agents.  As the craft probes the ground, the little green man appears in the graveyard.

Spotlight
A spotlight illuminates the sky and reveals a pertinent message.  The spotlight image is only 2D, and would have been better as 3D but is done this way to show the limitations.  Again, _MEM processing is required to make the message image respond to the spotlight.  The graveyard shows how this program was produced.


Discussion
This has been a tinkering project.  As ideas came, I'd change to new areas of coding and then return to unfinished parts.  This is a bad method to do projects.  Returning to old parts, you don't quite remember exactly what you previously did and end up making mistakes and taking a great deal of time.  The project could still benefit from further improvements/changes and the tinkering could go on for ever (certainly some of the animations are rather naff, if not great fun for the coder).  But I leave it as is so  as to demonstrate where 2D imaging is not good enough to show completely correct perspective/occlusion.


 
screenshot.jpg



« Last Edit: January 14, 2022, 03:12:04 pm by Qwerkey »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #1 on: December 10, 2019, 11:33:19 am »
Amazing is the right word. It's been a long hard pull for me to get my head around graphics programming, but QB64 has fielded everything I've tried so far.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #2 on: December 10, 2019, 12:39:28 pm »
Wow Qwerkey, that's some graphics show! A ten on the whimsical scale!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #3 on: December 10, 2019, 01:26:15 pm »
Incredible job Qwerkey! Fun to watch and listen too. Someone could make some incredible games with this kind of stuff.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #4 on: December 12, 2019, 07:22:19 am »
One slight flaw in a brilliant display was... The Starship Enterprise appears and so does a collection of Federation officers... The glitch is: The Enterprise is a Constellation Class Starship from the 'original' TV series and the uniforms, of the officers, were worn on the Galaxy Class Starship, featured on Next Generation....
Logic is the beginning of wisdom.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #5 on: December 12, 2019, 07:38:53 am »
Thanks guys, for your positive appraisals.  You may imagine that this project was a huge amount of fun.  Oh, Johnno, very much amused!  The one feature of this project is its complete departure from reality.  Actually, you'll be surprised that I have never seen Star Trek, but was aware of the existence on British TV of the first series.  In collecting images for the program I had to do a lot of googling, of course, and was completely unaware of what was what.  I'm glad, at least, that the crew (incorrectly dressed!) belonged on the right craft.
« Last Edit: December 14, 2019, 06:27:29 am by Qwerkey »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #6 on: December 14, 2019, 05:50:58 am »
Oh, I'm not too surprised. After all, not everyone can be a Star Trek nerd, like myself... lol  But, seriously, a REALLY good effort on your part... Well done!
Logic is the beginning of wisdom.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #7 on: December 14, 2019, 11:03:05 pm »
Beautiful and very detailed. I like it very much.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #8 on: April 06, 2020, 01:42:53 pm »
As Qwerkey just pointed out to me today, Pi-in-the-sky is not loading all the images for QB64 v 1.4 so here is my copy compiled in v1.3 for Windows:

You will still need all the assets from his download link.

BTW @Qwerkey how did you get Pi Image and Flying Saucer Image in different colors?
* pi in the sky for QB64 v1.3.zip (Filesize: 0.99 MB, Downloads: 165)
« Last Edit: April 06, 2020, 02:01:00 pm by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #9 on: April 06, 2020, 03:32:25 pm »
The program bee hives as advertised.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #10 on: April 10, 2020, 10:51:42 am »
@Qwerkey,

Have you made any progress determining why some .png's are showing and some are not with v1.4 while all worked fine with 1.3?

Checking image loads are easy enough:
Code: QB64: [Select]
  1. ' created for Johnno Battleship 5-AI b+ 2020-03-09
  2.  
  3. 'this function shuts down a program if an image file isn't loaded
  4. FUNCTION checkImageLoad& (file$)
  5.     IF _FILEEXISTS(file$) THEN
  6.         hdl& = _LOADIMAGE(file$)
  7.         IF hdl& = -1 THEN CLS: PRINT file$ + " can't be loaded.": SLEEP: END ELSE checkImageLoad& = hdl&
  8.     ELSE
  9.         CLS: PRINT file$ + " does nor exist.": SLEEP: END
  10.     END IF
  11.  
  12.  
  13.  

But my guess is you are handling the png for hive with branch and windmill building different than the other pngs. Odd, because these you seem to be manipulating the least they are or could be just part of background setting.

If there is something different between 1.3 and 1.4 it would be important to tease out the exact cause of problem.
« Last Edit: April 10, 2020, 11:22:03 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #11 on: April 10, 2020, 11:54:54 am »
Hey is that Fellippe looking out the Windmill?

FellippeHeitor

  • Guest
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #12 on: April 10, 2020, 12:18:22 pm »
LOL It's me...

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #13 on: April 10, 2020, 01:00:41 pm »
@bplus Regret that I've not looked into this yet, working on stuff elsewhere.  It's on my ToDo list (with no urgency).  As Fellippe confirms, it is he - you did point out that this project has a high level of whimsy!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Pi-in-the-Sky Graphics Demonstration Program (with 3D)
« Reply #14 on: April 10, 2020, 01:27:26 pm »
Well so far all I've learned is that my little checkImageLoad& function will throw an error if a graphics screen hasn't been called upon yet.

And commenting CHECKING:OFF didn't reveal any errors not being reported.