Пример #1
0
 /*
  * Constructor
  * parent, is the GameObject of the parent object (planet, in this case)
  * owner, is the owner class (Planet, in this case)
  * position is the location of the chunk we are currently working on
  * material, is the material that will cover the chunk - TODO: make it so that there is a material for each cube/quad
  *
  * e.g. chunk 0 will be based at 0,0,0 in the Universe
  */
 public PlanetChunk(GameObject parent, Planet owner, Vector3 chunkPosition, Material material, float chunkXIndex, float chunkYIndex, float chunkZIndex)
 {
     this.parent        = parent;
     planet             = owner;
     this.chunkPosition = chunkPosition;
     chunkMaterial      = material;
     this.chunkXIndex   = chunkXIndex;
     this.chunkYIndex   = chunkYIndex;
     this.chunkZIndex   = chunkZIndex;
     planetChunk        = new GameObject("Chunk_" + Universe.BuildPlanetChunkName(chunkXIndex, chunkYIndex, chunkZIndex));
     chunkData          = new Cube[owner.chunkSize, owner.chunkSize, owner.chunkSize];
     CubeIsSolid        = new bool[owner.chunkSize, owner.chunkSize, owner.chunkSize];
 }
Пример #2
0
 // Cube contructor
 public Cube(GameObject parent, PlanetChunk owner,
             int currentX, int currentY, int currentZ,
             Material material, int terrainType,
             Vector3 cubePosition, string chunkName)
 {
     cubeLocation      = cubePosition;
     this.parent       = parent;
     this.owner        = owner;
     cubePhysicalState = CubePhysicalState.SOLID; // default state
     cube          = new GameObject(chunkName + "_" + "Cube_" + Universe.BuildPlanetChunkName(cubeLocation));
     this.currentX = currentX;
     this.currentY = currentY;
     this.currentZ = currentZ;
 }
Пример #3
0
    // generate globe
    public Planet(Vector3 planetPosition)
    {
        this.planetPosition = planetPosition;

        fPlanetCentreXYZValue = planetSize * chunkSize / 2;
        planetCentre          = new Vector3(fPlanetCentreXYZValue, fPlanetCentreXYZValue, fPlanetCentreXYZValue);

        // planetData = new Cube[Universe.universeSize, Universe.universeSize, Universe.universeSize];
        planet = new GameObject("Planet_" + Universe.BuildPlanetChunkName(planetPosition));

        planetChunks = new Dictionary <string, PlanetChunk>();

        // build the planet
        GeneratePlanet();
    }
Пример #4
0
    //  // Called every frame. 'delta' is the elapsed time since the previous frame.
    //  public override void _Process(float delta)
    //  {
    //
    //  }


    /*
     * Constructor
     * parent, is the GameObject of the parent object (planet, in this case)
     * owner, is the owner class (Planet, in this case)
     * position is the location of the chunk we are currently working on
     * material, is the material that will cover the chunk - TODO: make it so that there is a material for each cube/quad
     *
     * e.g. chunk 0 will be based at 0,0,0 in the Universe
     */
    public PlanetChunk(Planet owner, Vector3 chunkPosition, SpatialMaterial chunkMaterial, float chunkXIndex, float chunkYIndex, float chunkZIndex)
    {
        planetChunk = new CSGCombiner();
        name        = "Chunk_" + Universe.BuildPlanetChunkName(chunkXIndex, chunkYIndex, chunkZIndex);

        combiner = new CSGCombiner();

        planet = owner; // the planet this chunk is part of (child of) TODO: IS THIS NEEDED??? I do no think so

        this.chunkPosition = chunkPosition;

        this.chunkXIndex = chunkXIndex;
        this.chunkYIndex = chunkYIndex;
        this.chunkZIndex = chunkZIndex;

        this.chunkMaterial = chunkMaterial;

        chunkData   = new Cube[planet.chunkSize, planet.chunkSize, planet.chunkSize];
        CubeIsSolid = new bool[owner.chunkSize, owner.chunkSize, owner.chunkSize];
    }
