BASIC

Author Topic: Auto-rounded 3D block landscapes  (Read 6115 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10709
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Auto-rounded 3D block landscapes
« Reply #15 on: 2012-Jan-08 »
My bilboards are reay X_OBJ.. objects. Here's the code to create them:

Code: GLBasic [Select]

// draw sprites after the camera was set
FUNCTION DrawBillboards%: id%, idtexture%, blockpix%, sprites[] AS Tsprite3D

        LOCAL tx, ty
        GETSPRITESIZE idtexture%, tx, ty
        LOCAL nperrow% = INTEGER(tx / blockpix)
        GetTextureSize(idtexture%, tx, ty)


        // texture size of a half pixel movement
        LOCAL offset = 0.50
        LOCAL halfpx_x = offset / tx
        LOCAL halfpx_y = offset / ty

        // scale factor to make a block 1 pixel smaller on texture than required
        // we want edge[0,0] be on center of pixel 0,0;
        // and edge[1,0] on center of pixel 15 (if blocksize=16)
        LOCAL txblockscale = (blockpix - 2.0*offset)/(1.0 * blockpix)
        LOCAL tyblockscale = (blockpix - 2.0*offset)/(1.0 * blockpix)

        // make tx/ty be the texture size of one block
        tx = blockpix / tx
        ty = blockpix / ty



LOCAL mat[]
        X_GETCAMERAMATRIX mat[]


//      X_SPOT_LT 0, 0, 0,0,0,  0,0,0, 0
        X_AUTONORMALS 1
        X_OBJSTART id%

        LOCAL h = 1.0, w = 0.5*h // size of this sprite
        // we need the "X" axis direction for the x-values of the sprite
        LOCAL dxx =mat[0], dxy=mat[4], dxz=mat[8] // dxy = 0.0 it camera-up is Y
        LOCAL upx =mat[1], upy=mat[5], upz=mat[9]


        LOCAL uw = tx * txblockscale // width of image to texture (15px for 16px blocks)
        LOCAL vh = ty * tyblockscale

        FOREACH spr IN sprites[]
                LOCAL deltau = MOD(spr.id%, nperrow)       // number of blocks to move
                LOCAL deltav = INTEGER(spr.id% / nperrow%) // nof blocks

                LOCAL u0 = halfpx_x + deltau * tx
                LOCAL v0 = halfpx_y + deltav * ty

                X_OBJADDVERTEX spr.x+w*dxx, spr.y-w*dxy+h, spr.z+w*dxz, u0+uw,v0   , 0xffffff
                X_OBJADDVERTEX spr.x+w*dxx, spr.y-w*dxy  , spr.z+w*dxz, u0+uw,v0+vh, 0xffffff
                X_OBJADDVERTEX spr.x-w*dxx, spr.y-w*dxy+h, spr.z-w*dxz, u0   ,v0   , 0xffffff
                X_OBJADDVERTEX spr.x-w*dxx, spr.y-w*dxy  , spr.z-w*dxz, u0   ,v0+vh, 0xffffff
                X_OBJNEWGROUP
        NEXT
        X_OBJEND

        X_MOVEMENT 0,0,0
        X_SCALING 1,1,1

        X_CULLMODE 1

        SMOOTHSHADING FALSE
        X_SETTEXTURE idtexture%, -1
        X_DRAWOBJ id%, 0
ENDFUNCTION
 


Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3366
  • Integrated Brain
    • View Profile
Re: Auto-rounded 3D block landscapes
« Reply #16 on: 2012-Jan-12 »
Thanks Gernnot  :nw: :nw: