Ejemplo n.º 1
0
TerrainChunk::TerrainChunk(
    int xChunkIndex,
    int yChunkIndex,
    int zChunkIndex,
    Terrain *terrain
):
    Entity("TerrainChunk"),
    _xChunkIndex(xChunkIndex),
    _yChunkIndex(yChunkIndex),
    _zChunkIndex(zChunkIndex),
    _terrain(terrain)
{
    std::ostringstream stringStream;
    stringStream << "TerrainChunk [" <<
        _xChunkIndex << ", " <<
        _yChunkIndex << ", " <<
        _zChunkIndex << "]";

    _name = stringStream.str();

    _paletteRenderables.reserve(DefaultCapacity);

    _grid = new MatrixVoxelGrid(ChunkSize, ChunkSize, ChunkSize);

    // Setup for a correct model matrix.
    setPosition(
        _xChunkIndex * ChunkSize,
        _yChunkIndex * ChunkSize,
        _zChunkIndex * ChunkSize);

    // Setup for correct frustum culling.
    AABB3 localAABB;
    localAABB.setMinMax(Vector3(0, 0, 0), Vector3(ChunkSize, ChunkSize, ChunkSize));
    expandLocalAABB(localAABB);
}
Ejemplo n.º 2
0
void Entity::addModel(Model *model, Material *mat) {
    ASSERT(model);

    for (int i = 0; i < model->getMeshCount(); i++) {
        ModelMesh *mesh = model->getMesh(i);
        expandLocalAABB(mesh->getBoundingBox());
        _renderables.push_back(new Renderable(
            mesh->getRenderOperation(),
            mat ? mat : mesh->getDefaultMaterial()));
    }
}