Пример #5
0
    /*
     * Check to see if we have crossed over to another chunk (required knowledge for building)
     * If we have, then we need to make sure we are working on the chunk we are now within
     * If not, then we sticl with the current chunk
     *
     * blockLocation - location of the block/cube that the Raycast has hit
     * newLocation - location of the block/cube that is to be placed (during building)
     * hitChunk - chunk that was hit by the Raycast
     *
     */
    PlanetChunk AtChunkBounds(Vector3 blockLocation, out Vector3 newLocation, PlanetChunk hitChunk)
    {
        // initialise cube's new location (initially set to the cube's loaction that the Raycast hit)
        newLocation.x = blockLocation.x;
        newLocation.y = blockLocation.y;
        newLocation.z = blockLocation.z;

        // Are we beyond the positive extreme of X?
        if (blockLocation.x > Universe.planet.chunkSize - 1)
        {
            //    print("We are at the X end");  // if location of block to be placed > PlanetSize * ChunkSize, then next chunk

            // Get neighbouring chunk
            string cn = "Chunk_" +
                        Universe.BuildPlanetChunkName(new Vector3(hitChunk.chunkXIndex + 1, hitChunk.chunkYIndex, hitChunk.chunkZIndex));

            // does that chunk exist?
            PlanetChunk newChunk;
            if (Universe.planet.planetChunks.TryGetValue(cn, out newChunk))
            {
                //    Debug.Log("New Chunk FOUND!");

                // set the cube's location
                newLocation.x = 0;
                newLocation.y = blockLocation.y;
                newLocation.z = blockLocation.z;

                return(newChunk);
            }
            else
            {
                //    Debug.Log("New Chunk NOT FOUND!"); // need to account for reaching end of the planet
                return(null);
            }
        }
        // Are we beyond the positive extreme of Y?
        if (blockLocation.y > Universe.planet.chunkSize - 1)
        {
            //    print("We are at the Y end"); // if location of block to be placed > PlanetSize * ChunkSize, then next chunk

            // Get neighbouring chunk
            string cn = "Chunk_" +
                        Universe.BuildPlanetChunkName(new Vector3(hitChunk.chunkXIndex, hitChunk.chunkYIndex + 1, hitChunk.chunkZIndex));

            // does that chunk exist?
            PlanetChunk newChunk;
            if (Universe.planet.planetChunks.TryGetValue(cn, out newChunk))
            {
                //    Debug.Log("New Chunk FOUND!");

                // set the cube's location
                newLocation.x = blockLocation.x;
                newLocation.y = 0;
                newLocation.z = blockLocation.z;

                return(newChunk);
            }
            else
            {
                //    Debug.Log("New Chunk NOT FOUND!"); // need to account to reaching end of the planet
                return(null);
            }
        }
        // Are we beyond the positive extreme of Z?
        if (blockLocation.z > Universe.planet.chunkSize - 1)
        {
            //    print("We are at the Z end"); // if location of block to be placed > PlanetSize * ChunkSize, then next chunk

            // Get neighbouring chunk
            string cn = "Chunk_" +
                        Universe.BuildPlanetChunkName(new Vector3(hitChunk.chunkXIndex, hitChunk.chunkYIndex, hitChunk.chunkZIndex + 1));

            // does that chunk exist?
            PlanetChunk newChunk;
            if (Universe.planet.planetChunks.TryGetValue(cn, out newChunk))
            {
                //    Debug.Log("New Chunk FOUND!");

                // set the cube's location
                newLocation.x = blockLocation.x;
                newLocation.y = blockLocation.y;
                newLocation.z = 0;

                return(newChunk);
            }
            else
            {
                //    Debug.Log("New Chunk NOT FOUND!"); // need to account to reaching end of the planet
                return(null);
            }
        }
        // Are we at the negative extreme of X?
        if (blockLocation.x < 0) // if location of block to be place is negative, then we have moved into another chunk
        {
            //    print("We are at the X beginning");

            // Get neighbouring chunk
            string cn = "Chunk_" +
                        Universe.BuildPlanetChunkName(new Vector3(hitChunk.chunkXIndex - 1, hitChunk.chunkYIndex, hitChunk.chunkZIndex));

            // does that chunk exist?
            PlanetChunk newChunk;
            if (Universe.planet.planetChunks.TryGetValue(cn, out newChunk))
            {
                //    Debug.Log("New Chunk FOUND!");

                // set the cube's location
                newLocation.x = Universe.planet.chunkSize - 1;
                newLocation.y = blockLocation.y;
                newLocation.z = blockLocation.z;

                return(newChunk);
            }
            else
            {
                //    Debug.Log("New Chunk NOT FOUND!"); // need to account to reaching end of the planet
                return(null);
            }
        }
        // Are we at the negative extreme of Y?
        if (blockLocation.y < 0) // if location of block to be place is negative, then we have moved into another chunk
        {
            //    print("We are at the Y beginning");

            // Get neighbouring chunk
            string cn = "Chunk_" +
                        Universe.BuildPlanetChunkName(new Vector3(hitChunk.chunkXIndex, hitChunk.chunkYIndex - 1, hitChunk.chunkZIndex));

            // does that chunk exist?
            PlanetChunk newChunk;
            if (Universe.planet.planetChunks.TryGetValue(cn, out newChunk))
            {
                //    Debug.Log("New Chunk FOUND!");

                // set the cube's location
                newLocation.x = blockLocation.x;
                newLocation.y = Universe.planet.chunkSize - 1;
                newLocation.z = blockLocation.z;

                return(newChunk);
            }
            else
            {
                //    Debug.Log("New Chunk NOT FOUND!"); // need to account to reaching end of the planet
                return(null);
            }
        }
        // Are we at the negative extreme of Z?
        if (blockLocation.z < 0) // if location of block to be place is negative, then we have moved into another chunk
        {
            //    print("We are at the Z beginning");

            // Get neighbouring chunk
            string cn = "Chunk_" +
                        Universe.BuildPlanetChunkName(new Vector3(hitChunk.chunkXIndex, hitChunk.chunkYIndex, hitChunk.chunkZIndex - 1));

            // does that chunk exist?
            PlanetChunk newChunk;
            if (Universe.planet.planetChunks.TryGetValue(cn, out newChunk))
            {
                //    Debug.Log("New Chunk FOUND!");

                // set the cube's location
                newLocation.x = blockLocation.x;
                newLocation.y = blockLocation.y;
                newLocation.z = Universe.planet.chunkSize - 1;

                return(newChunk);
            }
            else
            {
                //    Debug.Log("New Chunk NOT FOUND!");
                return(null);
            }
        }
        // we are not beyond the extremes of the chunk, therefore carry on with the current chunk
        return(hitChunk);
    }