forked from Mirrors/openclonk
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)
parent
fe04a0fe79
commit
6217a84f0b
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue