Skip to main content
gamedev.net
🔒 Locked

Deformable terrain...

Started by elis-cool Jun 17, 2002 at 1:32 AM 5 replies 350+ views
Original Post
elis-cool
elis-cool
Ok I played Pocket Tanks, similer to worms, where its a big 2d map and you have a bunch of different weapons to kill the other guy, now im wondering, how do you deformable terrain like that? The way I was thinking seems a little too slow/complex... you store every pixel into a massive linked list, which would be quite large eg it would be like 800*300 which is like 240 000 nodes into the list, then you need variables in each node, eg vertex x,y,z, color, velocitys etc... this seems like way to much to process through each frame and use way to much memory. Any ideas? im using D3D by the way... CEO Plunder Studios
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
__ODIN__
__ODIN__
You''re getting too complex.

In a purely 2D fashion, you can store only the edges (in this case, just the Height of ever row of pixels on the map.) An explosion just lowers this height. You can add further dynamics by adding particle-effects that behave sort-of-like the old Snow demos (where they settle on top of each other), and have dirt be thrown around by explosions.

The key is to focus on the row of stacks + any currently particles, rather than trying to model all of them as particles.

Allan

Fe doeyr, Frender Doeyr,Ein sjoelv doeyr paa sama vis

Eg veit et som aldri doeyr... Dom over kvar ein doed.
elis-cool
elis-cool
But what if the explosion undercuts a portion? and anyway that is still like 800 Nodes... but I sort of get ya...

CEO Plunder Studios
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
JuNC
JuNC
I thought about this, you can use spans. Keep a linked list for each column and just split up the spans as required. (this works very well for random generation of levels ala worms)

However, why would you want to keep all the terrain ''pixels'' in a linked list, surely an array would work fine? Or am I missing something? When you want to simulate an explosion, just ''draw'' the explosion shape onto the array, removing the desired pixels.

Dirge
Dirge
First, this game is a complete rip of Scorched Earth, a classic which was shareware too, so I find it disconcerting that this game is shareware too (it''s the same game). But anyhow...

You guy''s are still making this a little too complex. A 2D Array of say, your screen dimensions (800x600 in this example) is all you would need. Why a linked list? Theres no reason for it, the terrain only destroys itself, you never need to ad on to it. No reason for it to be dynamice.

So 800x600 structures of something called a terrain element. which could be this:
struct
{
// Color
int iR, iG, iB;

// Whether this terrain piece is alive or dead (destroyed)
bool bAlive;
};

And whatever else you may need.

So lets say there is a collision. You check the radius of the collision to the terrain elements that are within it''s radius. The appropriate one are destroyed (made dead). Now step two, apply gravity. If a pixel/terrain element does not have anything under it, just drop it! Thats it!

The terrain element are kind of like voxels btw if that makes sense to you (they have depth in a way).


"Love all, trust a few. Do wrong to none." - Shakespeare

Dirge - Aurelio Reis
www.CodeFortress.com
"Artificial Intelligence: the art of making computers that behave like the ones in movies."www.CodeFortress.com
JuNC
JuNC
quote:

surely an array would work fine?



*ahem* Your post is more informative though
__ODIN__
__ODIN__
Simple solution:

Assuming SCREEN_X is length of screen.

An array int iRow[SCREEN_X] essentially gives you the height for each point. Assume iRow[x] = -1 means that this layer has no height at pixel x.

When you now draw the landscape;

for (x=0 to SCREEN_X)
for (y = 0 to iRow[x])
Pixel(x, y) = Color;

To blow up the terrain;

Radius = Radius of explosion (in pixels)
Xp, Yp = X and Y of explosion epicenter (in pixels)

for (x = 0 to Radius)
{
ExplosionTop = iRow[Xp - x] + sqrt(x^2 + Radius^2)
ExplosionBottom = iRow[Xp - x] - sqrt(x^2 + Radius^2)
// Note that you can optimize this

if (ExplosionTop > iRow[Xp + x])
{
if (ExplosionBottom > iRow[Xp + x])
// Didn''t hit anything
else
// Shaved the top of the stack
iRow[Xp + x] = ExplosionBottom;
} else
{ // Took a chunk out of the middle.
// Remove that chunk, and reduce the stack
iRow[Xp+x] -= ExplosionTop - ExplosionBottom;
}
}

Voila...







Fe doeyr, Frender Doeyr,Ein sjoelv doeyr paa sama vis

Eg veit et som aldri doeyr... Dom over kvar ein doed.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.