CodeBase - Matrix

Return to the CodeBase listing

Category: Complete Applications

Version: 1.0

0
0

Information

Uploaded: 28th Feb 2005 11:34

Modified: 1st Jan 1970 01:00

Author:  Anonymous Coder

Summary

` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com remstart ------------------------------------------------------------------- program: Function to build + normalise matrix from height map ------------------------------------------------------------------- written by: James Barker [FROGGIE!] date: 10/02/05 ------------------------------------------------------------------- remend ` height map - Height map must be in BMP format. Width and height must be divisible by 2 ` function parametres needed: ` filename of bitmap, matrix number, matrix size x, matrix size z, maximum height of the matrix ` MATRIX MUST NOT EXIST! FUNCTION map_matrix(file_name$, mtx_number, mtx_x, mtx_z, mtx_max_height) ` load the file LOAD BITMAP file_name$,1 ` set a couple of variables map_x = BITMAP WIDTH(1) map_y = BITMAP HEIGHT(1) DEC map_x DEC map_y ` build the matrix MAKE MATRIX mtx_number,mtx_x,mtx_z,map_x,map_y ` set the heights of the matrix according to bitmap ` black (0,0,0) = height of 0 ` white (255,255,255) = maximum height FOR z = 0 TO map_y FOR x = 0 TO map_x col_value AS DWORD SET CURRENT BITMAP 1 col_value = (RGBR(POINT(x,z)))*255 map_percent = (col_value/255)*100 mtx_height# = (mtx_max_height/100)*map_percent SET MATRIX HEIGHT mtx_number,x,z,(mtx_height#/255) NEXT x NEXT z ` normalise the matrix FOR z_normal = 1 To map_y FOR x_normal = 1 To map_x height_8# = GET MATRIX HEIGHT(mtx_number,x_normal,z_normal-1) height_4# = GET MATRIX HEIGHT(mtx_number,x_normal-1,z_normal) height_0# = GET MATRIX HEIGHT(mtx_number,x_normal,z_normal) height_2# = GET MATRIX HEIGHT(mtx_number,x_normal,z_normal) x1# = (x_normal-1)*25.0 : y1# = height_0# x2# = (x_normal+0)*25.0 : y2# = height_4# dx# = x2#-x1# : dy# = y2#-y1# ax# = ATANFULL(dx#,dy#) ax# = WRAPVALUE(90-ax#) z1# = (z_normal-1)*25.0 : y1# = height_2# z2# = (z_normal+0)*25.0 : y2# = height_8# dz# = z2#-z1# : dy# = y2#-y1# az# = ATANFULL(dz#,dy#) az# = WRAPVALUE(90-az#) nx# = SIN(ax#) : ny# = COS(ax#) : nz#=SIN(az#) SET MATRIX NORMAL mtx_number,x_normal,z_normal,nx#,ny#,nz# NEXT x_normal NEXT z_normal ` refresh DELETE BITMAP 1 SET CURRENT BITMAP 0 UPDATE MATRIX mtx_number ENDFUNCTION

Full Description

` This code was downloaded from The Game Creators<br /> ` It is reproduced here with full permission<br /> ` http://www.thegamecreators.com<br /> <br /> remstart<br /> -------------------------------------------------------------------<br /> program: Function to build + normalise matrix from height map<br /> -------------------------------------------------------------------<br /> written by: James Barker [FROGGIE!]<br /> date: 10/02/05<br /> -------------------------------------------------------------------<br /> remend<br /> <br /> ` height map - Height map must be in BMP format. Width and height must be divisible by 2<br /> <br /> ` function parametres needed:<br /> ` filename of bitmap, matrix number, matrix size x, matrix size z, maximum height of the matrix<br /> ` MATRIX MUST NOT EXIST!<br /> FUNCTION map_matrix(file_name$, mtx_number, mtx_x, mtx_z, mtx_max_height)<br /> <br /> ` load the file<br /> LOAD BITMAP file_name$,1<br /> <br /> ` set a couple of variables<br /> map_x = BITMAP WIDTH(1)<br /> map_y = BITMAP HEIGHT(1)<br /> <br /> DEC map_x<br /> DEC map_y<br /> <br /> ` build the matrix<br /> MAKE MATRIX mtx_number,mtx_x,mtx_z,map_x,map_y<br /> <br /> ` set the heights of the matrix according to bitmap<br /> ` black (0,0,0) = height of 0<br /> ` white (255,255,255) = maximum height<br /> FOR z = 0 TO map_y<br /> FOR x = 0 TO map_x<br /> <br /> col_value AS DWORD<br /> SET CURRENT BITMAP 1<br /> col_value = (RGBR(POINT(x,z)))*255<br /> <br /> map_percent = (col_value/255)*100<br /> mtx_height# = (mtx_max_height/100)*map_percent<br /> <br /> SET MATRIX HEIGHT mtx_number,x,z,(mtx_height#/255)<br /> <br /> NEXT x<br /> NEXT z<br /> <br /> ` normalise the matrix<br /> FOR z_normal = 1 To map_y<br /> FOR x_normal = 1 To map_x<br /> <br /> height_8# = GET MATRIX HEIGHT(mtx_number,x_normal,z_normal-1)<br /> height_4# = GET MATRIX HEIGHT(mtx_number,x_normal-1,z_normal)<br /> height_0# = GET MATRIX HEIGHT(mtx_number,x_normal,z_normal)<br /> height_2# = GET MATRIX HEIGHT(mtx_number,x_normal,z_normal)<br /> <br /> x1# = (x_normal-1)*25.0 : y1# = height_0#<br /> x2# = (x_normal+0)*25.0 : y2# = height_4#<br /> dx# = x2#-x1# : dy# = y2#-y1#<br /> ax# = ATANFULL(dx#,dy#)<br /> ax# = WRAPVALUE(90-ax#)<br /> <br /> z1# = (z_normal-1)*25.0 : y1# = height_2#<br /> z2# = (z_normal+0)*25.0 : y2# = height_8#<br /> dz# = z2#-z1# : dy# = y2#-y1#<br /> az# = ATANFULL(dz#,dy#)<br /> az# = WRAPVALUE(90-az#)<br /> <br /> nx# = SIN(ax#) : ny# = COS(ax#) : nz#=SIN(az#)<br /> SET MATRIX NORMAL mtx_number,x_normal,z_normal,nx#,ny#,nz#<br /> <br /> NEXT x_normal<br /> NEXT z_normal<br /> <br /> ` refresh<br /> DELETE BITMAP 1<br /> SET CURRENT BITMAP 0<br /> UPDATE MATRIX mtx_number<br /> <br /> ENDFUNCTION

Comments

No comments yet.