Ejemplo n.º 1
0
 void addOneObstacle (void)
 {
     
     // pick a random center and radius,
     // loop until no overlap with other obstacles and the home base
     float r;
     Vec3 c;
     float minClearance;
     const float requiredClearance = gWanderAround->radius() * 4; // 2 x diameter
     do
     {
         r = frandom2 (1.5, 4);
         c = randomVectorOnUnitRadiusXZDisk () * gMaxStartRadius * 1.1f;
         minClearance = FLT_MAX;
         
         for (SOI so = allObstacles.begin(); so != allObstacles.end(); so++)
         {
             testOneObstacleOverlap ((**so).radius, (**so).center);
         }
     }
     while (minClearance < requiredClearance);
     
     // add new non-overlapping obstacle to registry
     allObstacles.push_back (new SphericalObstacle (r, c));
     obstacleCount++;
 }
Ejemplo n.º 2
0
void GroupBase::addOneObstacle (void)
{
    if (obstacleCount < maxObstacleCount)
    {
        // pick a random center and radius,
        // loop until no overlap with other obstacles and the home base
        float r;
        float3 c;
        float minClearance;
        const float requiredClearance = gSeeker->radius() * 4; // 2 x diameter
        do
        {
            r = frandom2 (1.5, 4);
            c = float3_scalar_multiply(float3_randomVectorOnUnitRadiusXZDisk(), gMaxStartRadius * 1.1f);
            minClearance = FLT_MAX;

            for (SOI so = allObstacles.begin(); so != allObstacles.end(); so++)
            {
                testOneObstacleOverlap ((**so).radius, (**so).center);
            }

            testOneObstacleOverlap (gHomeBaseRadius - requiredClearance,
                                    gHomeBaseCenter);
        }
        while (minClearance < requiredClearance);

        // add new non-overlapping obstacle to registry
        allObstacles.push_back (new SphericalObstacle (r, c));
        obstacleCount++;
    }
}