Esempio n. 1
0
        public Cell(Map map, int x, int y, float left, float top)
        {
            this.Map = map;
            this.Coord = new Point(x, y);
            this.Location = new Vector2(left, top);

            this.Neighbourghs = new Dictionary<int, Cell>();
            this.Neighbourghs.Add(1,null);
            this.Neighbourghs.Add(2,null);
            this.Neighbourghs.Add(3,null);
            this.Neighbourghs.Add(4,null);
            this.Neighbourghs.Add(5,null);
            this.Neighbourghs.Add(6,null);

            this.Points = new Dictionary<int, int>();
            this.Points.Add(1, -1);
            this.Points.Add(2, -1);
            this.Points.Add(3, -1);
            this.Points.Add(4, -1);
            this.Points.Add(5, -1);
            this.Points.Add(6, -1);
        }
Esempio n. 2
0
        private void InitializeMap()
        {
            Context.HeightMapRadius = 10f;

            Map = new Map(32,32);
            Map.CreateGrid();

            Map.Cells[Map.Cells.Count / 2].Height = Map.R * 10;
            Map.ElevateCell(Map.Cells[Map.Cells.Count / 2], 80f);

            Map.Cells[Map.Cells.Count / 3].Height = -Map.R * 15;
            Map.ElevateCell(Map.Cells[Map.Cells.Count / 2], 50f);

            Map.Cells[Map.Cells.Count / 3].Height = -Map.R * 15;
            Map.ElevateCell(Map.Cells[Map.Cells.Count / 3], 50f);

            Map.CalcHeightPoint();
        }
Esempio n. 3
0
        public static Vector3 NormalCell(Map map, Cell cell)
        {
            float? pickDistance = float.MaxValue;
            float pickCurDistance = 0f;
            float barycentricU = 0f;
            float barycentricV = 0f;
            Vector3 rayPosition = new Vector3(cell.Location,50f);
            Vector3 normal = Vector3.UnitZ;

            for (int i = 0; i < 4; i++)
            {
                bool intersect = RayIntersectTriangle(rayPosition, -Vector3.UnitZ,
                                    map.Points[cell.Points[listTriangle[i][0]]],
                                    map.Points[cell.Points[listTriangle[i][2]]],
                                    map.Points[cell.Points[listTriangle[i][1]]],
                                    ref pickCurDistance, ref barycentricU, ref barycentricV);

                if (intersect && pickCurDistance < pickDistance)
                {
                    pickDistance = pickCurDistance;

                    normal = NormalTriangle(
                                    map.Points[cell.Points[listTriangle[i][0]]],
                                    map.Points[cell.Points[listTriangle[i][1]]],
                                    map.Points[cell.Points[listTriangle[i][2]]]);
                }

            }

            return normal;
        }
Esempio n. 4
0
        public static float? RayIntersectCell(Vector3 rayPosition, Vector3 rayDirection, Map map, Cell cell)
        {
            float? pickDistance = float.MaxValue;
            float pickCurDistance = 0f;
            float barycentricU = 0f;
            float barycentricV = 0f;

            for (int i = 0; i < 4; i++)
            {
                bool intersect = RayIntersectTriangle(rayPosition, rayDirection,
                                    map.Points[cell.Points[listTriangle[i][0]]],
                                    map.Points[cell.Points[listTriangle[i][2]]],
                                    map.Points[cell.Points[listTriangle[i][1]]],
                                    ref pickCurDistance, ref barycentricU, ref barycentricV);

                if (intersect && pickCurDistance < pickDistance)
                {
                    pickDistance = pickCurDistance;
                }
            }

            if (pickDistance == float.MaxValue)
                return null;
            else
                return pickDistance;
        }