TGC Codebase Backup



Matrix to HeightMap by Squarch

28th Apr 2007 8:08
Summary

This fonction take in parameter a created matrix, that will be exported as a simple heightmap image.



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem fonction d'export en heightmap
function HeightMapExport(MatNum as integer, tilex as integer, tiley as integer, FileName as string)
   rem la tableau de valeur pour l'export des gris
   dim ColorsHeight(255) as integer
   for t=1 to 255
      ColorsHeight(t)= t
   next t
   Pos as integer
   Pos=0

   rem le memblock image
   make memblock 1, 12+(4*tilex*tiley)

      rem les en-têtes
      write memblock dword 1, 0, tilex
      write memblock dword 1, 4, tiley
      write memblock dword 1, 8, 32

      rem les 'datas' de l'image
      for t=1 to tilex
         for i=1 to tiley
            h = get matrix height(1, t, i)
            write memblock byte 1, 12+Pos, ColorsHeight(h):inc Pos:rem rouge
            write memblock byte 1, 12+Pos, ColorsHeight(h):inc Pos:rem vert
            write memblock byte 1, 12+Pos, ColorsHeight(h):inc Pos:rem bleu
            write memblock byte 1, 12+Pos, 100:inc Pos:rem opacité
         next i
      next t

   rem on creer l'image a partir du memblock
   make image from memblock 1,1
   save image FileName,1

   rem on efface les données creer pour l'export
   undim ColorsHeight(0)
   delete memblock 1
endfunction