コード例 #1
0
ファイル: game.cpp プロジェクト: elemel/crust
 void Game::initVoronoiDiagram()
 {
     Box2 vertexBounds = bounds_;
     vertexBounds.pad(5.0f);
     Box2 triangulationBounds = vertexBounds;
     triangulationBounds.pad(5.0f);
     delauneyTriangulation_ = DelauneyTriangulation(triangulationBounds);
     int subdivCount = 30;
     float subdivWidth = float(vertexBounds.getWidth()) / float(subdivCount);
     float subdivHeight = float(vertexBounds.getHeight()) / float(subdivCount);
     for (int i = 0; i < subdivCount; ++i) {
         for (int j = 0; j < subdivCount; ++j) {
             float x = vertexBounds.p1.x + (float(i) + getRandomFloat()) * subdivWidth;
             float y = vertexBounds.p1.y + (float(j) + getRandomFloat()) * subdivHeight;
             delauneyTriangulation_.addVertex(Vector2(x, y));
         }
     }
     voronoiDiagram_.generate(delauneyTriangulation_);
 }
コード例 #2
0
ファイル: game.cpp プロジェクト: elemel/crust
 void Game::initBlocks()
 {
     Box2 paddedBounds = bounds_;
     paddedBounds.pad(2.0f);
     for (int i = 0; i < voronoiDiagram_.getPolygonCount(); ++i) {
         Polygon2 polygon = voronoiDiagram_.getPolygon(i);
         if (contains(paddedBounds, polygon)) {
             addActor(actorFactory_->createBlock(polygon));
         }
     }
 }