BBC BASIC for Windows
« 3D Gaming Project »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:50pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 2 3  ...  8 Notify Send Topic Print
 veryhotthread  Author  Topic: 3D Gaming Project  (Read 1742 times)
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx 3D Gaming Project
« Thread started on: Feb 7th, 2016, 8:53pm »

DDRM asked to see a demo of my 3D project, so here goes.
I am learning to create 3D graphics for gaming purpose which has to be said is a steep learning curve. It started with a cube:
Code:
      MODE 3
      *REFRESH OFF
      DIM points(7,3)
      DIM faces(13,5)
      DIM temp(13)
      points(0,0)=100
      points(0,1)=100
      points(0,2)=-100
      points(1,0)=100
      points(1,1)=-100
      points(1,2)=-100
      points(2,0)=-100
      points(2,1)=-100
      points(2,2)=-100
      points(3,0)=-100
      points(3,1)=100
      points(3,2)=-100
      points(4,0)=100
      points(4,1)=100
      points(4,2)=100
      points(5,0)=100
      points(5,1)=-100
      points(5,2)=100
      points(6,0)=-100
      points(6,1)=-100
      points(6,2)=100
      points(7,0)=-100
      points(7,1)=100
      points(7,2)=100
      x=.05
      y=.05
      z=.05
      REPEAT
        PROCcalcangles
        PROCfacessetup
        PROCfacesorder
        CLS
        PROCfacesprint
        *REFRESH
        WAIT 20
        x=.1
        y=.1
        z=.1
      UNTIL FALSE
      END



      DEF PROCcalcangles
      PROCrotatex
      PROCrotatey
      PROCrotatez
      ENDPROC



      DEF PROCfacesorder
      REPEAT
        clearpass=0
        FOR loop=0 TO 4
          testa=faces(12,loop)
          testb=faces(12,loop+1)
          IF testb>testa THEN PROCsort
        NEXT
      UNTIL clearpass=0
      ENDPROC



      DEF PROCsort
      FOR loopa=0 TO 13
        temp(loopa)=faces(loopa,loop)
        faces(loopa,loop)=faces(loopa,loop+1)
        faces(loopa,loop+1)=temp(loopa)
        clearpass=1
      NEXT
      ENDPROC



      DEF PROCrotatez
      FOR loop%=0 TO 7
        rota=((points(loop%,0))*COSz)-((points(loop%,1))*SINz)
        rotb=((points(loop%,0))*SINz)+((points(loop%,1))*COSz)
        points(loop%,0)=rota
        points(loop%,1)=rotb
      NEXT
      ENDPROC



      DEF PROCrotatey
      FOR loop%=0 TO 7
        rota=((points(loop%,0))*COSy)-((points(loop%,2))*SINy)
        rotb=((points(loop%,0))*SINy)+((points(loop%,2))*COSy)
        points(loop%,0)=rota
        points(loop%,2)=rotb
      NEXT
      ENDPROC



      DEF PROCrotatex
      FOR loop%=0 TO 7
        rota=((points(loop%,1))*COSx)-((points(loop%,2))*SINx)
        rotb=((points(loop%,1))*SINx)+((points(loop%,2))*COSx)
        points(loop%,1)=rota
        points(loop%,2)=rotb
      NEXT
      ENDPROC



      DEF PROCfacessetup
      faces(0,0)=points(0,0)
      faces(1,0)=points(0,1)
      faces(2,0)=points(0,2)
      faces(3,0)=points(4,0)
      faces(4,0)=points(4,1)
      faces(5,0)=points(4,2)
      faces(6,0)=points(1,0)
      faces(7,0)=points(1,1)
      faces(8,0)=points(1,2)
      faces(9,0)=points(5,0)
      faces(10,0)=points(5,1)
      faces(11,0)=points(5,2)
      faces(13,0)=1
      faces(0,1)=points(0,0)
      faces(1,1)=points(0,1)
      faces(2,1)=points(0,2)
      faces(3,1)=points(3,0)
      faces(4,1)=points(3,1)
      faces(5,1)=points(3,2)
      faces(6,1)=points(1,0)
      faces(7,1)=points(1,1)
      faces(8,1)=points(1,2)
      faces(9,1)=points(2,0)
      faces(10,1)=points(2,1)
      faces(11,1)=points(2,2)
      faces(13,1)=2
      faces(0,2)=points(7,0)
      faces(1,2)=points(7,1)
      faces(2,2)=points(7,2)
      faces(3,2)=points(4,0)
      faces(4,2)=points(4,1)
      faces(5,2)=points(4,2)
      faces(6,2)=points(6,0)
      faces(7,2)=points(6,1)
      faces(8,2)=points(6,2)
      faces(9,2)=points(5,0)
      faces(10,2)=points(5,1)
      faces(11,2)=points(5,2)
      faces(13,2)=3
      faces(0,3)=points(7,0)
      faces(1,3)=points(7,1)
      faces(2,3)=points(7,2)
      faces(3,3)=points(3,0)
      faces(4,3)=points(3,1)
      faces(5,3)=points(3,2)
      faces(6,3)=points(6,0)
      faces(7,3)=points(6,1)
      faces(8,3)=points(6,2)
      faces(9,3)=points(2,0)
      faces(10,3)=points(2,1)
      faces(11,3)=points(2,2)
      faces(13,3)=4
      faces(0,4)=points(0,0)
      faces(1,4)=points(0,1)
      faces(2,4)=points(0,2)
      faces(3,4)=points(4,0)
      faces(4,4)=points(4,1)
      faces(5,4)=points(4,2)
      faces(6,4)=points(3,0)
      faces(7,4)=points(3,1)
      faces(8,4)=points(3,2)
      faces(9,4)=points(7,0)
      faces(10,4)=points(7,1)
      faces(11,4)=points(7,2)
      faces(13,4)=5
      faces(0,5)=points(2,0)
      faces(1,5)=points(2,1)
      faces(2,5)=points(2,2)
      faces(3,5)=points(6,0)
      faces(4,5)=points(6,1)
      faces(5,5)=points(6,2)
      faces(6,5)=points(1,0)
      faces(7,5)=points(1,1)
      faces(8,5)=points(1,2)
      faces(9,5)=points(5,0)
      faces(10,5)=points(5,1)
      faces(11,5)=points(5,2)
      faces(13,5)=6
      FOR loop=0 TO 5
        average=(faces(2,loop)+faces(5,loop)+faces(8,loop)+faces(11,loop))/4
        faces(12,loop)=average
      NEXT
      ENDPROC



      DEF PROCfacesprint
      FOR loop%=0 TO 5
        GCOL 0,faces(13,loop%)
        MOVE faces(0,loop%)*2+500,faces(1,loop%)*2+500
        MOVE faces(0,loop%)*2+500,faces(1,loop%)*2+500
        PLOT 85,faces(3,loop%)*2+500,faces(4,loop%)*2+500
        PLOT 85,faces(6,loop%)*2+500,faces(7,loop%)*2+500
        PLOT 85,faces(9,loop%)*2+500,faces(10,loop%)*2+500
      NEXT
      ENDPROC
 

After this I moved onto
the more complex issue of shading!!

Just copy, paste and RUN.

See you next time.
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #1 on: Feb 7th, 2016, 8:56pm »

Sorry its not annotated, I was not intending to make the code public.
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #2 on: Feb 9th, 2016, 8:35pm »

Evening all,
Here are a few more developments in my project.

I realised that in order to create a shading effect I would have to simulate light some how. Vectors are the answer, which aren't that complicated but necessitated a look back at the old GCSE maths books.

First I calculated the vectors from the centre of the object, which worked well, but was never going to work for objects with faces not perpendicular with the origin.

Back to the maths books, Normal vector calculation was needed. Slightly more complicated but still nothing serious.

This was the result:

