Page 1 of 3

DosBatch 3D Engine.

Posted: 13 May 2014 15:32
by einstein1969
Hi to all!

I have searched for the web with google but I have not found anything... :(

I do not mean wsh/hta or high-level. Neither utility in assembler/c/etc.

Does anyone know the previous works in this context?

Regards
Einstein1969

Re: DosBatch 3D Engine.

Posted: 27 May 2014 13:05
by einstein1969
Hi to all,

I think that is impossible that anyone not have explored this and, if no, I think that should do it.
Then I worked for see if there was any hope of getting something in 3d animated with a decent speed .

I started and the first I chose to draw a 3D sphere which is the base of all animations .
Well the result was that it was very slow and I could not figure it out . The problems that the dos batch in managing the environment and the various levels are really a maze that you never know .

However, I gave up and I tried and tried .

The following code is unfortunately not very readable format by subsequent optimizations that received to achieve the speed that today.

I had to work on keeping the environment free , use a few variables , use short names of variables and also keep the variables that are used at the top ( remember we are ordered alphabetically). This is the tricks for fast execution.

I had to put something in the algorithm of stochastic almost to lower execution times.
And also I had to pre- compute some static information . For the rest everything is calculated in real time.

The result seems to me to give space to new research possibilities in the field and good fun , with a wide margin to use external programs without slowing down too much .

Sphere 3D.cmd:

Code: Select all

@echo off & setlocal & title Sphere 3D & set /a cols=62, lines=62 & goto :Init_system

    :: By einstein1969. Dedicated to jeb, dbenham, penpen, carlos, aGerman, Aacini, EdDyreen,
    :: npocmaka_, Liviu, Sponge Belly, Magialisk, the users and the staff of Dostips forum.

  :: Use raster font 8x8.

:Main

set /a ar=100, rt=0, ds=0, cx=cols/2, cz=4000, cY=lines/2

(
  set SIN=
  set _PLOT$_=
  set _$PLOT_=
  set _empty=
  set lines=
  set cols=

  for /L %%\ in (1000,-1,0) do (

   set /a "rt+=31416/60"
   
   if !ds! lss 1000 set /a ds+=10

   setlocal

   set /a "a=(15708-rt) %% 62832, c=(a>>31|1)*a"

   if !c! gtr 47124 (set /a "a=a-(a>>31|1)*62832, b=%SIN%, a=rt %% 62832, c=(a>>31|1)*a")  else (if !c! gtr 15708 (set /a "a=(a>>31|1)*31416-a, b=%SIN%, a=rt %% 62832, c=(a>>31|1)*a") else set /a "b=%SIN%, a=rt %% 62832, c=(a>>31|1)*a")
   if !c! gtr 47124 (set /a "a=a-(a>>31|1)*62832, a=%SIN%")  else (if !c! gtr 15708 (set /a "a=(a>>31|1)*31416-a, a=%SIN%") else set /a "a=%SIN%")

   for %%f in ("0 9999" "-5000 8661" "-8661 5000" "-9999 0" "-8661 -5000" "-5000 -8661" "0 -9999" "5000 -8661" "8661 -5000" "9999 0" "8661 5000" "5000 8661") do for /f "tokens=1,2" %%g in (%%f) do (

   for %%t in ("3827 9239" "7071 7071" "9239 3827" "9999 0" "9239 -3827" "7071 -7071" "3827 -9239") do for /f "tokens=1,2" %%u in (%%t) do (

     set /a "ax=ar*%%h/10000*%%u/10000, az=ar*%%g/10000*%%u/10000, ay=ar*%%v/10000, aax=(ax*b/10000-(ay*a/10000+az*b/10000)*a/10000)*b/10000-(ay*b/10000-az*a/10000)*a/10000, aay=(ax*b/10000-(ay*a/10000+az*b/10000)*a/10000)*a/10000+(ay*b/10000-az*a/10000)*b/10000, e=ax*a/10000+(ay*a/10000+az*b/10000)*b/10000, c=ds*aax/(e-cz)+cx, d=ds*aay/(e-cz)+cy"   

     if not defined L!d! set L!d!=%_empty%
   
     if !e! lss 0 (%_$PLOT_% !c! !d! 1 %_PLOT$_%) else %_$PLOT_% !c! !d! 4 %_PLOT$_%

    )   
   )

   if not "!OT!"=="!time:~-1!" (
     cls & (For /L %%l in (1,1,%lines%) do if not defined L%%l (echo() else echo( !L%%l!)>CON
     if "!OT!"=="0" title Sphere 3D [%%\]
     endlocal
     set OT=!time:~-1!
   ) else endlocal

  )
)
goto :eof


:Init_system

  setlocal DisableDelayedExpansion

  set /a cc=cols+2, ll=lines+2

  mode %cc%,%ll% & cls
  for /F "Tokens=1 delims==" %%v in ('set') do set "%%v="
  set /a cols=%cols%, lines=%lines%
)
  set "_$PLOT_=For /F usebackq^ tokens^=1-3 %%x in ('"
  set "_PLOT$_=') do set /a f=%%x+1 & For %%w in (!f!) do set L%%y=!L%%y:~0,%%x!!g:~%%z,1!!L%%y:~%%w!"

  set "SIN=(a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000)"

  setlocal EnableDelayedExpansion

  For /L %%l in (1,1,%cols%) do set "_empty=!_empty! "

  set g= .±²@"

Goto :Main


einstein1969

Re: DosBatch 3D Engine.

Posted: 27 May 2014 13:18
by Squashman
einstein1969 wrote:I started and the first I chose to draw a 3D sphere which is the base of all animations .

I thought polygons were?

Regardless what you did so far is pretty cool.

Re: DosBatch 3D Engine.

Posted: 27 May 2014 14:25
by einstein1969
Squashman wrote:
einstein1969 wrote:I started and the first I chose to draw a 3D sphere which is the base of all animations .

I thought polygons were?

Regardless what you did so far is pretty cool.


Thanks Squashman.

There are only 3D points/dot and a very simple Z buffer. The animation is rotation of points of sphere. The number that you see in the code are the pre-calcultate angle of dot on the surface of the sphere. Then the script calculate in real time the position of the dots and after rotate. The last is projecting in prospective mode.

Re: DosBatch 3D Engine.

Posted: 28 May 2014 19:00
by Ed Dyreen
that's amazing

Re: DosBatch 3D Engine.

Posted: 29 May 2014 07:33
by einstein1969
Thanks Ed!

I think that is more beauty if I add input control for move the sphere (pan,rotate,zoom) and change focal lenght. Is more istructive...

I will do!

einstein1969

Re: DosBatch 3D Engine.

Posted: 29 May 2014 07:57
by foxidrive
Ed Dyreen wrote:that's amazing


It is good, very impressive.

Re: DosBatch 3D Engine.

Posted: 29 May 2014 21:39
by dbenham
einstein1969 wrote:I think that is more beauty if I add input control for move the sphere (pan,rotate,zoom) and change focal lenght. Is more istructive...

I will do!

That certainly will make it even more incredible. But it is already high on the cool meter. 8)

Re: DosBatch 3D Engine.

Posted: 30 May 2014 06:11
by Squashman
And it will be super awesome when you figure out color and shading.

Re: DosBatch 3D Engine.

Posted: 30 May 2014 10:08
by einstein1969
Squashman wrote:And it will be super awesome when you figure out color and shading.


The color is a big problem in dos batch. I tried something but there are too variables for generate
a consistent result. In fact is that I can not do alone to solve the problem. It would take the cooperation of others. :idea:

What are the variables to control for consistent result?

- The monitor type.
- The gamma of monitor
- The configuration of smooth color in windows.
- The configuration of gamma in windows
- The configuration of ClearType font in windows.
- The font obviously. For example using the lucida sans unicode. But I don't know if findstr can manage this.
- The calculous of palette finally in HSV rater RGB for examples.
- Then we can use custom palette or standard and adding antialiasing and dithering.

And the speed of findstr is not too much for real time rendering. Static thing we can do.

einstein1969

Re: DosBatch 3D Engine.

Posted: 02 Jun 2014 03:27
by Dragokas
einstein1969 wrote:Does anyone know the previous works in this context?


Look here: http://www.cyberforum.ru/beta-testing/thread375694.html
There are some code without assembler in archieve.

Best wishes, Alex.

Re: DosBatch 3D Engine.

Posted: 02 Jun 2014 13:19
by einstein1969
Dragokas wrote:
einstein1969 wrote:Does anyone know the previous works in this context?


Look here: http://www.cyberforum.ru/beta-testing/thread375694.html
There are some code without assembler in archieve.

Best wishes, Alex.


Good!

Many thanks Alex!

einstein1969

Re: DosBatch 3D Engine.

Posted: 14 Jul 2014 07:02
by einstein1969
Hi to all!

I'm going to do a complete batch file that draw a sphere with a technique like ray tracing.

I will calculate a light that are on the surface of the sphere and draw this information.

I will do step by step.

I have not done in this manner. There will be mistakes and corrections, as well as choices to make to speed things up. I do not know if it will be possible to draw in real time. But this time I will also go over the maximum reached. I share this journey with you.

The first step is draw a 3D sphere in 2D plane. This is draw a circle.

The first step is this:

Code: Select all

@echo off & setlocal EnableDelayedExpansion

rem use font raster 8x8 for better aspect ratio.

:: Sphere radius
set R=15

For /L %%y in (-%R%,1,%R%) do (
  For /L %%x in (-%R%,1,%R%) do (

    :: calculate sphere equation
    set /a S=%%x*%%x+%%y*%%y-R*R

    :: draw the sphere
    if !S! leq 0 (set/p".=*"<nul) else set/p".=."<nul
  )
  echo(
)


This is better and faster way than using SIN/COS method.

einstein1969

Re: DosBatch 3D Engine.

Posted: 21 Oct 2015 07:32
by einstein1969
from 31-May-2014

improvements:

Code: Select all

    :: v 0.0.2 passed from 16.6 FPS to ~20.0 FPS


Code: Select all

@echo off & setlocal EnableDelayedExpansion & title Sphere 3D & set /a cols=62, lines=58 & goto :Init_system


    :: By einstein1969. Dedicated to jeb, dbenham, penpen, carlos, aGerman, Aacini, EdDyreen,
    :: npocmaka_, Sponge Belly, Magialisk, the users and the staff of Dostips forum.

    :: Use raster font 8x8

    :: v 0.0.2 passed from 16.6 FPS to ~20.0 FPS

    :: Variables enigma:

    :: ?   =   Sphere radius
    :: rt   =   Rotation angle
    :: ds   =   Distance Z of sphere
    :: _dx,_dy   =   Offset x,y of projecting coordinates in 2D plane.
    :: a,b   =   Sine, cosine of rotation angle
    :: ax,ay,az   =   Rotation coordinate 3D, now a, b, c
    :: c,d   =   X,Y coordinate of projecting 3D to 2D, now a,b
    :: e   =   Z coordinate, now c

:Main

set /a ?=100, rt=0, ds=0, _dx=cols/2, _dy=lines/2, _dz=4000, _1=10000

:loop

(setlocal

  for /F "Tokens=1 delims==" %%v in ('set _') do set "%%v="
  set lines=
  set cols=

  rem giro completo (120)*31416/60 o multipli di 120
  for /L %%\ in (0,1,1199) do (
   
   set /a "rt+=31416/60"
   
   if !ds! lss 1000 (set /a ds+=10) else %_FPS%

   setlocal

   set /a "a=(15708-rt) %% 62832, c=(a>>31|1)*a"

   if !c! gtr 47124 (set /a "a=a-(a>>31|1)*62832, b=%_SIN%, a=rt %% 62832, c=(a>>31|1)*a")  else (if !c! gtr 15708 (set /a "a=(a>>31|1)*31416-a, b=%_SIN%, a=rt %% 62832, c=(a>>31|1)*a") else set /a "b=%_SIN%, a=rt %% 62832, c=(a>>31|1)*a")
   if !c! gtr 47124 (set /a "a=a-(a>>31|1)*62832, a=%_SIN%")  else (if !c! gtr 15708 (set /a "a=(a>>31|1)*31416-a, a=%_SIN%") else set /a "a=%_SIN%")

   For /f "tokens=1,2" %%a in ("!a! !b!") do for %%f in ("0 9999" "-5000 8661" "-8661 5000" "-9999 0" "-8661 -5000" "-5000 -8661" "0 -9999" "5000 -8661" "8661 -5000" "9999 0" "8661 5000" "5000 8661") do for /f "tokens=1,2" %%g in (%%f) do (

   for %%t in ("3827 9239" "7071 7071" "9239 3827" "9999 0" "9239 -3827" "7071 -7071" "3827 -9239") do for /f "tokens=1,2" %%u in (%%t) do (

     set /a "a=?*%%h/10000*%%u/10000, c=?*%%g/10000*%%u/10000, b=?*%%v/10000, a=(a*%%b/10000-(b*%%a+c*%%b)/10000*%%a/10000)*%%b/10000-(b*%%b-c*%%a)/10000*%%a/10000, b=(?*%%h/10000*%%u/10000*%%b/10000-(b*%%a+c*%%b)/10000*%%a/10000)*%%a/10000+(b*%%b-c*%%a)/10000*%%b/10000, c=?*%%h/10000*%%u/10000*%%a/10000+(?*%%v/10000*%%a+c*%%b)/10000*%%b/10000, a=ds*a/(c-%_dz%)+%_dx%, b=ds*b/(c-%_dz%)+%_dy%"

     if not defined L!b! set L!b!=%_empty%

     if !c! lss 0 (%_$PLOT_% !a! !b! 1 %_PLOT$_%) else %_$PLOT_% !a! !b! 2 %_PLOT$_%

    )   
   )

   if not "!OT!"=="!time:~-1!" (
     cls & (For /L %%l in (1,1,%lines%) do if not defined L%%l (echo() else echo( !L%%l!)>CON
     endlocal
     set OT=!time:~-1!
   ) else endlocal
  )

endlocal)

set /a ds=1000, rt=1200*31416/60

goto :loop

:Init_system

  set /a cc=cols+2, ll=lines+2
  mode %cc%,%ll% & cls


  for /F "Tokens=1 delims==" %%v in ('set') do set "%%v="
  set /a cols=%cols%, lines=%lines%
)

  setlocal DisableDelayedExpansion

  set "_$PLOT_=For /F usebackq^ tokens^=1-3 %%x in ('"
  set "_PLOT$_=') do set c=!L%%y:~%%x!& set L%%y=!L%%y:~0,%%x!!g:~%%z,1!!c:~1!"

  set "_SIN=(a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000)"

  set _FPS=if   %%\  geq !_FPS_NC! (set /a "_FPS_NC=1!time:~-5,-3!!time:~-2!, _dt_F=_FPS_NC-t0_F, t0_F=_FPS_NC, mFPS=_dt_F-1>>31, _FPS_NC=_dt_F/(_dt_F+(mFPS&1)), _dt_F=(%%\-oFPS)*10000/(_dt_F+(mFPS&6000)), _FPS_NC=%%\+8*_dt_F/100+(1-_FPS_NC)*100, oFPS=%%\, mFPS=1000000000/(_dt_F+(_dt_F-1>>31&1))" ^&title Sphere 3D - FPS=!_dt_F:~0,-2!.!_dt_F:~-2! [!mFPS:~0,-1!.!mFPS:~-1! æs] [#%%\]^& set mFPS=^& set _dt_F=)

  setlocal EnableDelayedExpansion

  For /L %%l in (1,1,%cols%) do set "_empty=!_empty! "

  set g= .@"

Goto :Main



einstein1969

Re: DosBatch 3D Engine.

Posted: 23 Oct 2015 01:03
by Aacini
I like this program! :D I wanted to modify it in order to control the rotation of the sphere via WASDQZERX keys this way:

Code: Select all

            up
 zoom in    ^
        \   |   counterclockwise <- E  R -> clockwise
         Q  W
  left <- A S D -> right
         Z  |
        /   v   X = exit
zoom out   down

However, I can not sucessfully do it. I just achieved to implement Q-Z keys to change the size of the sphere, A-D to control the speed of the rotation, and X key for exit. I don't understand how "rt" variable is used to modify the three rotation axes. I would need more information in order to complete my goal!

Code: Select all

@echo off
setlocal EnableDelayedExpansion

REM APA mod
if "%1" neq "" goto %1

title Sphere 3D


    :: By einstein1969. Dedicated to jeb, dbenham, penpen, carlos, aGerman, Aacini, EdDyreen,
    :: npocmaka_, Sponge Belly, Magialisk, the users and the staff of Dostips forum.

    :: Use raster font 8x8

    :: v 0.0.2 passed from 16.6 FPS to ~20.0 FPS

    :: Variables enigma:

    :: ?   =   Sphere radius
    :: rt   =   Rotation angle
    :: ds   =   Distance Z of sphere
    :: _dx,_dy   =   Offset x,y of projecting coordinates in 2D plane.
    :: a,b   =   Sine, cosine of rotation angle
    :: ax,ay,az   =   Rotation coordinate 3D, now a, b, c
    :: c,d   =   X,Y coordinate of projecting 3D to 2D, now a,b
    :: e   =   Z coordinate, now c


:Init_system

  set /a cols=62, lines=58

  set /a cc=cols+2, ll=lines+2
  mode %cc%,%ll% & cls


  for /F "Tokens=1 delims==" %%v in ('set') do set "%%v="
  set /a cols=%cols%, lines=%lines%
  REM APA mod
  set "ComSpec=%ComSpec%"
)

  setlocal DisableDelayedExpansion

  set "_$PLOT_=For /F usebackq^ tokens^=1-3 %%x in ('"
  set "_PLOT$_=') do set c=!L%%y:~%%x!& set L%%y=!L%%y:~0,%%x!!g:~%%z,1!!c:~1!"

  set "_SIN=(a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000)"

  setlocal EnableDelayedExpansion

  For /L %%l in (1,1,%cols%) do set "_empty=!_empty! "

  set g= .@"

set /a ?=100, rt=0, ds=800, _dx=cols/2, _dy=lines/2, _dz=4000, _1=10000


REM APA mod
cd . > pipeFile.txt
"%~F0" Input >> pipeFile.txt | "%~F0" Main < pipeFile.txt
del pipeFile.txt
goto :EOF


REM Get control keys and send the corresponding command to Main part
:Input
set Drt=0
set ds=800
set exit=0
set "letter= ADQZX"
set "com[A]=Drt-=31416/180"  &  set "var[A]=Drt"
set "com[D]=Drt+=31416/180"  &  set "var[D]=Drt"
set "com[Q]=ds+=100"         &  set "var[Q]=ds"
set "com[Z]=ds-=100"         &  set "var[Z]=ds"
set "com[X]=exit=1"          &  set "var[X]=exit"

title Rotating Sphere - Speed=%Drt%,  Zoom=%ds:~0,-1%%%
:getKey
   C:\Windows\System32\choice /C %letter% /N
   set "option=!letter:~%errorlevel%,1!"
   set /A "!com[%option%]!"
   set "var=!var[%option%]!"
   echo %var%=!%var%!
   title Rotating Sphere - Speed=%Drt%,  Zoom=%ds:~0,-1%%%
if %option% neq X goto getKey
C:\Windows\System32\ping localhost -n 3 > NUL
exit



:Main

(setlocal

  for /F "Tokens=1 delims==" %%v in ('set _') do set "%%v="
  set lines=
  set cols=

  rem giro completo (120)*31416/60 o multipli di 120
  for /L %%\ in () do (
   
   REM APA mod
   set /P "command="
   if defined command (
      set /A "!command!"
      set "command="
      if !exit! neq 0 exit
   )
   REM Instead of: if !ds! lss 1000 (set /a ds+=10) else %_FPS%

   set /a "rt+=Drt"
   
   setlocal

   set /a "a=(15708-rt) %% 62832, c=(a>>31|1)*a"

   if !c! gtr 47124 (
      set /a "a=a-(a>>31|1)*62832, b=%_SIN%, a=rt %% 62832, c=(a>>31|1)*a"
   ) else if !c! gtr 15708 (
      set /a "a=(a>>31|1)*31416-a, b=%_SIN%, a=rt %% 62832, c=(a>>31|1)*a"
   ) else (
      set /a "b=%_SIN%, a=rt %% 62832, c=(a>>31|1)*a"
   )

   if !c! gtr 47124 (
      set /a "a=a-(a>>31|1)*62832, a=%_SIN%"
   )  else if !c! gtr 15708 (
      set /a "a=(a>>31|1)*31416-a, a=%_SIN%"
   ) else (
      set /a "a=%_SIN%"
   )

   For /f "tokens=1,2" %%a in ("!a! !b!") do for %%f in ("0 9999" "-5000 8661" "-8661 5000" "-9999 0" "-8661 -5000" "-5000 -8661" "0 -9999" "5000 -8661" "8661 -5000" "9999 0" "8661 5000" "5000 8661") do for /f "tokens=1,2" %%g in (%%f) do (

   for %%t in ("3827 9239" "7071 7071" "9239 3827" "9999 0" "9239 -3827" "7071 -7071" "3827 -9239") do for /f "tokens=1,2" %%u in (%%t) do (

     set /a "a=?*%%h/10000*%%u/10000, c=?*%%g/10000*%%u/10000, b=?*%%v/10000, a=(a*%%b/10000-(b*%%a+c*%%b)/10000*%%a/10000)*%%b/10000-(b*%%b-c*%%a)/10000*%%a/10000, b=(?*%%h/10000*%%u/10000*%%b/10000-(b*%%a+c*%%b)/10000*%%a/10000)*%%a/10000+(b*%%b-c*%%a)/10000*%%b/10000, c=?*%%h/10000*%%u/10000*%%a/10000+(?*%%v/10000*%%a+c*%%b)/10000*%%b/10000, a=ds*a/(c-%_dz%)+%_dx%, b=ds*b/(c-%_dz%)+%_dy%"

     if not defined L!b! set L!b!=%_empty%

     if !c! lss 0 (%_$PLOT_% !a! !b! 1 %_PLOT$_%) else %_$PLOT_% !a! !b! 2 %_PLOT$_%

    )   
   )

   if not "!OT!"=="!time:~-1!" (
     cls & (For /L %%l in (1,1,%lines%) do if not defined L%%l (echo() else echo( !L%%l!)>CON
     endlocal
     set OT=!time:~-1!
   ) else endlocal
  )

endlocal)

Antonio