Author Topic: 16 cubic cube  (Read 4271 times)

Offline Scott_AW

  • Mr. Polyvector
  • ***
  • Posts: 214
    • View Profile
    • SAW Game Design
16 cubic cube
« on: 2010-Mar-13 »
I've always had a thing for voxels, renewed when I found out about voxlap.  But I'm not about to mess with ray tracing math.

I posted for some recommendations on how to fix a issue I was having.  But I had a chance to read through it again and made it simpler and work.  So yay.

So now that I got it fixed up, here's the code.  I've got some more fun test I want to work on...

First here's a screen capture and a compiled exe.



Download cube16.zip

UPDATED 3/13/10
Now it will show a bunch of same model, with ripped FPS code showing you the frame rate.  I think I fixed the hole problem that I kept seeing.
Quote
// --------------------------------- //
// Project: Cube16
// Start: Thursday, March 04, 2010
// Author: Scott A. Williams
// IDE Version: 7.285
  //Object conversion
  DIM cbox[18][18][18]
// Init =====================================================================================||

// Main =====================================================================================||

// Test =====================================================================================||
  GLOBAL cnt, rot=0, final = FALSE

  //Process
  GOSUB make_obj_thinwall
  create_obj(1)
  //X_LOADOBJ "dump.ddd", 1
  GOSUB ShowFPS
  PRINT "done",300,100
  SHOWSCREEN
  KEYWAIT

  X_AUTONORMALS 0
WHILE final = FALSE
  //Display
  X_MAKE3D 1, 128, 45
  X_CAMERA 9-rot,8,48+rot, 9,8,0
  X_CULLMODE 0
  //X_SPOT_LT 0, RGB(255,255,255), 8,16,32, 1,-1,-1, 90
  //X_SPOT_LT 1, RGB(255,255,255), 8,16,-16, -1,-1,-1, 90
 
  IF rot < 96
    INC rot, 1
  ELSE
    rot = 0
  ENDIF
 
  FOR cnt = 0 TO 5
    X_MOVEMENT 16,0,-8*cnt; X_DRAWOBJ 1,0
    X_MOVEMENT 0,-16,-8*cnt; X_DRAWOBJ 1,0
    X_MOVEMENT 0,16,-8*cnt; X_DRAWOBJ 1,0
    X_MOVEMENT -16,0,-8*cnt; X_DRAWOBJ 1,0
  NEXT
  GOSUB ShowFPS
  SHOWSCREEN
  IF KEY(1) THEN final = TRUE
WEND
  END
// Subs =====================================================================================||
SUB make_obj_thinwall:
  // Create 1 thick 16 squared wall
  LOCAL cx, cy, cz
  FOR cy = 0 TO 17
    FOR cx = 0 TO 17
      FOR cz = 0 TO 17
        cbox[cx][cy][cz] = 0
      NEXT
    NEXT
  NEXT
  FOR cy = 1 TO 16
    FOR cx = 1 TO 16
      FOR cz = 1 TO 7
        cbox[cx][cy][cz] = 1//RND(1)
      NEXT
    NEXT
  NEXT
ENDSUB

FUNCTION create_obj: index
  // Scan through object data, create model
  LOCAL cx, cy, cz
  LOCAL fn,fs,fe,fw,fu,fd,fc
  LOCAL first = 0
  LOCAL line = 0, tic = 0
  X_OBJSTART index
  FOR cy = 1 TO 16
    FOR cx = 1 TO 16
      FOR cz = 1 TO 16
        IF cbox[cx][cy][cz] > 0
          fn = cbox[cx][cy][cz-1]
          fs = cbox[cx][cy][cz+1]
          fw = cbox[cx+1][cy][cz]
          fe = cbox[cx-1][cy][cz]
          fd = cbox[cx][cy-1][cz]
          fu = cbox[cx][cy+1][cz]
          fc = cbox[cx][cy][cz]
          make_cube(cx,cy,cz,fn,fs,fe,fw,fu,fd,fc)
          PRINT "posxyz:" + cx+cy+cz + " facekey:"+fn+fs+fe+fw+fu+fd+" color:"+fc,0,8*line
          INC line, 1
        ENDIF
        PRINT "sector:"+tic+" value:"+cbox[cx][cy][cz],400,8*line
        INC tic, 1
      NEXT
    NEXT
  NEXT
  X_OBJEND
  X_SAVEOBJ "dump.ddd", index

ENDFUNCTION

FUNCTION make_cube: x,y,z,n,s,w,e,u,d,col
  color = RGB((y*4)+64,(y*4)+64,(z*4)+64)
  IF n = 0
    X_OBJNEWGROUP
    X_OBJADDVERTEX x+1,y,z,1,0,color
    X_OBJADDVERTEX x,y,z,0,0,color
    X_OBJADDVERTEX x+1,y+1,z,1,1,color
    X_OBJADDVERTEX x,y+1,z,0,1,color
  ENDIF
  IF s = 0
    X_OBJNEWGROUP
    X_OBJADDVERTEX x+1,y+1,z+1,1,1,color
    X_OBJADDVERTEX x+1,y,z+1,1,0,color
    X_OBJADDVERTEX x,y+1,z+1,0,1,color
    X_OBJADDVERTEX x,y,z+1,0,0,color
  ENDIF
  IF e = 0
    X_OBJNEWGROUP
    X_OBJADDVERTEX x+1,y+1,z+1,1,1,color
    X_OBJADDVERTEX x+1,y+1,z,1,0,color
    X_OBJADDVERTEX x+1,y,z+1,0,1,color
    X_OBJADDVERTEX x+1,y,z,0,0,color
  ENDIF
  IF w = 0
    X_OBJNEWGROUP
    X_OBJADDVERTEX x,y+1,z,1,0,color
    X_OBJADDVERTEX x,y,z,0,0,color
    X_OBJADDVERTEX x,y+1,z+1,1,1,color
    X_OBJADDVERTEX x,y,z+1,0,1,color
  ENDIF
  IF u = 0
    X_OBJNEWGROUP
    X_OBJADDVERTEX x,y+1,z,0,0,color
    X_OBJADDVERTEX x,y+1,z+1,0,1,color
    X_OBJADDVERTEX x+1,y+1,z,1,0,color
    X_OBJADDVERTEX x+1,y+1,z+1,1,1,color
  ENDIF
  IF d = 0
    X_OBJNEWGROUP
    X_OBJADDVERTEX x,y,z+1,0,1,color
    X_OBJADDVERTEX x+1,y,z+1,1,1,color
    X_OBJADDVERTEX x,y,z,0,0,color
    X_OBJADDVERTEX x+1,y,z,1,0,color
  ENDIF
