示例#1
0
 void ButtonDown(std::string b) {
     if (b=="f") {
         follow = !follow;
     } else if (b=="w") {
         wireframe = !wireframe;
     } else if (b=="n") {
         navMesh->Enabled() = !navMesh->Enabled();
         //navMesh->EnableComponent<Material>(!navMesh->IsComponentEnabled<Material>());
     }else if (b=="c") {
         collisionMesh->Enabled() = !collisionMesh->Enabled();
         //collisionMesh->EnableComponent<Material>(!collisionMesh->IsComponentEnabled<Material>());
     } else if (b=="b") {
         Point size(1 + MathHelper::Random(3), 1 + MathHelper::Random(3));
         GameObject* building = world.CreateObject();
         building->AddComponent<Transform>()->Position = marker->GetComponent<Transform>()->Position;
         building->GetComponent<Transform>()->Rotation = Quaternion(MathHelper::Random(0, MathHelper::DegToRad * 360.0f), {0,1,0});
         building->AddComponent<Obstacle>()->size = size;
         building->AddComponent<Material>()->Shader = &renderer->Shaders.LitColored;
         building->AddComponent<Mappable>()->Map = map->GetComponent<Map>();
         auto& mesh = building->AddComponent<Mesh>()->GetMesh<Vertex>();
         mesh.AddCube({0,1,0}, {(float)size.x,1,(float)size.y});
     }
 }
示例#2
0
 void NavigationMeshUpdated(Map* map) {
     if (navMesh) navMesh->Remove();
     if (collisionMesh) collisionMesh->Remove();
     
 
     NavMesh& mesh = *map->NavMesh();
     
     for (int i=0; i<2; i++) {
     
         GameObject* meshObject = world.CreateObject();
         meshObject->Enabled() = false;
         meshObject->AddComponent<Transform>();
         meshObject->AddComponent<Material>()->Shader = &renderer->Shaders.Colored;
         meshObject->GetComponent<Material>()->BlendMode = BlendModeType::Alpha;
         //meshObject->EnableComponent<Material>(false);
         auto& navMeshMesh = meshObject->AddComponent<Mesh>()->GetMesh<Vertex>();
         
         NavMesh::Vertices& vertices = i==0 ? mesh.navigation : mesh.collision;
         
         for(auto& p : vertices) {
             Vertex v;
             v.Position = {p.x, 1.50f+i*0.1f, p.y};
             v.Color = i==0 ? Colour::Red() : Colour::Green(); //Colour::HslToRgb(i*180, 1, 1, 1);
             navMeshMesh.vertices.push_back(v);
             if (navMeshMesh.vertices.size()>25000) break;
         }
         
         for (auto& p : mesh.GetTriangles()) {
             bool valid = true;
             for (int i=0; i<3; i++) {
                 if (p->corners[i]>=navMeshMesh.vertices.size()) {
                     valid = false;
                     break;
                 }
             }
             if (!valid) continue;
         
             for (int i=0; i<3; i++) {
                 navMeshMesh.triangles.push_back(p->corners[i]);
             }
         }
         navMeshMesh.Flip();
         
         if (i==0) {
             navMesh = meshObject;
         } else {
             collisionMesh = meshObject;
         }
     }
 }