示例#1
0
        /// <summary>
        /// Gets a world space position of a point on terrain's tile coordinates
        /// </summary>
        /// <returns>The height map coords.</returns>
        /// <param name="pointOnTerrain">Point on terrain.</param>
        protected Vector3 GetHeightMapCoords(Vector3 pointOnTerrain)
        {
            Vector3 pos = pointOnTerrain - world.terrain.transform.position;

            pos.x = world.worldData.tileWidth * Mathf.Round(pos.x / world.worldData.tileWidth);
            pos.z = world.worldData.tileWidth * Mathf.Round(pos.z / world.worldData.tileWidth);
            pos.y = world.GetHeight(pos.x, pos.z);

            return(pos);
        }
示例#2
0
        void DrawTile(int x, int y)
        {
            float   tileWidth = world.worldData.tileWidth;
            Vector3 center    = world.GetWorldPositionFromTile(x, y, true);

            Vector3 c1 = center + new Vector3(-0.4f * tileWidth, 0, -0.4f * tileWidth);

            c1.y = Mathf.Max(world.GetHeight(c1), world.GetWaterLevelHeight());
            Vector3 c2 = center + new Vector3(-0.4f * tileWidth, 0, 0.4f * tileWidth);

            c2.y = Mathf.Max(world.GetHeight(c2), world.GetWaterLevelHeight());
            Vector3 c3 = center + new Vector3(0.4f * tileWidth, 0, 0.4f * tileWidth);

            c3.y = Mathf.Max(world.GetHeight(c3), world.GetWaterLevelHeight());
            Vector3 c4 = center + new Vector3(0.4f * tileWidth, 0, -0.4f * tileWidth);

            c4.y = Mathf.Max(world.GetHeight(c4), world.GetWaterLevelHeight());

            GL.Vertex(c1);
            GL.Vertex(c2);
            GL.Vertex(c3);
            GL.Vertex(c4);
        }
示例#3
0
        void OnPostRender()
        {
            // set the current material
            lineMaterial.SetPass(0);

            GL.Begin(GL.LINES);

            if (isVisible)
            {
                GL.Color(mainColor);

                #region draw gl lines
                Vector3 wsOffset = world.terrain.transform.position;
                Vector3 lsStart  = start;
                Vector3 lsStop   = stop;
                int     startX   = Mathf.RoundToInt(lsStart.x < lsStop.x ? lsStart.x :lsStop.x);
                int     stopX    = Mathf.RoundToInt(lsStart.x > lsStop.x ? lsStart.x :lsStop.x);

                int startZ = Mathf.RoundToInt(lsStart.z < lsStop.z ? lsStart.z :lsStop.z);
                int stopZ  = Mathf.RoundToInt(lsStart.z > lsStop.z ? lsStart.z :lsStop.z);

                switch (overlayType)
                {
                case OverlayType.SQUARE:
                    for (int x = startX; x < stopX; x++)
                    {
                        GL.Vertex3(x + wsOffset.x, world.GetHeight(x, startZ) + offsetY + wsOffset.y, startZ + wsOffset.z);
                        GL.Vertex3(x + 1 + wsOffset.x, world.GetHeight(x + 1, startZ) + offsetY + wsOffset.y, startZ + wsOffset.z);

                        GL.Vertex3(x + wsOffset.x, world.GetHeight(x, stopZ) + offsetY + wsOffset.y, stopZ + wsOffset.z);
                        GL.Vertex3(x + 1 + wsOffset.x, world.GetHeight(x + 1, stopZ) + offsetY + wsOffset.y, stopZ + wsOffset.z);
                    }

                    for (int z = startZ; z < stopZ; z++)
                    {
                        GL.Vertex3(startX + wsOffset.x, world.GetHeight(startX, z) + offsetY + wsOffset.y, z + wsOffset.z);
                        GL.Vertex3(startX + wsOffset.x, world.GetHeight(startX, z + 1) + offsetY + wsOffset.y, z + 1 + wsOffset.z);

                        GL.Vertex3(stopX + wsOffset.x, world.GetHeight(stopX, z) + offsetY + wsOffset.y, z + wsOffset.z);
                        GL.Vertex3(stopX + wsOffset.x, world.GetHeight(stopX, z + 1) + offsetY + wsOffset.y, z + 1 + wsOffset.z);
                    }
                    break;

                case OverlayType.CROSS:
                    for (int x = startX; x < stopX; x++)
                    {
                        GL.Vertex3(x + wsOffset.x, world.GetHeight(x, (start.z + stop.z) / 2) + offsetY + wsOffset.y, (start.z + stop.z) / 2 + wsOffset.z);
                        GL.Vertex3(x + 1 + wsOffset.x, world.GetHeight(x + 1, (start.z + stop.z) / 2) + offsetY + wsOffset.y, (start.z + stop.z) / 2 + wsOffset.z);
                    }

                    for (int z = startZ; z < stopZ; z++)
                    {
                        GL.Vertex3((start.x + stop.x) / 2 + wsOffset.x, world.GetHeight((start.x + stop.x) / 2, z) + offsetY + wsOffset.y, z + wsOffset.z);
                        GL.Vertex3((start.x + stop.x) / 2 + wsOffset.x, world.GetHeight((start.x + stop.x) / 2, z + 1) + offsetY + wsOffset.y, z + 1 + wsOffset.z);
                    }
                    break;

                default:
                    break;
                }



                #endregion
            }


            GL.End();
        }