ENDFUNCTION

// ------------------------------------------------------------- //
// -=#  SHOWFPS  #=-
// ------------------------------------------------------------- //
SUB ShowFPS:
   X_MAKE2D
   dtime=GETTIMER()
   fps = ((1000/dtime)+fps)/2
   delay=delay+dtime
   IF delay>1000 // 1/2 sec
      delay=0
      fps_draw=fps
   ENDIF
   PRINT "FPS: "+fps_draw, 0 ,0
ENDSUB // SHOWFPS

« Last Edit: 2010-Mar-14 by Scott_AW »
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1545
    • View Profile
Re: 16 cubic cube
« Reply #1 on: 2010-Mar-13 »
This is interesting and I'll would like to look further into this soon. Voxels are new to me since watching a current controversial video regarding non-polygon 3D, which some are saying is that or similar.

Unlimited Detail Technology
http://www.youtube.com/watch?v=eXJUGLiZkV0

Offline Scott_AW

  • Mr. Polyvector
  • ***
  • Posts: 214
    • View Profile
    • SAW Game Design
Re: 16 cubic cube
« Reply #2 on: 2010-Mar-14 »
There is already a few interesting works with voxel style graphics, but usually emulated.  Theres a Voxel/ISO Metroid out there and a somewhat questionable developement called Voxelstein.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Offline doimus

  • Dr. Type
  • ****
  • Posts: 284
    • View Profile
Re: 16 cubic cube
« Reply #3 on: 2010-Mar-14 »
Voxels are basically 3D pixels, having the x,y and z coordinates.
Back in early 90s, before hardware-accelerated 3D, voxel games were all the rage. Company called Novalogic was at the forefront of this. They've released number of military-themed voxel-based games. I remember being the coolest guy in class in '93, having the computer that could run Comanche Maximum Overkill.
That particular game had unbelievable graphics for its time, looked better and required lot less resources than polygon-based games of that time.
That all changed when hardware acceleration appeared, and by today's standards, Novalogic games are rather crappy.

http://www.mobygames.com/game-group/games-with-voxel-graphics/offset,25/so,1d/

Offline Scott_AW

  • Mr. Polyvector
  • ***
  • Posts: 214
    • View Profile
    • SAW Game Design
Re: 16 cubic cube
« Reply #4 on: 2010-Mar-14 »
And there was also Outcast which was pretty impressive at its time.  I wonder how hard it would be to get the Voxlap code to work in GLBasic's inline functions.  http://advsys.net/ken/voxlap.htm you can find the source code here.

A new demo,  think I fixed some more bugs and such.  No code with this though, I think I'll wait until its finished.  It won't be the actual game engine, since the game will just use the created models, won't need to build objects.  So this will evolve into a simple object creation tool.  The scene in this demo was create by using a strip of images that consisted of the slices to create a 3d sprite.  This is pretty much how voxels work, except being simulated by polygons and such.

http://host-a.net/scott_aw/Cube16_test3.zip
« Last Edit: 2010-Mar-17 by Scott_AW »
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Hatonastick

  • Guest
Re: 16 cubic cube
« Reply #5 on: 2010-Mar-21 »
This is interesting and I'll would like to look further into this soon. Voxels are new to me since watching a current controversial video regarding non-polygon 3D, which some are saying is that or similar.

Unlimited Detail Technology
http://www.youtube.com/watch?v=eXJUGLiZkV0

Interesting video.  I'm a little skeptical, but so are a lot of other people it seems.  If it's for real and really does work as well as they claim, a decent set of chips created and shoved on a card to speed up the software process could make for some pretty powerful graphics I'm guessing.  Problem is the industry as a whole is 'addicted' to polygons and the likelihood they are just going to swap (spending millions more than they have on the tech that they already use) to something brand new and totally out there is pretty minimal.  It's something that would have to change gradually I'm guessing, if indeed it ever takes off.

Offline Scott_AW

  • Mr. Polyvector
  • ***
  • Posts: 214
    • View Profile
    • SAW Game Design
Re: 16 cubic cube
« Reply #6 on: 2010-Mar-25 »
Its like trying to get people who use pens into using pencils.  Even though you can produce more detail with a pencil drawing than a pen.  That would make the video card the factor of the ink's quality while the pencil lead would be like raw cpu power.

You really just need a math chip, not a graphics chip to handle voxels.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1792
    • View Profile
    • Homepage
Re: 16 cubic cube
« Reply #7 on: 2010-Mar-25 »
I have troubles seeing the grafics companies shooting themselves in the foot. Besides, everyone has a grapics card already, any other graphics-solution needs to build on these cards to be successful.