예제 #1
0
    public void Generate(int x, int y, int z)
    {
        OpenCog.Map.OCBlockData block = map.GetBlock(x, y - 1, z);
        if (block.IsEmpty() || !block.block.GetName().Equals("Dirt"))
        {
            return;
        }
        if (Random.Range(0f, 1f) > 0.2f)
        {
            return;
        }

        GenerateTree(x, y, z);
    }
    public static Vector3?Intersection(OpenCog.Map.OCMap map, Ray ray, float distance)
    {
        Vector3 start  = ray.origin;
        Vector3 end    = ray.origin + ray.direction * distance;
        int     startX = Mathf.RoundToInt(start.x);
        int     startY = Mathf.RoundToInt(start.y);
        int     startZ = Mathf.RoundToInt(start.z);
        int     endX   = Mathf.RoundToInt(end.x);
        int     endY   = Mathf.RoundToInt(end.y);
        int     endZ   = Mathf.RoundToInt(end.z);

        if (startX > endX)
        {
            int tmp = startX;
            startX = endX;
            endX   = tmp;
        }

        if (startY > endY)
        {
            int tmp = startY;
            startY = endY;
            endY   = tmp;
        }

        if (startZ > endZ)
        {
            int tmp = startZ;
            startZ = endZ;
            endZ   = tmp;
        }

        float minDistance = distance;

        for (int z = startZ; z <= endZ; z++)
        {
            for (int y = startY; y <= endY; y++)
            {
                for (int x = startX; x <= endX; x++)
                {
                    OpenCog.Map.OCBlockData block = map.GetBlock(x, y, z);
                    if (block == null || block.IsEmpty() || block.IsFluid())
                    {
                        continue;
                    }
                    float dis = BlockRayIntersection(new Vector3(x, y, z), ray);
                    minDistance = Mathf.Min(minDistance, dis);
                }
            }
        }

        if (minDistance != distance)
        {
            return(ray.origin + ray.direction * minDistance);
        }
        return(null);
    }
예제 #3
0
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Private Member Functions

        //---------------------------------------------------------------------------

        private static bool IsFaceVisible(OpenCog.Map.OCMap map, Vector3i nearPos)
        {
            OCBlockData blockData = map.GetBlock(nearPos);

            if (blockData == null)
            {
                return(false);
            }
            OCBlock block = blockData.block;

            return(!(block is OCCubeBlock) || block.IsAlpha());
        }
예제 #4
0
    private static Contact?GetClosestContact(OpenCog.Map.OCMap map, CharacterController controller)
    {
        Vector3 pos = controller.transform.position;
        int     x1  = Mathf.FloorToInt(pos.x - controller.radius);
        int     y1  = Mathf.FloorToInt(pos.y);
        int     z1  = Mathf.FloorToInt(pos.z - controller.radius);

        int x2 = Mathf.CeilToInt(pos.x + controller.radius);
        int y2 = Mathf.CeilToInt(pos.y + controller.height);
        int z2 = Mathf.CeilToInt(pos.z + controller.radius);

        Contact?contact = null;

        for (int x = x1; x <= x2; x++)
        {
            for (int y = y1; y <= y2; y++)
            {
                for (int z = z1; z <= z2; z++)
                {
                    OpenCog.Map.OCBlockData block = map.GetBlock(x, y, z);
                    if (block.IsSolid())
                    {
                        Contact?_newContact = BlockCharacterCollision.GetContactBlockCharacter(new Vector3i(x, y, z), pos, controller);
                        if (_newContact.HasValue && _newContact.Value.delta.magnitude > float.Epsilon)
                        {
                            Contact newContact = _newContact.Value;
                            if (!contact.HasValue || newContact.sqrDistance > contact.Value.sqrDistance)
                            {
                                contact = newContact;
                            }
                        }
                    }
                }
            }
        }

        return(contact);
//		return null;
    }
예제 #5
0
        public static void Build(Vector3i localPos, Vector3i worldPos, OpenCog.Map.OCMap map, OpenCog.Builder.OCMeshBuilder mesh, bool onlyLight)
        {
            OpenCog.Map.OCBlockData block = map.GetBlock(worldPos);
            OCCubeBlock             cube  = (OCCubeBlock)block.block;

            OpenCog.Map.OCBlockDirection direction = block.GetDirection();

            for (int i = 0; i < 6; i++)
            {
                OCCubeBlock.CubeFace face    = faces[i];
                Vector3i             dir     = directions[i];
                Vector3i             nearPos = worldPos + dir;
                if (IsFaceVisible(map, nearPos))
                {
                    if (!onlyLight)
                    {
                        BuildFace(face, cube, direction, localPos, mesh);
                    }
                    BuildFaceLight(face, map, worldPos, mesh);
                }
            }
        }
예제 #6
0
    private bool GenerateChunk(Vector3i chunkPos)
    {
        bool reportedWater   = false;
        bool reportedTerrain = false;
        bool reportedIsland  = false;

        reportedWater   = true;
        reportedTerrain = true;
        reportedIsland  = true;

        bool generated = false;

        for (int z = -1; z < OpenCog.Map.OCChunk.SIZE_Z + 1; z++)
        {
            for (int x = -1; x < OpenCog.Map.OCChunk.SIZE_X + 1; x++)
            {
                for (int y = 0; y < OpenCog.Map.OCChunk.SIZE_Y; y++)
                {
                    Vector3i worldPos = OpenCog.Map.OCChunk.ToWorldPosition(chunkPos, new Vector3i(x, y, z));

                    if (worldPos.y <= WATER_LEVEL)
                    {
                        if (map.GetBlock(worldPos).IsEmpty())
                        {
                            map.SetBlock(water, worldPos);
                        }
                        if (!reportedWater)
                        {
                            Debug.Log("I made a water block!");
                            reportedWater = true;
                        }
                        generated = true;
                    }

                    int terrainHeight = GetTerrainHeight(worldPos.x, worldPos.z);
                    if (worldPos.y <= terrainHeight)
                    {
                        GenerateBlockForBaseTerrain(worldPos);
                        if (!reportedTerrain)
                        {
                            Debug.Log("I made a terrain block!");
                            reportedTerrain = true;
                        }
                        generated = true;
                        continue;
                    }

                    int islandHeight = GetIslandHeight(worldPos.x, worldPos.z);
                    if (worldPos.y <= islandHeight)
                    {
                        GenerateBlockForIsland(worldPos, islandHeight - worldPos.y, islandHeight);
                        if (!reportedIsland)
                        {
                            Debug.Log("I made an island block!");
                            reportedIsland = true;
                        }
                        generated = true;
                        continue;
                    }
                }
            }
        }
        return(generated);
    }