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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
void PourSuivrexx (IVectPropulsable Poursuivant, IVectMobile Cible)
{
float distanceBrute,dist1s, distanceEstimee, tempParcour;
Vecteur2d posPoursuivantEstimer, posCibleEstimer;
AngleRadian angleCorrigé;
distanceBrute = Vecteur2d.Distance(Poursuivant.Coordonnées, Cible.Coordonnées);
//if(Vecteur2d.Distance(Poursuivant.Vitesse) < Poursuivant.Accélération )
//{
// dist1s = Poursuivant.Accélération ;
//}
//else
//{
dist1s = Vecteur2d.Distance(Poursuivant.Vitesse);
// }
tempParcour = (distanceBrute / dist1s);
posPoursuivantEstimer = Poursuivant.Coordonnées + (Poursuivant.Vitesse * tempParcour);
//dist1s = Vecteur2d.Distance(Cible.Vitesse);
//tempParcour = (distanceBrute / dist1s);
posCibleEstimer = Cible.Coordonnées + (Cible.Vitesse * tempParcour);
distanceEstimee = Vecteur2d.Distance(posPoursuivantEstimer, posCibleEstimer);
angleCorrigé = (AngleRadian)Vecteur2d.Delta(Poursuivant.Coordonnées, posCibleEstimer);
Poursuivant.Propulser((Vecteur2d)angleCorrigé, ZI.DuréeCycle);
}
private void Poursuivre (EvolAnimal EnCour, Evol proie)
{
float aCorrection;
AngleRadian angleVersCible, aCorriger, aPoussee, aPropul;
Vecteur2d vectPropulsion, vDelta;
vDelta = Vecteur2d.Delta(EnCour.Coordonnées, proie.Coordonnées);
angleVersCible = (AngleRadian)Vecteur2d.Delta(EnCour.Coordonnées, proie.Coordonnées);
angleVersCible = AngleRadian.Normalize(angleVersCible);
aPoussee = (AngleRadian)EnCour.Vitesse;
/* Prédator.Vitesse = Prédator.Vitesse+ ((vecteurDirection * Prédator.Accélération) * zi.DuréeCycle));
* Non non ce n'est pas juste, je dois calculer la différence d'angle entre l'angle actuel du prédateur et l'angle de propulsion
* et l'ajouté à l'angle de propulsion
* À VÉRIFIER
*/
aCorrection = AngleRadian.Différence(angleVersCible, (AngleRadian)EnCour.Vitesse);
float aTest;
aTest = (float)(Math.PI / 2);
// sup 45°
if(aCorrection > aTest)
{ // = (-180 + diff)/3
aCorrection = (-(float)Math.PI + aCorrection) / 3;
}
// inf -45°
else if(aCorrection < -aTest)
{
aCorrection = ((float)Math.PI + aCorrection) / 3;
}
// inf - 120° sup 120°
else if(aCorrection < -Math.PI / 3 * 2 || aCorrection > Math.PI / 3 * 2)
{
aCorrection = 0 - ((aCorrection / 3) * 2);
}
else
{
aCorrection = 0 - aCorrection;
}
aCorriger = angleVersCible + aCorrection;
//aCorriger = angleVersCible;// +aCorrection;
/*
Console.WriteLine(angleVersCible.Degrés+"; - " +
((AngleRadian)Prédator.Vitesse).Degrés+
((AngleRadian)aCorrection).Degrés+ " = "+ aCorriger.Degrés);
*/
vectPropulsion = (Vecteur2d)aCorriger;
EnCour.Propulser( vectPropulsion, ZI.DuréeCycle);
} |
Partager