示例#1
0
        private Model3DGroup CreateBackgroundModelGroup(Point3D p0, Point3D p1, Point3D p2, Point3D p3, ImageBrush image)
        {
            MeshGeometry3D mesh = new MeshGeometry3D();

            mesh.Positions.Add(p0);
            mesh.Positions.Add(p1);
            mesh.Positions.Add(p2);
            mesh.Positions.Add(p3);

            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(2);
            mesh.TriangleIndices.Add(1);

            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(3);
            mesh.TriangleIndices.Add(2);

            //Vector3D normal = Geometry3DHelper.CalculateNormal(p0, p2, p1);
            Vector3D normal = Geometry3DHelper.CalculateNormal(p0, p1, p2);

            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);

            mesh.TextureCoordinates.Add(new Point(0, 0));
            mesh.TextureCoordinates.Add(new Point(1, 0));
            mesh.TextureCoordinates.Add(new Point(1, 1));
            mesh.TextureCoordinates.Add(new Point(0, 1));

            GeometryModel3D model = new GeometryModel3D(mesh, new DiffuseMaterial(image));
            Model3DGroup    group = new Model3DGroup();

            group.Children.Add(model);
            return(group);
        }
示例#2
0
        public void Update(IEnumerable <Contracts.Agents.AgentBase> agents)
        {
            if (_selectedLayer == null)
            {
                return;
            }
            var shapes = new List <Shape>();

            Agents = null;
            var items = agents.Where(a => a.LayerId == Layers.IndexOf(SelectedLayer)).ToList();

            //var img = (System.Drawing.Bitmap)SelectedLayer.Mask.Clone();
            //using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img))
            //{
            foreach (var item in items)
            {
                //g.FillEllipse(System.Drawing.Brushes.Red, item.Position.X, item.Position.Y, (float)item.Size.X * 2.5F, (float)item.Size.Y * 2.5F);
                //g.DrawEllipse(new System.Drawing.Pen(System.Drawing.Brushes.Black, 0.2F), item.Position.X, item.Position.Y, (float)item.Size.X * 2.5F, (float)item.Size.Y * 2.5F);
                var shape = item.GetAgentShape();
                shape.Fill            = Geometry3DHelper.GetColorByGroup(item.GroupId);
                shape.RenderTransform = new TranslateTransform(item.Position.X - 5.5, item.Position.Y - 12.5);
                if (item is Contracts.Agents.VehicleAgentBase)
                {
                    double         angle = (item as Contracts.Agents.VehicleAgentBase).Angle;
                    TransformGroup tg    = new TransformGroup();
                    tg.Children.Add(new RotateTransform(angle));
                    tg.Children.Add(new TranslateTransform(item.Position.X - 5.5, item.Position.Y - 12.5));
                    shape.RenderTransform = tg;
                }
                shapes.Add(shape);
            }
            //}
            //Background = new ImageBrush(Helpers.Imaging.ImageManager.BitmapToBitmapImage(img));
            //OnPropertyChanged("Background");
            Agents = shapes;
        }
示例#3
0
        public void Update(IEnumerable <Contracts.Agents.AgentBase> agents)
        {
            //Делаем группу для отрисовки агентов
            Model3DGroup group = new Model3DGroup();

            Dictionary <ulong, MeshGeometry3D> dict = new Dictionary <ulong, MeshGeometry3D>();

            var col = agents.ToList();

            for (int i = 0; i < col.Count; i++)
            {
                if (col[i] is Contracts.Agents.VehicleAgentBase)
                {
                    group.Children.Add((col[i] as Contracts.Agents.VehicleAgentBase).GetModel());
                }
                else
                {
                    if (!dict.ContainsKey(col[i].GroupId))
                    {
                        dict.Add(col[i].GroupId, new MeshGeometry3D());
                    }
                    var mesh    = dict[col[i].GroupId];
                    int?layerId = null;
                    if (_map.Count > 1)
                    {
                        layerId = col[i].LayerId;
                    }

                    double zCoordinate = GetZCoordiante(col[i].Position, layerId);
                    col[i].AddAgentGeometry(zCoordinate, ref mesh);
                }
            }


            //Добавляем группы агентов в группу отрисовки
            foreach (var pair in dict)
            {
                GeometryModel3D geom = new GeometryModel3D(pair.Value, new DiffuseMaterial(Geometry3DHelper.GetColorByGroup(pair.Key)));
                //geom.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 180), Width / 2, Height / 2, 0);
                //geom.Transform = new TranslateTransform3D(-Width / 2, 0, -Height / 2);
                group.Children.Add(geom);
            }

            //GeometryModel3D geom = new GeometryModel3D(meshGeometry, new DiffuseMaterial(GetColorByGroup()));
            //geom.Transform = new TranslateTransform3D(-Width / 2, 0, -Height / 2);
            //group.Children.Add(geom);
            Agents = group;
            LightDirectionChanged();

            OnPropertyChanged("Agents");
        }