The calculations are the real time computaions of all the vectors needed.
Code:
      DIM points(26)
      MODE 3
      *REFRESH OFF
      points(0)=-2
      points(1)=0
      points(2)=2
      points(3)=2
      points(4)=0
      points(5)=2
      points(6)=-2
      points(7)=0
      points(8)=-2
      points(9)=2
      points(10)=0
      points(11)=-2
      x=.01
      y=.01
      z=.01

      REPEAT
        PROCprintface
        PROCcalcnormal
        PROCprintnormal
        PROCcalcangles
        *REFRESH
        REM WAIT 20
        CLS
      UNTIL INKEY(-99)=-1
      END




      DEF PROCcalcangles
      PROCrotatex
      PROCrotatey
      PROCrotatez
      ENDPROC




      DEF PROCrotatez
      FOR loop%=0 TO 9 STEP 3
        rota=((points(loop%))*COSz)-((points(loop%+1))*SINz)
        rotb=((points(loop%))*SINz)+((points(loop%+1))*COSz)
        points(loop%)=rota
        points(loop%+1)=rotb
      NEXT
      ENDPROC



      DEF PROCrotatey
      FOR loop%=0 TO 9 STEP 3
        rota=((points(loop%))*COSy)-((points(loop%+2))*SINy)
        rotb=((points(loop%))*SINy)+((points(loop%+2))*COSy)
        points(loop%)=rota
        points(loop%+2)=rotb
      NEXT
      ENDPROC



      DEF PROCrotatex
      FOR loop%=0 TO 9 STEP 3
        rota=((points(loop%+1))*COSx)-((points(loop%+2))*SINx)
        rotb=((points(loop%+1))*SINx)+((points(loop%+2))*COSx)
        points(loop%+1)=rota
        points(loop%+2)=rotb
      NEXT
      ENDPROC




      DEF PROCprintnormal
      points(24)=(points(0)+points(3)+points(6)+points(9))/4
      points(25)=(points(1)+points(4)+points(7)+points(10))/4
      points(26)=(points(2)+points(5)+points(8)+points(11))/4
      GCOL 0,1
      MOVE points(24)*100+500,points(25)*100+400
      DRAW (points(21)+points(24))*100+500,(points(22)+points(25))*100+400
      ENDPROC




      DEF PROCcalcnormal
      points(12)=points(3)-points(0)
      points(13)=points(4)-points(1)
      points(14)=points(5)-points(2)
      points(15)=points(6)-points(0)
      points(16)=points(7)-points(1)
      points(17)=points(8)-points(2)
      PRINTTAB(0,0)"v1 [";points(12);"]"
      PRINTTAB(0,1)"   [";points(13);"]"
      PRINTTAB(0,2)"   [";points(14);"]"
      PRINTTAB(18,0)"v2 [";points(15);"]"
      PRINTTAB(18,1)"   [";points(16);"]"
      PRINTTAB(18,2)"   [";points(17);"]"
      points(18)=(points(13)*points(17))-(points(14)*points(16))
      points(19)=(points(14)*points(15))-(points(12)*points(17))
      points(20)=(points(12)*points(16))-(points(13)*points(15))
      PRINTTAB(36,0)"n1 [";points(18);"]"
      PRINTTAB(36,1)"   [";points(19);"]"
      PRINTTAB(36,2)"   [";points(20);"]"
      veclen=SQR((points(18)*points(18))+(points(19)*points(19))+(points(20)*points(20)))
      points(21)=points(18)/veclen
      points(22)=points(19)/veclen
      points(23)=points(20)/veclen
      PRINTTAB(54,0)"u1 [";points(21);"]"
      PRINTTAB(54,1)"   [";points(22);"]"
      PRINTTAB(54,2)"   [";points(23);"]"
      ENDPROC




      DEF PROCprintface
      GCOL 0,15
      MOVE points(0)*100+500,points(1)*100+400
      MOVE points(0)*100+500,points(1)*100+400
      DRAW points(3)*100+500,points(4)*100+400
      DRAW points(6)*100+500,points(7)*100+400
      DRAW points(9)*100+500,points(10)*100+400
      DRAW points(0)*100+500,points(1)*100+400
      ENDPROC
 


The vector required is the red line poking out of the middle of the mock face. u1 is the unit vector which is required to calculate the cosine angle with the light to produce shading.

Happy viewing
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #3 on: Feb 9th, 2016, 8:44pm »

After this I needed a good sorting algorithm, the one I was using was a simple bubble sort. Soooooooooo sssslllllloooooowwwwww. After a bit of research I plumped for a merge sort.
Code:
      MODE 3
      ON ERROR GOTO 20
      DIM faces(1,2047)
      DIM tempsort(7,2047)
      FOR loop%=0 TO 2047
        faces(1,loop%)=RND(5000)
      NEXT
      offset=2
      left=0
      right=0
      column=0
      destcolumn=2
      count=0
      TIME=0

      FOR loop%=0 TO 2047 STEP 2
        IF faces(1,loop%)>faces(1,loop%+1) THEN
          tempsort(0,loop%)=faces(1,loop%)
          tempsort(0,loop%+1)=faces(1,loop%+1)
          tempsort(1,loop%)=loop%
          tempsort(1,loop%+1)=loop%+1
        ELSE
          tempsort(0,loop%)=faces(1,loop%+1)
          tempsort(0,loop%+1)=faces(1,loop%)
          tempsort(1,loop%)=loop%+1
          tempsort(1,loop%+1)=loop%
        ENDIF
      NEXT

      WHILE offset<2047
  
        FOR loop%=0 TO 2047 STEP offset*2
    
          REPEAT
      
            IF tempsort(column,loop%+left)>tempsort(column,loop%+right+offset) THEN
              tempsort(destcolumn,count)=tempsort(column,loop%+left)
              tempsort(destcolumn+1,count)=tempsort(column+1,loop%+left)
              left+=1
            ELSE
              tempsort(destcolumn,count)=tempsort(column,loop%+right+offset)
              tempsort(destcolumn+1,count)=tempsort(column+1,loop%+right+offset)
              right+=1
            ENDIF
            count+=1
      
          UNTIL left=offset OR right=offset
    
          IF left=offset THEN
      
            REPEAT
              tempsort(destcolumn,count)=tempsort(column,loop%+offset+right)
              tempsort(destcolumn+1,count)=tempsort(column+1,loop%+offset+right)
              right+=1
              count+=1
            UNTIL right=offset
      
          ELSE
      
            REPEAT
              tempsort(destcolumn,count)=tempsort(column,loop%+left)
              tempsort(destcolumn+1,count)=tempsort(column+1,loop%+left)
              left+=1
              count+=1
            UNTIL left=offset
      
          ENDIF
          left=0
          right=0
    
        NEXT
        count=0
        column=(column+2) MOD 4
        destcolumn=(destcolumn+2) MOD 4
        offset*=2
  
      ENDWHILE

      PRINT TIME








   10 FOR loop%=0 TO 2047
        PRINT " "tempsort(1,loop%);" ";tempsort(2,loop%),
      NEXT
   20 PRINT "COUNT      ";count
      PRINT "LEFT       ";left
      PRINT "RIGHT      ";right
      PRINT "OFFSET     ";offset
      PRINT "COLUMN     ";column
      PRINT "DESTCOLUMN ";destcolumn
 


The code generates a random list of 2047 numbers and then sorts them in to size order (this is needed to place all the faces of an object into relative distance/depth before displaying). The sort takes milli seconds but printing the result takes time. The number on the left is the position the number on the right started in the list.

Happy viewing.
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #4 on: Feb 9th, 2016, 8:51pm »

