added GetSurfaceVector() to Math.c which can be used to get informations about the surface of the landscape at some point (f.e. for bouncing projectiles)

issue1247
David Dormagen 2013-07-11 21:09:04 +02:00 committed by Sven Eberhardt
parent fe04a0fe79
commit 6217a84f0b
1 changed files with 21 additions and 0 deletions

View File

@ -162,4 +162,25 @@ global func FindHeight(int x)
while (GBackSemiSolid(x, y) && y)
y--;
return y;
}
/*
Returns the normal vector of the (solid) landscape at a point relative to an object.
Can f.e. be used to bounce projectiles.
*/
global func GetSurfaceVector(int x, int y)
{
var normal = {x = 0, y = 0};
var fac = 1;
for(var fac = 1; fac <= 4; fac *= 2)
{
if(GBackSolid(x + fac, y)) {--normal.x;}
if(GBackSolid(x - fac, y)) {++normal.x;}
if(GBackSolid(x, y + fac)) {--normal.y;}
if(GBackSolid(x, y - fac)) {++normal.y;}
}
return normal;
}