You are not logged in.
Pages: 1
I was bored so I made these ds_grid scripts. They will return bilinear and bicubic interpolated cell values when passed a fractional grid coordinate.
The task that comes to mind for these is when using a grid as a height map in a 3D environment. I regularly see requests at GMC for smoothly navigating a height map.
ds_grid_get_bilinear(id,x,y)
// ds_grid_get_bilinear(id,x,y)
// returns bilinear interpolation of the
// four grid cells surrounding the given
// fractional coordinate
//
// A-----B
// | |
// | X |
// C-----D
//
// GMLscripts.com
{
var ix,iy,fx,fy,A,B;
ix = floor(argument1);
iy = floor(argument2);
fx = argument1 - ix;
fy = argument2 - iy;
A = ds_grid_get(argument0,ix,iy);
B = ds_grid_get(argument0,ix+1,iy);
A += fy*(ds_grid_get(argument0,ix,iy+1)-A);
B += fy*(ds_grid_get(argument0,ix+1,iy+1)-B);
return A+fx*(B-A);
}
ds_grid_get_bicubic(id,x,y) - depends on http://www.gmlscripts.com/script/spline4
// ds_grid_get_bicubic(id,x,y)
// returns bicubic interpolation of the
// sixteen grid cells surrounding the given
// fractional coordinate
// DEPENDENCIES: spline4(t,x0,x1,x2,x3)
// Catmull-Rom Spline (four knots)
// http://www.gmlscripts.com/script/spline4
//
// A - - B - - C - - D
// ' ' ' '
// ' ' ' '
// E - - F-----G - - H
// ' | | '
// ' | X | '
// I - - J-----K - - L
// ' ' ' '
// ' ' ' '
// M - - N - - O - - P
//
// GMLscripts.com
{
var ix,iy,fx,fy;
ix = floor(argument1);
iy = floor(argument2);
fx = argument1 - ix;
fy = argument2 - iy;
return spline4(fx,
spline4(fy,
ds_grid_get(argument0,ix-1,iy-1),
ds_grid_get(argument0,ix-1,iy ),
ds_grid_get(argument0,ix-1,iy+1),
ds_grid_get(argument0,ix-1,iy+2)),
spline4(fy,
ds_grid_get(argument0,ix ,iy-1),
ds_grid_get(argument0,ix ,iy ),
ds_grid_get(argument0,ix ,iy+1),
ds_grid_get(argument0,ix ,iy+2)),
spline4(fy,
ds_grid_get(argument0,ix+1,iy-1),
ds_grid_get(argument0,ix+1,iy ),
ds_grid_get(argument0,ix+1,iy+1),
ds_grid_get(argument0,ix+1,iy+2)),
spline4(fy,
ds_grid_get(argument0,ix+2,iy-1),
ds_grid_get(argument0,ix+2,iy ),
ds_grid_get(argument0,ix+2,iy+1),
ds_grid_get(argument0,ix+2,iy+2)));
}
Here are the scripts for download.
http://www.planetxot.com/download/ds_gr … icubic.gml
Should be pretty self-explanitory but here is a demonstration as well.
http://www.planetxot.com/download/ds_gr … icubic.gmk
The demo requires GM7. To use with GM8 you'll need to modify the background creation call found in User Event 1.
Abusing forum power since 1986.
Offline
This was a Life Saver.
I changed the random filler to favor higher numbers the lower you go, with a forced lower limit. Then I assigned each "mineral" in my game, to a range. The 0 to 40 range got Air, for example. The 240 to 242 range got Diamond.
I generated a random number every 4 pixels and used the Bucubic "smoothing" to fill in the rest. It's a very good level editor with very cool, fun landscapes, and it gives you amazing accuracy on rarity if you use it for generating landscapes. I can have pockets of minerals, with stone being the foundation of the world, and rarer materials encased deep inside more common materials.
Very cool. I would have been doomed without these scripts.
Offline
Hi Daniel! Welcome to the GMLscripts.com forums.
I'm pleased you like the scripts. It sounds like you've found a very interesting application for them. I look forward to learning more about your game and your level editor. Is there any other information you can share?
Abusing forum power since 1986.
Offline
Offline
Neat! Thanks for sharing that.
The vertical gradient you are using to influence the shape and composition of the random landscape brought to mind an article I read recently in Game Developer Magazine. In it Joshua Tippetts attempts to create a Minecraft-like world builder. The original journal entry the article was based on can be found linked below. You might find it interesting.
http://www.gamedev.net/blog/33/entry-22 … world-gen/
The explanation is fairly vague with implementation details and it has some minor technical errors, but it's not a bad read.
Abusing forum power since 1986.
Offline
I stumbled across the same article. It was great.
I soon found that the same map style simply won't work in 2D, and needed something better. I was using linear interpolation initially. Cubic interpolation added a certain bang to the terrain, making it more fun for 2D play. I know with the right kind of noise I could do it (noise can do anything!), but this method was much simpler as I didn't have to generate a noise map that smoothly matched up to the smoothmap in another adjacent chunk. This method I could just throw random values into the unknown territory and it would still look right.
Offline
Just think of it as single-octave aperiodic noise. Sounds fancy.
Abusing forum power since 1986.
Offline
Pages: 1