1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| PointMax = point d'intersection entre mon rayon et le plan d'équation Y=(HauteurMax de mon terrain)
PointMin = point d'intersection entre mon rayon et le plan d'équation Y=(HauteurMin de mon terrain)
Delta = PointMax - PointMin
//définition du sens de parcours selon la direction de mon rayon
if(Delta.x > 0)
MoveX = 1;
else
MoveX = -1;
if(Delta.z > 0)
MoveZ = 1;
else
MoveZ = -1;
//Point va être sur le droite d'équation PointMax - t*Delta
Point = IntersectMax
while( t<=1.0f)
{
// test du triangle { ((int)Point.X, (int)Point.Z); ((int)Point.X+1, (int)Point.Z); ((int)Point.X+1, (int)Point.Z+1)
// test du triangle { ((int)Point.X, (int)Point.Z); ((int)Point.X, (int)Point.Z+1); ((int)Point.X+1, (int)Point.Z+1)
//on passe aux prochain triangles
//on cherche le temps minimal pour passer à une des cases d'à coté
tx = (PointMax.x - Point.x + MoveX)/Delta.x;
tz = (PointMax.z - Point.z + MoveZ)/Delta.z;
if(tx < tz)
t=tx;
else
t = tz;
if(Delta.x == 0)
t=tz;
if(Delta.z == 0)
t=tx;
Point = PointMax - Delta * t;
} |
Partager