It was now time to apply this to the cube.
Here is an all green cube with shading showing the normal vectors and using the merge sort.
Code:
      REM faces(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,Az)
      REM tempsort(Az,loc,Az,loc,none,Ax,Ay,v1x,v1y,v1z,v2x,v2y,v2z,Nx,Ny,Nz)
      MODE 3
      REM ON ERROR PROCerror
      HIMEM=(LOMEM+500000000) AND -4
      REM *REFRESH OFF
      DIM points(2,2047)
      DIM faces(12,2047)
      DIM tempsort(16,2047)
      FOR LOOPY=0 TO 2047
        FOR LOOPX=0 TO 7
          tempsort(LOOPX,LOOPY)=-1000
        NEXT
      NEXT
      FOR LOOPY=0 TO 2047
        FOR LOOPX=0 TO 12
          faces(LOOPX,LOOPY)=-1000
        NEXT
      NEXT

      points(0,0)=100
      points(1,0)=100
      points(2,0)=-100
      points(0,1)=100
      points(1,1)=-100
      points(2,1)=-100
      points(0,2)=-100
      points(1,2)=-100
      points(2,2)=-100
      points(0,3)=-100
      points(1,3)=100
      points(2,3)=-100
      points(0,4)=100
      points(1,4)=100
      points(2,4)=100
      points(0,5)=100
      points(1,5)=-100
      points(2,5)=100
      points(0,6)=-100
      points(1,6)=-100
      points(2,6)=100
      points(0,7)=-100
      points(1,7)=100
      points(2,7)=100




      x=0.1
      y=0.05
      z=0.1
      PROCfacessetup
      REPEAT
        REM TIME=0
        PROCcalcangles
        REM PRINTTAB(0,0);TIME
        REM TIME=0
        PROCfacessetup
        REM PRINTTAB(0,1);TIME
        REM TIME=0
        PROCcalcZaverages
        REM PRINTTAB(0,2);TIME
        REM TIME=0
        PROCfacesorder
        REM PRINTTAB(55,19);TIME
        PROCcalcXYaverages
        CLS
        REM TIME=0
        REM PROCprintZs
        PROCfindvector
        PROCfacesprint
        *REFRESH
        REM PRINTTAB(0,3);TIME
      UNTIL FALSE
      END



      DEF PROCcalcangles
      PROCrotatex
      PROCrotatey
      PROCrotatez
      ENDPROC



      DEF PROCcalcZaverages
      FOR loop%=0 TO 2047
        faces(12,loop%)=(faces(2,loop%)+faces(5,loop%)+faces(8,loop%)+faces(11,loop%))/4
      NEXT
      ENDPROC



      DEF PROCcalcXYaverages
      FOR loop%=0 TO 2047
        tempsort(6,loop%)=(faces(0,tempsort(1,loop%))+faces(3,tempsort(1,loop%))+faces(6,tempsort(1,loop%))+faces(9,tempsort(1,loop%)))/4
        tempsort(7,loop%)=(faces(1,tempsort(1,loop%))+faces(4,tempsort(1,loop%))+faces(7,tempsort(1,loop%))+faces(10,tempsort(1,loop%)))/4
      NEXT
      ENDPROC



      DEF PROCfacesorder

      offset=2
      left=0
      right=0
      column=0
      destcolumn=2
      count=0
      TIME=0

      FOR loop%=0 TO 2047 STEP 2
        IF faces(12,loop%)>faces(12,loop%+1) THEN
          tempsort(0,loop%)=faces(12,loop%)
          tempsort(0,loop%+1)=faces(12,loop%+1)
          tempsort(1,loop%)=loop%
          tempsort(1,loop%+1)=loop%+1
        ELSE
          tempsort(0,loop%)=faces(12,loop%+1)
          tempsort(0,loop%+1)=faces(12,loop%)
          tempsort(1,loop%)=loop%+1
          tempsort(1,loop%+1)=loop%
        ENDIF
      NEXT

      WHILE offset<2047
  
        FOR loop%=0 TO 2047 STEP offset*2
    
          REPEAT
      
            IF tempsort(column,loop%+left)>tempsort(column,loop%+right+offset) THEN
              tempsort(destcolumn,count)=tempsort(column,loop%+left)
              tempsort(destcolumn+1,count)=tempsort(column+1,loop%+left)
              left+=1
            ELSE
              tempsort(destcolumn,count)=tempsort(column,loop%+right+offset)
              tempsort(destcolumn+1,count)=tempsort(column+1,loop%+right+offset)
              right+=1
            ENDIF
            count+=1
      
          UNTIL left=offset OR right=offset
    
          IF left=offset THEN
      
            REPEAT
              tempsort(destcolumn,count)=tempsort(column,loop%+offset+right)
              tempsort(destcolumn+1,count)=tempsort(column+1,loop%+offset+right)
              right+=1
              count+=1
            UNTIL right=offset
      
          ELSE
      
            REPEAT
              tempsort(destcolumn,count)=tempsort(column,loop%+left)
              tempsort(destcolumn+1,count)=tempsort(column+1,loop%+left)
              left+=1
              count+=1
            UNTIL left=offset
      
          ENDIF
          left=0
          right=0
    
        NEXT
        count=0
        column=(column+2) MOD 4
        destcolumn=(destcolumn+2) MOD 4
        offset*=2
  
      ENDWHILE
      ENDPROC



      DEF PROCsort
      FOR loopa=0 TO 16
        temp(loopa)=faces(loopa,loop)
        faces(loopa,loop)=faces(loopa,loop+1)
        faces(loopa,loop+1)=temp(loopa)
      NEXT
      clearpass=1
      ENDPROC



      DEF PROCrotatez
      FOR loop%=0 TO 2047
        rota=((points(0,loop%))*COSz)-((points(1,loop%))*SINz)
        rotb=((points(0,loop%))*SINz)+((points(1,loop%))*COSz)
        points(0,loop%)=rota
        points(1,loop%)=rotb
      NEXT
      ENDPROC



      DEF PROCrotatey
      FOR loop%=0 TO 2047
        rota=((points(0,loop%))*COSy)-((points(2,loop%))*SINy)
        rotb=((points(0,loop%))*SINy)+((points(2,loop%))*COSy)
        points(0,loop%)=rota
        points(2,loop%)=rotb
      NEXT
      ENDPROC



      DEF PROCrotatex
      FOR loop%=0 TO 2047
        rota=((points(1,loop%))*COSx)-((points(2,loop%))*SINx)
        rotb=((points(1,loop%))*SINx)+((points(2,loop%))*COSx)
        points(1,loop%)=rota
        points(2,loop%)=rotb
      NEXT
      ENDPROC

 

Sill a bit juddery, but it is BASIC still.
Happy viewing.
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: 3D Gaming Project
« Reply #5 on: Feb 10th, 2016, 12:14pm »

Hi Ric,

I get an error due to the lack of a PROCfacessetup... and I can't just lift it from the original "cube" post since the arrays have changed...

Do you know there is a sortlib which implements Quicksort very quickly? It may or not be a good solution to your problem (and you may want to do it yourself out of principle!).

Best wishes,

D
User IP Logged

Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #6 on: Feb 15th, 2016, 09:56am »

