Exemple #1
0
        private double?GetClickDistanceNearSwarm(RayHitTestParameters clickRay)
        {
            SwarmCluster[] clusters = _botClusters.Clusters;
            if (clusters == null || clusters.Length == 0)
            {
                return(null);
            }

            Point3D?closestPoint = null;
            double  minDist      = double.MaxValue;

            foreach (SwarmCluster cluster in clusters)
            {
                SwarmClusterInfo clusterInfo = cluster.GetCurrentInfo();

                Point3D closest = Math3D.GetClosestPoint_Line_Point(clickRay.Origin, clickRay.Direction, clusterInfo.Center);
                if (Vector3D.DotProduct(closest - clickRay.Origin, clickRay.Direction) < 0)
                {
                    // It's behind the camera
                    continue;
                }

                double lenSqr = (clusterInfo.Center - closest).LengthSquared;

                if (lenSqr < minDist)
                {
                    minDist      = lenSqr;
                    closestPoint = closest;
                }
            }

            if (closestPoint == null)
            {
                return(null);
            }
            else if (Math.Sqrt(minDist) > BOUNDRYSIZE / 4)
            {
                return(null);
            }

            return((closestPoint.Value - clickRay.Origin).Length);
        }
Exemple #2
0
            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));
            }