Because the first memblock matrix code seemed to be usefull, I decided to make some extended functions which might come in handy.
The new functions are:
settoheightmap(matrix nr, image file string, maximum height)
A simple function to set the height of the matrix according to a heightmap
smoothmatrix(matrix nr, iterations, smooth value)
This function will smooth out the shape of the matrix
Iterations are the times the matrix is smoothed and the smooth value controls how much
the current height is pulled to the averaged height for a point. A smooth value of 1
will pull it to the average height of the point.
The average height is calculated using the surrounding points
colormatrix(matrix nr,height1,height2,height3,lowcolor,midcolor,topcolor)
This function colors the matrix according to a simple coloring algorithm
If the height of the matrix is below height1 then it will get the lowcolor
If the height of the matrix is between height1 and height2 then it will interpolate between the lowcolor and the midcolor
If the height of the matrix is between height2 and height3 then it will interpolate between the midcolor and the topcolor
If the height of the matrix is above height3 then it will get the topcolor
precalcnormals(matrix nr)
To precalculate the normals, needed for the next function
intersectmatrix(matrix nr,bx,by,bz,ex,ey,ez)
This command works the same as the intersect object command, but this command
also returns the tile and the poly hit, which can be used to get the normals.
This command does require that the precalcnormals function is executed before using it
The resulting dist# will be -1.0 if nothing has been hit.
clickonterrain(matrix nr, Field of view, depth, intersect type)
This command will perform an intersect matrix where the mouse is pointing at.
The depth will define how far the reach is of the ray where the mouse is pointing
An intersect type of 1 will perform the special intersectmatrix command which will give you more data
about where you have pointed (position, tile,poly) and will return a dist# of -1.0 if nothing is hit
An intersect type of 2 will perform the standard intersect object command, but will only return the hit position
createlightmap(original matrix nr,lightmap matrix nr,image nr,sun direction x,sun direction y,sun direction z,multiplier for image size,ambient light,maximum light,edge length,height above original matrix)
This command creates a new lightmap matrix and calcualtes a lightmap and puts it over the matrix
The lightmap matrix can be an existing matrix. If it isn't, a new matrix is made (and automatically shaped correctly).
The multiply value defines the size of the lightmap. A value of 1 will make a lightmap image
of the same size of the matrix (vertex count). A multiply value of 2 will make it twice as big.
The rest of the parameters should be clear.
And that's all for now. I hope this is useful as well.
http://www.dannywartnaby.co.uk/rgt/attachments/memmatrix2.zip
Kevil