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
|
void computeBoundsCone(const glm::fvec2& start, const glm::fvec2& end, const glm::fvec2& direction, float& x, float& y)
{
const float angleRotation = computeAngle(glm::fvec2(0.f, 1.f), glm::normalize(direction));
// On se met dans une repère à l'origine
glm::fvec2 vecteur(end.x - start.x, end.y - start.y);
static const float angleCone = 20.f;
glm::fvec2 v1(glm::cos(angleCone / 2) * vecteur.y, vecteur.y);
glm::fvec2 v2(-glm::cos(angleCone / 2) * vecteur.y, vecteur.y);
std::random_device rdx;
std::mt19937 genX(rdx());
std::uniform_real<> disX(v2.x, v1.x);
x = disX(genX);
std::random_device rdy;
std::mt19937 genY(rdy());
std::uniform_real<> disY(0.f, vecteur.y);
y = disY(genY);
x = x * (y / vecteur.y);
glm::fvec2 xy(x, y);
xy *= (glm::length2(xy) / vecteur.y);
if (angleRotation != 0)
{
float radians = glm::radians(angleRotation);
float cosinus = glm::cos(radians);
float sinus = glm::sin(radians);
// rotation around 0,0
float xnew = cosinus * x + sinus * y;
float ynew = sinus * -x + cosinus * y;
// translation
x = xnew + start.x;
y = ynew + start.y;
}
else
{
x += start.x;
y += start.y;
}
x = xy.x;
y = xy.y;
} |
Partager