public ClusterVisuals(SwarmCluster[] clusters, bool showVelocity)
            {
                this.Clusters = clusters;
                _showVelocity = showVelocity;

                var visual = CreateVisual(clusters, showVelocity);

                this.Visual = visual.Item1;
                _transforms = visual.Item2;
            }
Esempio n. 2
0
        public static bool IsSame(SwarmCluster[] cluster1, SwarmCluster[] cluster2)
        {
            if (cluster1 == null && cluster2 == null)
            {
                return true;
            }
            else if (cluster1 == null || cluster2 == null)
            {
                return false;
            }
            else if (cluster1.Length != cluster2.Length)
            {
                return false;
            }

            for (int cntr = 0; cntr < cluster1.Length; cntr++)
            {
                if (cluster1[cntr].Token != cluster2[cntr].Token)
                {
                    return false;
                }
            }

            return true;
        }
            private static Tuple<Visual3D, Tuple<TranslateTransform3D, ScaleTransform3D, BillboardLine3D>[]> CreateVisual(SwarmCluster[] clusters, bool showVelocity)
            {
                Model3DGroup models = new Model3DGroup();

                // Hull Material
                MaterialGroup materials = new MaterialGroup();
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("10FFFFFF"))));
                materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("18FFFFFF")), 4));

                var transforms = new Tuple<TranslateTransform3D, ScaleTransform3D, BillboardLine3D>[clusters.Length];

                for (int cntr = 0; cntr < clusters.Length; cntr++)
                {
                    SwarmClusterInfo clusterInfo = clusters[cntr].GetCurrentInfo();

                    #region velocity

                    BillboardLine3D velocity = null;
                    if (showVelocity)
                    {
                        velocity = new BillboardLine3D()
                        {
                            Color = UtilityWPF.ColorFromHex("20FFFFFF"),
                            IsReflectiveColor = false,
                            Thickness = .2,
                        };

                        velocity.SetPoints(clusterInfo.Center, clusterInfo.Center + clusterInfo.Velocity);

                        models.Children.Add(velocity.Model);
                    }

                    #endregion

                    #region hull

                    // Model
                    GeometryModel3D hull = new GeometryModel3D();
                    hull.Material = materials;
                    hull.BackMaterial = materials;
                    hull.Geometry = UtilityWPF.GetSphere_Ico(1d, 2, true);

                    // Transform
                    Transform3DGroup transformGroup = new Transform3DGroup();

                    ScaleTransform3D scale = new ScaleTransform3D(clusterInfo.Radius, clusterInfo.Radius, clusterInfo.Radius);
                    transformGroup.Children.Add(scale);

                    TranslateTransform3D translate = new TranslateTransform3D(clusterInfo.Center.ToVector());
                    transformGroup.Children.Add(translate);

                    hull.Transform = transformGroup;

                    models.Children.Add(hull);

                    #endregion

                    transforms[cntr] = Tuple.Create(translate, scale, velocity);
                }

                ModelVisual3D visual = new ModelVisual3D();
                visual.Content = models;

                return Tuple.Create((Visual3D)visual, transforms);
            }