Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Memblock matrix extended functions

Author
Message
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 25th Jan 2004 18:21
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
OutLand
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: uk,wales
Posted: 25th Jan 2004 21:08
Very Very nice. I liked being able to color each tile as well as texturing them. Nice new functions to
Steele
21
Years of Service
User Offline
Joined: 25th Oct 2003
Location: Somewhere over the rainbow
Posted: 15th Feb 2004 04:09 Edited at: 15th Feb 2004 04:11
Hi Kevil,

I've been working on a game using a large matrix and I read your first thread on the MemMatrix function. Unfortunately, that link is no longer valid. Is it possible to attach the new link for it?

*Edited here*

Nevermind, I see that they are already included in MemMatrix2.zip.

Thanks,

Steele

-- I straddle the line between genius and insanity. Guess which side I am on now? --

Login to post a reply

Server time is: 2024-11-24 01:06:45
Your offset time is: 2024-11-24 01:06:45