Hi D
I must have exceeded the 9000 characters or so. Copy and paste this onto the end of the cube code and it should work! (Probably)
Code:
      DEF PROCfacessetup
      faces(0,0)=points(0,4)
      faces(1,0)=points(1,4)
      faces(2,0)=points(2,4)
      faces(3,0)=points(0,0)
      faces(4,0)=points(1,0)
      faces(5,0)=points(2,0)
      faces(6,0)=points(0,5)
      faces(7,0)=points(1,5)
      faces(8,0)=points(2,5)
      faces(9,0)=points(0,1)
      faces(10,0)=points(1,1)
      faces(11,0)=points(2,1)
      faces(0,1)=points(0,0)
      faces(1,1)=points(1,0)
      faces(2,1)=points(2,0)
      faces(3,1)=points(0,3)
      faces(4,1)=points(1,3)
      faces(5,1)=points(2,3)
      faces(6,1)=points(0,1)
      faces(7,1)=points(1,1)
      faces(8,1)=points(2,1)
      faces(9,1)=points(0,2)
      faces(10,1)=points(1,2)
      faces(11,1)=points(2,2)
      faces(0,2)=points(0,7)
      faces(1,2)=points(1,7)
      faces(2,2)=points(2,7)
      faces(3,2)=points(0,4)
      faces(4,2)=points(1,4)
      faces(5,2)=points(2,4)
      faces(6,2)=points(0,6)
      faces(7,2)=points(1,6)
      faces(8,2)=points(2,6)
      faces(9,2)=points(0,5)
      faces(10,2)=points(1,5)
      faces(11,2)=points(2,5)
      faces(0,3)=points(0,3)
      faces(1,3)=points(1,3)
      faces(2,3)=points(2,3)
      faces(3,3)=points(0,7)
      faces(4,3)=points(1,7)
      faces(5,3)=points(2,7)
      faces(6,3)=points(0,2)
      faces(7,3)=points(1,2)
      faces(8,3)=points(2,2)
      faces(9,3)=points(0,6)
      faces(10,3)=points(1,6)
      faces(11,3)=points(2,6)
      faces(0,4)=points(0,3)
      faces(1,4)=points(1,3)
      faces(2,4)=points(2,3)
      faces(3,4)=points(0,0)
      faces(4,4)=points(1,0)
      faces(5,4)=points(2,0)
      faces(6,4)=points(0,7)
      faces(7,4)=points(1,7)
      faces(8,4)=points(2,7)
      faces(9,4)=points(0,4)
      faces(10,4)=points(1,4)
      faces(11,4)=points(2,4)
      faces(0,5)=points(0,1)
      faces(1,5)=points(1,1)
      faces(2,5)=points(2,1)
      faces(3,5)=points(0,2)
      faces(4,5)=points(1,2)
      faces(5,5)=points(2,2)
      faces(6,5)=points(0,5)
      faces(7,5)=points(1,5)
      faces(8,5)=points(2,5)
      faces(9,5)=points(0,6)
      faces(10,5)=points(1,6)
      faces(11,5)=points(2,6)
      ENDPROC
      place=0
      FOR loop=0 TO 29
        FOR loopa=0 TO 59
          faces(0,place)=points(0,(loop*61)+loopa)
          faces(1,place)=points(1,(loop*61)+loopa)
          faces(2,place)=points(2,(loop*61)+loopa)
          faces(3,place)=points(0,(loop*61)+loopa+1)
          faces(4,place)=points(1,(loop*61)+loopa+1)
          faces(5,place)=points(2,(loop*61)+loopa+1)
          faces(6,place)=points(0,(loop*61)+loopa+61)
          faces(7,place)=points(1,(loop*61)+loopa+61)
          faces(8,place)=points(2,(loop*61)+loopa+61)
          faces(9,place)=points(0,(loop*61)+loopa+62)
          faces(10,place)=points(1,(loop*61)+loopa+62)
          faces(11,place)=points(2,(loop*61)+loopa+62)
          place+=1
        NEXT
      NEXT
      ENDPROC



      DEF PROCfacesprint
      FOR loop%=0 TO 5
        REM Create LIGHT vector
        lightx=-10000-tempsort(6,loop%)
        lighty=-10000-tempsort(7,loop%)
        lightz=0-tempsort(0,loop%)
        lightveclen=SQR((lightx*lightx)+(lighty*lighty)+(lightz*lightz))
        REM Create unit light vector
        lightx=lightx/lightveclen
        lighty=lighty/lightveclen
        lightz=lightz/lightveclen
        REM Create unit vector
        REM veclen=SQR((tempsort(6,loop%)*tempsort(6,loop%))+(tempsort(7,loop%)*tempsort(7,loop%))+(tempsort(0,loop%)*tempsort(0,loop%)))
        REM tempsort(6,loop%)=tempsort(6,loop%)/veclen
        REM tempsort(7,loop%)=tempsort(7,loop%)/veclen
        REM tempsort(0,loop%)=tempsort(0,loop%)/veclen
        REM Create Normal unit vector
        veclen=SQR((tempsort(14,loop%)*tempsort(14,loop%))+(tempsort(15,loop%)*tempsort(15,loop%))+(tempsort(16,loop%)*tempsort(16,loop%)))
        tempsort(14,loop%)=tempsort(14,loop%)/veclen
        tempsort(15,loop%)=tempsort(15,loop%)/veclen
        tempsort(16,loop%)=tempsort(16,loop%)/veclen
        REM Create angle
        angle=(tempsort(14,loop%)*lightx)+(tempsort(15,loop%)*lighty)+(tempsort(16,loop%)*lightz)
        REM PRINT TAB(0,4);angle
        COLOUR 3,0,255*((angle+1)/2),0
        GCOL 0,3
        jump=tempsort(1,loop%)
        MOVE faces(0,jump)+500,faces(1,jump)+500
        MOVE faces(0,jump)+500,faces(1,jump)+500
        PLOT 85,faces(3,jump)+500,faces(4,jump)+500
        PLOT 85,faces(6,jump)+500,faces(7,jump)+500
        PLOT 85,faces(9,jump)+500,faces(10,jump)+500
        GCOL 0,15
        MOVE tempsort(6,loop%)+500,tempsort(7,loop%)+500
        DRAW tempsort(6,loop%)-(tempsort(14,loop%)*100)+500,tempsort(7,loop%)-(tempsort(15,loop%)*100)+500
        REM WAIT 1
      NEXT
      ENDPROC


      DEF PROCprintZs
      FOR loop%=0 TO 2047
        PRINT "";tempsort(0,loop%);" ";tempsort(1,loop%)
        WAIT 1
      NEXT
      PRINT column
      END
      ENDPROC




      DEF PROCfindvector
      FOR loop%=0 TO 5
        jump=tempsort(1,loop%)
        REM NORMAL VECTOR TO PLANE = [P1-P2=V12 THEN P1-P3=V13 THEN V13*V12 (CROSS PRODUCT){(A*B=(A2B3-A3B2),(A3B1-A1B3),(A1B2-A2B1)}]
        tempsort(8,loop%)=faces(3,jump)-faces(0,jump)
        tempsort(9,loop%)=faces(4,jump)-faces(1,jump)
        tempsort(10,loop%)=faces(5,jump)-faces(2,jump)
        tempsort(11,loop%)=faces(6,jump)-faces(0,jump)
        tempsort(12,loop%)=faces(7,jump)-faces(1,jump)
        tempsort(13,loop%)=faces(8,jump)-faces(2,jump)
        tempsort(14,loop%)=(tempsort(9,loop%)*tempsort(13,loop%))-(tempsort(10,loop%)*tempsort(12,loop%))
        tempsort(15,loop%)=(tempsort(10,loop%)*tempsort(11,loop%))-(tempsort(8,loop%)*tempsort(13,loop%))
        tempsort(16,loop%)=(tempsort(8,loop%)*tempsort(12,loop%))-(tempsort(9,loop%)*tempsort(11,loop%))
      NEXT
      ENDPROC




      DEF PROCerror
      PRINT TAB(0,0)"X";faces(14,loop%),"Y";faces(15,loop%),"Z";faces(16,loop%)
      END
 

Where or how do I find to D3D or sortlib?
Regards Ric
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #7 on: Feb 15th, 2016, 09:58am »

Also, the code for each step is getting longer and exceeding 9000 characters, is there a way of posting larger banks of code?
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: 3D Gaming Project
« Reply #8 on: Feb 15th, 2016, 11:29am »

Hi Ric,

That's pretty impressive! Bring on the full game... grin

In terms of posting code, there is a Wiggio group, though it's not letting me log in at the moment, not sure why - possibly that I've forgotten my password, but it won't send me a reminder either, so it may be more than that. There is also a Yahoo group:

https://groups.yahoo.com/neo/groups/bb4w/conversations/messages

Both have file repositories. You would probably have to join (both are free) in order to post. Then you could post a link, though maybe only members could read it...

Best wishes,

D
User IP Logged

Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #9 on: Feb 17th, 2016, 7:45pm »

It may sound obvious, but in order to create the graphics for the game some kind of plotting routine to take a sprite of x,y and transpose it into a rhomboid is needed.

This code does exactly that and to boot it has been designed to use only interger numbers so it can be easily turned into ASM and only to print the pixels required so if you shrink the sprite size to create depth in a gaming view, it does not waste time over printing its self, ok that bit is only 80% efficient, but that can be worked on!!

Code:
   10 MODE 3
   20 DIM sprite(255,255)
   30 REM *********************************************
   40 REM *          GREATE CHESS BOARD             ***
   50 REM *********************************************
   60 FOR x=0 TO 7
   70   FOR y=0 TO 7
   80     IF (x MOD 2=1 AND y MOD 2=1) OR (x MOD 2=0 AND y MOD 2=0) THEN
   90       FOR xloop=0 TO 31
  100         FOR yloop=0 TO 31
  110           sprite((x*32)+xloop,(y*32)+yloop)=1
  120         NEXT
  130       NEXT
  140     ELSE
  150       FOR xloop=0 TO 31
  160         FOR yloop=0 TO 31
  170           sprite((x*32)+xloop,(y*32)+yloop)=4
  180         NEXT
  190       NEXT
  200     ENDIF
  210   NEXT
  220 NEXT
  230 REM ************************************
  240 REM *        PRINT GRID LINES          *
  250 REM ************************************
  260 
  270 FOR LOOP=0 TO 1000 STEP 100
  280   MOVE LOOP,0
  290   DRAW LOOP,1000
  300   MOVE 0,LOOP
  310   DRAW 1000,LOOP
  320 NEXT
  330 REM ******************************************************************************************
  340 REM *          IF YOU REMOVE THE GOTO 380, THIS PRINTS THE CHESS BOARD ORTHOGANALLY          *
  350 REM *          AT THE COORDINATES 0,0                                                        *
  360 REM ******************************************************************************************
  370 GOTO 450
  380 FOR xloop=0 TO 255
  390   FOR yloop=0 TO 255
  400     GCOL 0,sprite(xloop,yloop)
  410     MOVE (xloop*2),(yloop*2)
  420     DRAW (xloop*2),(yloop*2)
  430   NEXT
  440 NEXT
  450 VDU 23,65,&FF,&FF,&FF,&FF,&FF,&FF,&FF,&FF :REM *** ANYONE KNOW WHY THIS COMMAND DOESNT WORK?? ***
  460 VDU 5
  470 GCOL 0,15
  480 MOVE 0,1000
  490 PRINT"The origional tile being transfered is a chessboard, 256x256 pixels."
  500 PRINT"Choose the coordinates for nodes 0,1,2 and 3 and watch"
  510 PRINT""
  520 PRINT"Node order is       N2      N3"
  530 PRINT""
  540 PRINT""
  550 PRINT""
  560 PRINT"                    N0      N1"
  570 MOVE 0,500
  580 GCOL 0,0
  590 PRINT"AAAAAAAAAA"
  600 MOVE 0,500
  610 GCOL 0,15
  620 INPUT"N0x ";x0
  630 IF x0<0 OR x0>1000 THEN 570
  640 MOVE 0,450
  650 GCOL 0,0
  660 PRINT"AAAAAAAAAA"
  670 MOVE 0,450
  680 GCOL 0,15
  690 INPUT"N0y ";y0
  700 IF y0<0 OR y0>1000 THEN 640
  710 MOVE 0,400
  720 GCOL 0,0
  730 PRINT"AAAAAAAAAA"
  740 MOVE 0,400
  750 GCOL 0,15
  760 INPUT"N1x ";x1
  770 IF x1<0 OR x1>1000 THEN 710
  780 MOVE 0,350
  790 GCOL 0,0
  800 PRINT"AAAAAAAAAA"
  810 MOVE 0,350
  820 GCOL 0,15
  830 INPUT"N1y ";y1
  840 IF y1<0 OR y1>1000 THEN 780
  850 MOVE 0,300
  860 GCOL 0,0
  870 PRINT"AAAAAAAAAA"
  880 MOVE 0,300
  890 GCOL 0,15
  900 INPUT"N2x ";x2
  910 IF x2<0 OR x2>1000 THEN 850
  920 MOVE 0,250
  930 GCOL 0,0
  940 PRINT"AAAAAAAAAA"
  950 MOVE 0,250
  960 GCOL 0,15
  970 INPUT"N2y ";y2
  980 IF y2<0 OR y2>1000 THEN 920
  990 MOVE 0,200
 1000 GCOL 0,0
 1010 PRINT"AAAAAAAAAA"
 1020 MOVE 0,200
 1030 GCOL 0,15
 1040 INPUT"N3x ";x3
 1050 IF x3<0 OR x3>1000 THEN 990
 1060 MOVE 0,150
 1070 GCOL 0,0
 1080 PRINT"AAAAAAAAAA"
 1090 MOVE 0,150
 1100 GCOL 0,15
 1110 INPUT"N3y ";y3
 1120 IF y3<0 OR y3>1000 THEN 1060
 1130 
 1140 contspritepointerx%=0           : REM *** CREATE THE CONTINOUS VARIABLE FOR THE POSITION OF THE PRINTING DOT IN THE SPRITE ***
 1150 contspritepointery%=0
 1160 
 1170 spritesizex%=256                : REM *** SET UP THE SPRITE SIZE, THIS IS NOT REALLY NECESSARY FOR THIS DEMO, BUT WOULD    ***
 1180 spritesizey%=256                : REM *** NEED TO BE PASSED TO A ROUTINE WHEN DIFFERENT SPRITES ARE USED                   ***
 1190 
 1200 spritepointerx%=0               : REM *** CREATE THE VARIABLES FOR THE EXACT POSITION OF THE DOT BEING PRINTED IN THE      ***
 1210 spritepointery%=0               : REM *** SPRITE                                                                           ***
 1220 
 1230 division%=1048576               : REM *** THE NUMBER USED TO MULTIPLY EVERYTHING SO INTERGERS CAN BE USED 100% OF THE TIME ***
 1240 
 1250 PROCtranslate_face
 1260 GOTO 470
 1270 
 1280 
 1290 
 1300 
 1310 DEF PROCtranslate_face
 1320 
 1330 scale=1                         : REM *** NOT REALLY NEEDED, BUT CAN BE USED TO ENLARGE THE IMAGE PRINTED, BEWARE!!!       ***
 1340 
 1350 spritepointerx%=0
 1360 spritepointery%=0
 1370 
 1380 p0to1length=(SQR(((x1-x0)*(x1-x0)*division%)+((y1-y0)*(y1-y0)*division%)))DIV1024 : REM *** THE CALCULATIONS USED TO       ***
 1390 p0to2length=(SQR(((x2-x0)*(x2-x0)*division%)+((y2-y0)*(y2-y0)*division%)))DIV1024 : REM *** CALCULATE THE LENGTH OF ALL    ***
 1400 p1to3length=(SQR(((x3-x1)*(x3-x1)*division%)+((y3-y1)*(y3-y1)*division%)))DIV1024 : REM *** SIDES OF THE TRANSPOSED        ***
 1410 p2to3length=(SQR(((x3-x2)*(x3-x2)*division%)+((y3-y2)*(y3-y2)*division%)))DIV1024 : REM *** SPRITE SHAPE                   ***
 1420 
 1430 IF p0to1length>p2to3length THEN           : REM ****************************************
 1440 longesthorizontal%=p0to1length            : REM *                                      *
 1450 ELSE                                      : REM * SORT THE 4 SIDES OF THE RHOMBOID     *
 1460 longesthorizontal%=p2to3length            : REM * TRANSPOSED SHAPE AND PLACE THE VALUE *
 1470 ENDIF                                     : REM * INTO THE VARIABLE longestside%       *
 1480 IF p0to2length>p1to3length THEN           : REM *                                      *
 1490 longestvertical%=p0to2length              : REM ****************************************
 1500 ELSE
 1510 longestvertical%=p1to3length
 1520 ENDIF
 1530 IF longestvertical%>longesthorizontal% THEN
 1540 longestside%=longestvertical%
 1550 ELSE
 1560 longestside%=longesthorizontal%
 1570 ENDIF
 1580 
 1590 
 1600 
 1610 spriteincx%=(spritesizex%*division%)DIVlongestside%     : REM *** CALCULATE THE STEP THROUGH THE ORIGIONAL SPRITE (X)   ***
 1620 spriteincy%=(spritesizey%*division%)DIVlongestside%     : REM *** CALCULATE THE STEP THROUGH THE ORIGIONAL SPRITE (Y)   ***
 1630 
 


2nd half of code in the next post!
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #10 on: Feb 17th, 2016, 7:48pm »

2nd half
Code:
 1640 p0to2incx%=(x2-x0)*division%DIVlongestside%             : REM *** CALCULATE THE STEP INN THE SIDE FROM NODES 0 TO 2 (X) ***
 1650 p0to2incy%=(y2-y0)*division%DIVlongestside%             : REM *** CALCULATE THE STEP INN THE SIDE FROM NODES 0 TO 2 (Y) ***
 1660 
 1670 p1to3incx%=(x3-x1)*division%DIVlongestside%             : REM *** CALCULATE THE STEP INN THE SIDE FROM NODES 1 TO 3 (X) ***
 1680 p1to3incy%=(y3-y1)*division%DIVlongestside%             : REM *** CALCULATE THE STEP INN THE SIDE FROM NODES 1 TO 3 (Y) ***
 1690 
 1700 p0to2fpx%=0                                             : REM *** SET THE ORIGIN OF NODE 0 TO 0,0 (SIDE N0 TO N2)       ***
 1710 p0to2fpy%=0
 1720 
 1730 p1to3fpx%=(x1-x0)*division%                             : REM *** SET THE START POINT OF THE SIDE N1 TO N3 IN RELATION  ***
 1740 p1to3fpy%=(y1-y0)*division%                             : REM *** TO N0                                                 ***
 1750 
 1760 REPEAT
 1770 
 1780 linefpx%=p0to2fpx%                                      : REM *** SET THE START POINT OF THE LINE TO BE PRINTED BETWEEN ***
 1790 linefpy%=p0to2fpy%                                      : REM *** LINES N0,N2 AND N1,N3                                 ***
 1800 
 1810 contspritepointerx%=0                                   : REM *** RESET THE CONTINUOUS POINTER FOR THE SPRITE           ***
 1820 spritepointerx%=0                                       : REM *** RESET THE SPRITE POINTER IN THE X PLANE               ***
 1830 
 1840 lineincx%=(p1to3fpx%-p0to2fpx%)/longestside%            : REM *** CALCULATE THE STEPS BETWEEN LINES N0,N2 TO N1,N3 (X)  ***
 1850 lineincy%=(p1to3fpy%-p0to2fpy%)/longestside%            : REM *** CALCULATE THE STEPS BETWEEN LINES N0,N2 TO N1,N3 (Y)  ***
 1860 
 1870 
 1880 REPEAT
 1890 
 1900 GCOL 0,sprite(spritepointerx%,spritepointery%)                            : REM *** RETRIEVE COLOUR OF DOT TO BE DRAWN  ***
 1910 MOVE x0+((linefpx%*scale)DIVdivision%),y0+((linefpy%*scale)DIVdivision%)  : REM *** MOVE TO DRAW POINT                  ***
 1920 DRAW x0+((linefpx%*scale)DIVdivision%),y0+((linefpy%*scale)DIVdivision%)  : REM *** DRAW DOT                            ***
 1930 
 1940 linefpx%+=lineincx%                                     : REM *** INCREASE(STEP) THE POSITION OF THE LINE BETWEEN N0,N2 ***
 1950 linefpy%+=lineincy%                                     : REM *** AND N1,N3 READY FOR THE PLOTTING OF THE NEXT DOT      ***
 1960 
 1970 contspritepointerx%+=spriteincx%                        : REM *** INCREASE CONTINUOUS POINTER (X)                       ***
 1980 spritepointerx%=contspritepointerx%DIVdivision%         : REM *** CALCULATE NEW POINTER POSITION IN ORIGIONAL SPRITE (X)***
 1990 
 2000 UNTIL spritepointerx%>=spritesizex%               : REM *** HAS THE SPRITE POINTER EXCEEDED THE SIZE OF THE SPRITE (X)  ***
 2010 
 2020 p0to2fpx%+=p0to2incx%                             : REM *** INCREASE(STEP) THE LINE N0,N2 FOR THE NEXT PRINTED LINE (X) ***
 2030 p0to2fpy%+=p0to2incy%                             : REM *** INCREASE(STEP) THE LINE N0,N2 FOR THE NEXT PRINTED LINE (Y) ***
 2040 
 2050 p1to3fpx%+=p1to3incx%                             : REM *** INCREASE(STEP) THE LINE N1,N3 FOR THE NEXT PRINTED LINE (X) ***
 2060 p1to3fpy%+=p1to3incy%                             : REM *** INCREASE(STEP) THE LINE N1,N3 FOR THE NEXT PRINTED LINE (Y) ***
 2070 
 2080 contspritepointery%+=spriteincy%                  : REM *** INCREASE CONTINUOUS POINTER (Y)                             ***
 2090 spritepointery%=contspritepointery%DIVdivision%   : REM *** CALCULATE NEW POINTER POSITION IN ORIGIONAL SPRITE (X)      ***
 2100 
 2110 UNTIL spritepointery%=>spritesizey%               : REM *** HAS THE SPRITE POINTER EXCEEDED THE SIZE OF THE SPRITE (Y)  ***
 2120 
 2130 ENDPROC
 


Hope its annotated enough

Enjoy
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: 3D Gaming Project
« Reply #11 on: Feb 18th, 2016, 08:09am »

Hi Ric,

That seems to work nicely, if quite slowly in BASIC - not surprisingly! I'll be interested to see if you can make it fly in assembler.

Of course there are much quicker ways to do this for a chessboard, but I presume it's just a convenient image to analyse, and the ultimate goal would be an image, so you can't just draw triangles.

With regard to your query about the VDU 23 line - what doesn't work? It generates a black square instead of A. You are using it to clear the bit of screen where you are putting your coordinate requests? Wouldn't RECTANGLE FILL be easier?

Best wishes,

D
User IP Logged

Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #12 on: Feb 27th, 2016, 5:16pm »

Evening D and others
Just a quck one for Saturday night.

You were right D, the chess board was just a fancy block of colour to transpose and the goal is a coloured image.

Here is the assembler version, and pretty fast it is too. Code:
      VDU 23,22,1346;674;16,16,16,0
      HIMEM=(LOMEM+500000000) AND -4

      DIM code% NOTEND AND 2047, code% 6143
      DIM data% 2048
      DIM temp% 2048
      DIM sprite% 1368640
      DIM count% 3
      FOR I% = 0 TO 2 STEP 2
  
        P% = code%
  
        [
  
        OPT I%
  
        .starttranspose
  
        mov   eax,         0                 ;    }
        mov   ebx,         0                 ;    } Clear registers
        mov   ecx,         0                 ;    }
        mov   edx,         0                 ;    }
        mov   DWORD        [data%+116],    0 ;    }
        mov   DWORD        [data%+120],    0 ;    }
        mov   DWORD        [data%+124],    0 ;    }
        mov   DWORD        [data%+128],    0 ;    }
  
  
  
        mov   eax,         [data%+8]         ;  }
        sub   eax,         [data%]           ;  } Load Node 1 x in to eax,
        mov   ebx,         eax               ;  } subtract Node 0 x
        mul   ebx                            ;  } Put eax in to ebx and miltply.
        mov   ecx,         eax               ;  } (square eax) And store in ecx.
        mov   eax,         [data%+12]        ;    }
        sub   eax,         [data%+4]         ;    } Load Node 1 y in to eax
        mov   ebx,         eax               ;    } subtract Node 0 y
        mul   ebx                            ;    } Put eax in to ebx and multiply.
        add   eax,         ecx               ;    } (square) And add to ecx.
        mov   ebx,         16384             ;  }
        mul   ebx                            ;  } Multiply ecx by 16384
        mov   [temp%],     eax               ;  } and place result in [temp]
        fild  DWORD [temp%]                  ;    }
        fsqrt                                ;    } Find squareroot of [temp]
        fistp DWORD [temp%]                  ;    }
        mov   eax,         [temp%]           ;  } Divide the root by 128 to
        mov   ebx,         128               ;  } convert the result to the
        mov   edx,         0                 ;  } correct factor.
        div   ebx                            ;  }
        mov   [data%+32],  eax               ;    } Store result in [p0to1l]
  
  
        mov   eax,         [data%+16]        ;
        sub   eax,         [data%]           ;
        mov   ebx,         eax               ;
        mul   ebx                            ;
        mov   ecx,         eax               ;   Find length between
        mov   eax,         [data%+20]        ;   Nodes 2 and 0
        sub   eax,         [data%+4]         ;
        mov   ebx,         eax               ;
        mul   ebx                            ;
        add   eax,         ecx               ;
        mov   ebx,         16384             ;
        mul   ebx                            ;
        mov   [temp%],     eax               ;
        fild  DWORD [temp%]                  ;
        fsqrt                                ;
        fistp DWORD [temp%]                  ;
        mov   eax,         [temp%]           ;
        mov   ebx,         128               ;
        mov   edx,         0                 ;
        div   ebx                            ;
        mov   [data%+36],  eax               ;
  
  
        mov   eax,         [data%+24]        ;
        sub   eax,         [data%+8]         ;
        mov   ebx,         eax               ;
        mul   ebx                            ;
        mov   ecx,         eax               ;   Find length between
        mov   eax,         [data%+28]        ;   Nodes 3 and 1
        sub   eax,         [data%+12]        ;
        mov   ebx,         eax               ;
        mul   ebx                            ;
        add   eax,         ecx               ;
        mov   ebx,         16384             ;
        mul   ebx                            ;
        mov   [temp%],     eax               ;
        fild  DWORD [temp%]                  ;
        fsqrt                                ;
        fistp DWORD [temp%]                  ;
        mov   eax,         [temp%]           ;
        mov   ebx,         128               ;
        mov   edx,         0                 ;
        div   ebx                            ;
        mov   [data%+40],  eax               ;
  
  
        mov   eax,         [data%+24]        ;
        sub   eax,         [data%+16]        ;
        mov   ebx,         eax               ;
        mul   ebx                            ;
        mov   ecx,         eax               ;   Find length between
        mov   eax,         [data%+28]        ;   Nodes 3 and 2
        sub   eax,         [data%+20]        ;
        mov   ebx,         eax               ;
        mul   ebx                            ;
        add   eax,         ecx               ;
        mov   ebx,         16384             ;
        mul   ebx                            ;
        mov   [temp%],     eax               ;
        fild  DWORD [temp%]                  ;
        fsqrt                                ;
        fistp DWORD [temp%]                  ;
        mov   eax,         [temp%]           ;
        mov   ebx,         128               ;
        mov   edx,         0                 ;
        div   ebx                            ;
        mov   [data%+44],  eax               ;
  
  
        mov   eax,         [data%+44]        ;
        cmp   [data%+32],  eax               ;
        jae   higherh                        ;
        mov   [data%+48],  eax               ;  Load longest
        jmp   passa                          ;  horizontal side
        .higherh                             ;  in to the register
        mov   eax,         [data%+32]        ;  [longesthorizontal]
        mov   [data%+48],  eax               ;
  
        .passa
        mov   eax,         [data%+40]        ;
        cmp   [data%+36],  eax               ;
        jae   higherv                        ;
        mov   [data%+52],  eax               ;  Load longest
        jmp   passb                          ;  vertical side
        .higherv                             ;  in to the register
        mov   eax,         [data%+36]        ;  [longestvertical]
        mov   [data%+52],  eax               ;
  
        .passb
        mov   eax,         [data%+52]        ;
        cmp   [data%+48],  eax               ;
        jae   highers                        ;  Load longest
        jmp   passc                          ;  side
        .highers                             ;  in to the register
        mov   eax,         [data%+48]        ;  [longestside]
        .passc                               ;
        sal   eax,         6                 ;
        mov   ebx,         43
        mov   edx,         0
        div   ebx
        mov   [data%+56],  eax               ;
  
        mov   eax,         16384             ;
        mov   ebx,         [data%+60]        ;  Calculate the sprite
        mul   ebx                            ;  step increase in x and
        mov   ebx,         [data%+56]        ;  store result in [data%+68]
        div   ebx                            ;
        mov   [data%+68],  eax               ;
  
        mov   eax,         16384             ;
        mov   ebx,         [data%+64]        ;  Calculate the sprite
        mul   ebx                            ;  step increase in y and
        mov   ebx,         [data%+56]        ;  store result in [data%+72]
        div   ebx                            ;
        mov   [data%+72],  eax               ;
  
        mov   eax,         [data%+16]        ;
        sub   eax,         [data%]           ;
        mov   ebx,         16384             ;  Calculate step from
        mul   ebx                            ;  n0 to n2 in x and store
        mov   ebx,         [data%+56]        ;  in [data%+76]
        cmp   eax,         0                 ;
        jl    p0to2xnegdiv                   ;
        mov   edx,         0                 ;
        div   ebx                            ;
        jmp   p0to2xnegpass                  ;
        .p0to2xnegdiv                        ;
        neg   eax                            ;  }
        mov   edx,         0                 ;  } Produce a negative
        div   ebx                            ;  } division
        neg   eax                            ;  }
        .p0to2xnegpass                       ;
        mov   [data%+76],  eax               ;
  
  
        mov   eax,         [data%+20]        ;
        sub   eax,         [data%+4]         ;
        mov   ebx,         16384             ;  Calculate step from
        mul   ebx                            ;  n0 to n2 in y and store
        mov   ebx,         [data%+56]        ;  in [data%+80]
        cmp   eax,         0                 ;
        jl    p0to2ynegdiv                   ;
        mov   edx,         0                 ;
        div   ebx                            ;
        jmp   p0to2ynegpass                  ;
        .p0to2ynegdiv                        ;
        neg   eax                            ;  }
        mov   edx,         0                 ;  } Produce a negative
        div   ebx                            ;  } division
        neg   eax                            ;  }
        .p0to2ynegpass                       ;
        mov   [data%+80],  eax               ;
  
        

