Exemple #1
0
Exhaustion::Exhaustion(kick::GameObject *gameObject) : Component(gameObject) {
    MeshRenderer* mr = gameObject->addComponent<MeshRenderer>();
    Material *material = new Material();
    material->setShader(Project::loadShader("poly-assets/shaders/unlit_vertex_colored.shader"));
    mr->setMaterial(material);
    Mesh *mesh = new Mesh();

    mesh->setMeshData(loadPlyData("poly-assets/models","cloud.ply"));
    mr->setMesh(mesh);
}
Exemple #2
0
void Terrain::addPlant(Transform *parent, vec3 pos){
    static int plantCounter = 0;
    plantCounter++;
    Mesh* plantMesh = plants[plantCounter % plants.size()];
    auto gameObject = Engine::activeScene()->createGameObject("Terrain");
    MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
    meshRenderer->setMesh(plantMesh);
    Material *material = new Material();
    material->setShader(Project::loadShader("poly-assets/shaders/diffuse_vertex_colored.shader"));
    meshRenderer->setMaterial(material);

    vec3 finalPos = (vec3)(parent->globalMatrix()*vec4(pos,1.0f));
    gameObject->transform()->setLocalPosition(finalPos);
    gameObject->transform()->setLocalScale(vec3(1)*linearRand(0.5f,1.5f));
    gameObject->transform()->setLocalRotationEuler(vec3(0,(float)linearRand(-M_PI,M_PI),0));
}
Exemple #3
0
void Terrain::addCloud(vec3 pos, vec3 min, vec3 max){
    static MeshData* cloudMesh = loadPlyData("poly-assets/models","cloud.ply");
    static Mesh *mesh = new Mesh();
    mesh->setMeshData(cloudMesh);

    auto gameObject = Engine::activeScene()->createGameObject("Cloud");
    gameObject->addComponent<Cloud>(min, max);
    MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
    meshRenderer->setMesh(mesh);
    Material *material = new Material();
    material->setShader(Project::loadShader("poly-assets/shaders/unlit_vertex_colored.shader"));
    meshRenderer->setMaterial(material);


    gameObject->transform()->setLocalPosition(pos);
    gameObject->transform()->setLocalScale(vec3(1)*linearRand(0.5f,5.0f));
    gameObject->transform()->setLocalRotationEuler(vec3(0,(float)linearRand(-M_PI,M_PI),0));
}
Exemple #4
0
void Terrain::buildTerrain(vec2 offset, Mesh *mesh, MeshData* meshData, vec3 min, vec3 max){
    auto gameObject = Engine::activeScene()->createGameObject("Terrain");
    MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
    meshRenderer->setMesh(mesh);
    Material *material = new Material();
    material->setShader(Project::loadShader("poly-assets/shaders/unlit_vertex_colored.shader"));
    meshRenderer->setMaterial(material);

    gameObject->transform()->setPosition(vec3{offset.x*200*worldScale, 0, offset.y*200*worldScale});
    gameObject->transform()->setLocalScale(vec3{worldScale, 1, worldScale});
    gameObject->transform()->setLocalRotationEuler(vec3{0,M_PI*(offset.x+offset.y),0});

    auto& indices = meshData->submeshIndices(0);
    auto& pos = meshData->position();
    for (int i=0;i<190;i++){
        // find random triangle
        int index = (int)linearRand(0.0f, indices.size()/3-1.0f)*3;

        vec3 p1 = pos[index];
        vec3 p2 = pos[index+1];
        vec3 p3 = pos[index+2];
        if (p1.y <-0.1){
            continue;
        }
        bool horizontal =glm::abs(p1.y- p2.y)+glm::abs(p2.y-p3.y)<0.1f;
        if (horizontal){
            vec3 midpoint = (p1+p2+p3)*(1/3.0f);
            addPlant (gameObject->transform(), midpoint);
        }
    }

    for (int i=0;i<20;i++){
        float x= linearRand((-100.0f),(100.0f));
        float z= linearRand((-100.0f),(100.0f));
        vec3 cloudPos = vec3(x,0,z) * worldScale + gameObject->transform()->position();
        cloudPos.y = linearRand(20.0f,50.0f);

        addCloud(cloudPos, min, max);
    }
}