As is now usual the post is in two halves so will need to do some careful pasting.

Ric
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #13 on: Feb 27th, 2016, 5:19pm »

Code:
        mov   eax,         [data%+24]        ;
        sub   eax,         [data%+8]         ;
        mov   ebx,         16384             ;  Calculate step from
        mul   ebx                            ;  n1 to n3 in x and store
        mov   ebx,         [data%+56]        ;  in [data%+84]
        cmp   eax,         0                 ;
        jl    p1to3xnegdiv                   ;
        mov   edx,         0                 ;
        div   ebx                            ;
        jmp   p1to3xnegpass                  ;
        .p1to3xnegdiv                        ;
        neg   eax                            ;  }
        mov   edx,         0                 ;  } Produce a negative
        div   ebx                            ;  } division
        neg   eax                            ;  }
        .p1to3xnegpass                       ;
        mov   [data%+84],  eax               ;
  
        mov   eax,         [data%+28]        ;
        sub   eax,         [data%+12]        ;
        mov   ebx,         16384             ;  Calculate step from
        mul   ebx                            ;  n1 to n3 in y and store
        mov   ebx,         [data%+56]        ;  in [data%+88]
        cmp   eax,         0                 ;
        jl    p1to3ynegdiv                   ;
        mov   edx,         0                 ;
        div   ebx                            ;
        jmp   p1to3ynegpass                  ;
        .p1to3ynegdiv                        ;
        neg   eax                            ;  }
        mov   edx,         0                 ;  } Produce a negative
        div   ebx                            ;  } division
        neg   eax                            ;  }
        .p1to3ynegpass                       ;
        mov   [data%+88],  eax               ;
  
        mov   DWORD        [data%+92],  0    ;  Set start point for p0to2
        mov   DWORD        [data%+96],  0    ;  x and y
  
        mov   eax,         [data%+8]         ;
        sub   eax,         [data%]           ;  Set start point for p1to3
        mov   ebx,         16384             ;  in x
        mul   ebx                            ;
        mov   [data%+100], eax               ;
  
        mov   eax,         [data%+12]        ;
        sub   eax,         [data%+4]         ;  Set start point for p1to3
        mov   ebx,         16384             ;  in y
        mul   ebx                            ;
        mov   [data%+104], eax               ;
  
        .startmainloopy
  
        mov   eax,         [data%+92]        ;  Set linefpx to p0to2fpx
        mov   [data%+108], eax               ;
  
        mov   eax,         [data%+96]        ;  Set linefpy to p0to2fpy
        mov   [data%+112], eax               ;
  
        mov   DWORD        [data%+116], 0    ;  Initialise contspritepointerx
        mov   DWORD        [data%+124], 0    ;  Initialise spritepointerx
  
        mov   eax,         [data%+100]       ;
        sub   eax,         [data%+92]        ;  Calculate lineincx and
        mov   ebx,         [data%+56]        ;  store in [data%+132]
        cmp   eax,         0                 ;
        jl    lixnegdiv                      ;
        mov   edx,         0                 ;
        div   ebx                            ;
        jmp   lixnegpass                     ;
        .lixnegdiv                           ;
        neg   eax                            ;  }
        mov   edx,         0                 ;  } Produce a negative
        div   ebx                            ;  } division
        neg   eax                            ;  }
        .lixnegpass                          ;
        mov   [data%+132],  eax              ;
  
        mov   eax,         [data%+104]       ;
        sub   eax,         [data%+96]        ;  Calculate lineincy and
        mov   ebx,         [data%+56]        ;  store in [data%+136]
        cmp   eax,         0                 ;
        jl    liynegdiv                      ;
        mov   edx,         0                 ;
        div   ebx                            ;
        jmp   liynegpass                     ;
        .liynegdiv                           ;
        neg   eax                            ;  }
        mov   edx,         0                 ;  } Produce a negative
        div   ebx                            ;  } division
        neg   eax                            ;  }
        .liynegpass                          ;
        mov   [data%+136],  eax              ;
  
        .startmainloopx
  
        mov   ecx,         0
        mov   edx,         0
        mov   eax,         [data%+108]       ;
        mov   ebx,         16384             ;
        cmp   eax,         0                 ;  Calculate x displacement
        jl    cxdnegdiv                      ;
        mov   edx,         0                 ;
        div   ebx                            ;
        jmp   cxdnegpass                     ;
        .cxdnegdiv                           ;
        neg   eax                            ;  }
        mov   edx,         0                 ;  } Produce a negative
        div   ebx                            ;  } division
        neg   eax                            ;  }
        .cxdnegpass                          ;
        add   eax,         [data%]           ;  for next pixel
        ;  INSERT CHECKS HERE AGAINST X DISPLACEMENT OUTSIDE SCREENSIZE
        ;  AND JUMP TO .pixelpass
        mov   ebx,         4                 ;
        mul   ebx                            ;
        mov   ecx,         eax               ;
  
        mov   eax,         [data%+112]       ;
        mov   ebx,         16384             ;
        cmp   eax,         0                 ;  Calculate y displacement
        jl    cydnegdiv                      ;
        mov   edx,         0                 ;
        div   ebx                            ;
        jmp   cydnegpass                     ;
        .cydnegdiv                           ;
        neg   eax                            ;  }
        mov   edx,         0                 ;  } Produce a negative
        div   ebx                            ;  } division
        neg   eax                            ;  }
        .cydnegpass                          ;
        add   eax,         [data%+4]         ;  for next pixel
        ;  INSERT CHECKS HERE AGAINST Y DISPLACEMENT OUTSIDE SCREENSIZE
        ;  AND JUMP TO .pixelpass
        mov   ebx,         5384              ;
        mul   ebx                            ;
  
        add   ecx,         eax               ;  Sum x and y to create offset for bits%
        push  ecx
  
        mov   edx,         [data%+124]       ;  Load edx with spritepointerx
        sal   edx,         2                 ;  Multiply by 4
        push  edx                            ;
        mov   eax,         [data%+128]       ;  Load eax with spritepointery
        mov   ebx,         [data%+60]        ;  Multiply by spritesizex
        mul   ebx                            ;
        sal   eax,         2                 ;  Multiply by 4 (eax)
        pop   edx                            ;
  
        add   eax,         edx               ;  Add edx to eax to create offset for sprite%
  
        pop   ecx                            ;
        mov   edx,         [^bits%]          ;  Create physical position of next
        add   edx,         ecx               ;  pixel to be printed
  
        mov   ebx,         sprite%           ;  Get colour of pixel to be printed
        add   ebx,         eax               ;  from array sprite%
  
        mov   eax,         [ebx]             ;  Print pixel
        mov   [edx],       eax               ;
  
        .pixelpass
  
        mov   eax,         [data%+132]       ;  Increase linefpx by lineincx
        add   [data%+108], eax               ;
  
        mov   eax,         [data%+136]       ;  Increase linefpy by lineincy
        add   [data%+112], eax               ;
  
        mov   eax,         [data%+68]        ;  Increase contspritepointerx by
        add   [data%+116], eax               ;  spriteincx
  
        mov   DWORD        [temp%],    16384 ;
        fild  DWORD        [data%+116]       ;
        fidiv DWORD        [temp%]           ;  Calculate new value for spritepointerx
        fistp DWORD        [data%+124]       ;  and place back in [data%+124]
  
        mov   eax,         [data%+124]
        cmp   eax,         [data%+60]
  
        jb    NEAR         startmainloopx
  
        mov   eax,         [data%+76]        ;  Increment p0to2fpx by p0to2incx
        add   [data%+92],  eax               ;
  
        mov   eax,         [data%+80]        ;  Increment p0to2fpy by p0to2incy
        add   [data%+96],  eax               ;
  
        mov   eax,         [data%+84]        ;  Increment p1to3fpx by p1to3incx
        add   [data%+100], eax               ;
  
        mov   eax,         [data%+88]        ;  Increment p1to3fpy by p1to3incy
        add   [data%+104], eax               ;
  
        mov   eax,         [data%+72]        ;  Increment contspritepointery
        add   [data%+120], eax               ;  by spriteincy
  
        mov   ecx,          0
        mov   edx,          0
        mov   eax,         [data%+120]       ;
        mov   ebx,         16384             ;  Calculate new value of spritepointery
        div   ebx                            ;  and place back in [data%+128]
        mov   edx,         0                 ;
        mov   [data%+128], eax               ;
  
        mov   eax,         [data%+128]
        cmp   eax,         [data%+64]
        jb    NEAR         startmainloopy
  
        ret
  
        ]
  
      NEXT I%


      



ok, may be three posts!!!!!!!!!!
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: 3D Gaming Project
« Reply #14 on: Feb 27th, 2016, 5:26pm »

Post three!!

Code:
      DIM BITMAPINFOHEADER{Size%, Width%, Height%, Planes{l&,h&}, BitCount{l&,h&}, Compression%, SizeImage%, XPelsPerMeter%, YPelsPerMeter%, ClrUsed%, ClrImportant%}
      DIM bmi{Header{} = BITMAPINFOHEADER{}}
      bmi.Header.Size% = DIM(BITMAPINFOHEADER{})
      bmi.Header.Width% = 1346
      bmi.Header.Height% = 674
      bmi.Header.Planes.l& = 1
      bmi.Header.BitCount.l& = 32

      SYS "CreateDIBSection", @memhdc%, bmi{}, 0, ^bits%, 0, 0 TO hbitmap%
      IF hbitmap%=0 ERROR 100, "Couldn't create DIBSection"

      SYS "SelectObject", @memhdc%, hbitmap% TO oldhbm%
      SYS "DeleteObject", oldhbm%
      SYS "InvalidateRect", @hwnd%, 0, 0


      FOR x=0 TO 7
        FOR y=0 TO 7
          IF (x MOD 2=1 AND y MOD 2=1) OR (x MOD 2=0 AND y MOD 2=0) THEN
            FOR xloop=0 TO 31
              FOR yloop=0 TO 31
                ?(sprite%+(((x*128)+(xloop*4))+((((y*32)+yloop)*1024))))=255
                ?(sprite%+(((x*128)+(xloop*4))+((((y*32)+yloop)*1024))+1))=0
                ?(sprite%+(((x*128)+(xloop*4))+((((y*32)+yloop)*1024))+2))=0
                ?(sprite%+(((x*128)+(xloop*4))+((((y*32)+yloop)*1024))+3))=0
              NEXT
            NEXT
          ELSE
            FOR xloop=0 TO 31
              FOR yloop=0 TO 31
                ?(sprite%+(((x*128)+(xloop*4))+((((y*32)+yloop)*1024))))=0
                ?(sprite%+(((x*128)+(xloop*4))+((((y*32)+yloop)*1024))+1))=255
                ?(sprite%+(((x*128)+(xloop*4))+((((y*32)+yloop)*1024))+2))=0
                ?(sprite%+(((x*128)+(xloop*4))+((((y*32)+yloop)*1024))+3))=0
              NEXT
            NEXT
          ENDIF
        NEXT
      NEXT

      REPEAT
        ?(data%+61)=1
        ?(data%+65)=1
        CLS
        SYS "InvalidateRect", @hwnd%, 0, 0
        PRINT"The origional tile being transfered is a chessboard, 256x256 pixels."
        PRINT"Choose the coordinates for nodes 0,1,2 and 3 and watch"
        PRINT""
        PRINT"Max distance between nodes is 350 point to point!!!!!!"
        PRINT""
        PRINT"Node order is       N2      N3"
        PRINT""
        PRINT""
        PRINT""
        PRINT"                    N0      N1"
  
        FOR loop=0 TO 3
          PRINTTAB(0,10+(loop*2))"Nx";loop
          INPUTTAB(4,10+(loop*2))"";nodex
          ?(data%+(loop*8))=nodex MOD 256
          ?(data%+(loop*8+1))=nodex DIV 256
          PRINTTAB(0,10+(loop*2)+1)"Ny";loop
          INPUTTAB(4,10+(loop*2)+1)"";nodey
          ?(data%+(loop*8+4))=nodey MOD 256
          ?(data%+(loop*8+5))=nodey DIV 256
        NEXT
        TIME=0
        CALL starttranspose
        SYS "InvalidateRect", @hwnd%, 0, 0
        PRINT "Time taken : ";TIME
        PRINTTAB(30,40)"Press any key to do it again"
        Key%=0
        *FX 15,1
        REPEAT
    
          Key%=INKEY(100)
    
        UNTIL Key%<>-1
  
      UNTIL FALSE











      REM   data      nodex0
      REM   data+4    nodey0
      REM   data+8    nodex1
      REM   data+12   nodey1
      REM   data+16   nodex2
      REM   data+20   nodey2
      REM   data+24   nodex3
      REM   data+28   nodey3
      REM   data+32   p0to1length
      REM   data+36   p0to2length
      REM   data+40   p1to3length
      REM   data+44   p2to3length
      REM   data+48   longesthorizontal
      REM   data+52   longestvertical
      REM   data+56   longestside
      REM   data+60   spritesizex
      REM   data+64   spritesizey
      REM   data+68   spriteincx
      REM   data+72   spriteincy
      REM   data+76   p0to2incx
      REM   data+80   p0to2incy
      REM   data+84   p1to3incx
      REM   data+88   p1to3incy
      REM   data+92   p0to2fpx
      REM   data+96   p0to2fpy
      REM   data+100  p1to3fpx
      REM   data+104  p1to3fpy
      REM   data+108  linefpx
      REM   data+112  linefpy
      REM   data+116  contspritepointerx
      REM   data+120  contspritepointery
      REM   data+124  spritepointerx
      REM   data+128  spritepointery
      REM   data+132  lineincx
      REM   data+136  lineincy
 


The sprite to be printed is in full 32bit colour and would benefit from a photo etc to really try it out. Does anyone know if you can openin#x a .bmp etc so I can easily import a picture?

Ric
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Pages: 1 2 3  ...  8 Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls