Пример #1
0
        private Tuple <BillboardLine3D, Visual3D> GetChaseBallVisual_Orientation()
        {
            BillboardLine3D line = new BillboardLine3D()
            {
                Color             = UtilityWPF.ColorFromHex("C03000"),
                IsReflectiveColor = false,
                Thickness         = .2,
            };

            ModelVisual3D visual = new ModelVisual3D();

            visual.Content = line.Model;

            return(new Tuple <BillboardLine3D, Visual3D>(line, visual));
        }
Пример #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));
            }
Пример #3
0
        //TODO: Rewrite this.  Make it look like a cave, or sea shell - something organic with an opening
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            ScaleTransform3D scaleTransform = new ScaleTransform3D(SCALE, SCALE, SCALE);

            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D  geometry;
            MaterialGroup    material;
            DiffuseMaterial  diffuse;
            SpecularMaterial specular;

            Transform3DGroup transformGroup = new Transform3DGroup();

            transformGroup.Children.Add(scaleTransform);

            #region Outer Shell

            geometry = new GeometryModel3D();
            material = new MaterialGroup();

            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.SwarmBay_Color));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.SwarmBay_Color));
            material.Children.Add(diffuse);

            specular = WorldColors.SwarmBay_Specular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                base.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material     = material;
            geometry.BackMaterial = material;

            transformGroup = new Transform3DGroup();
            transformGroup.Children.Add(scaleTransform);
            transformGroup.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation())));

            geometry.Geometry  = UtilityWPF.GetSphere_Ico(.5, 0, false);
            geometry.Transform = transformGroup;

            retVal.Children.Add(geometry);

            #endregion
            #region Line

            BillboardLine3D line = new BillboardLine3D();
            line.Color             = WorldColors.SwarmBay_Color;
            line.Thickness         = .05 * SCALE;
            line.IsReflectiveColor = false;
            line.FromPoint         = new Point3D(0, 0, 0);
            line.ToPoint           = new Point3D(0, 0, .55 * SCALE);

            retVal.Children.Add(line.Model);

            #endregion

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return(retVal);
        }
Пример #4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                _itemOptions = new ItemOptions();

                #region Init World

                _boundryMin = new Point3D(-BOUNDRYSIZEHALF, -BOUNDRYSIZEHALF, -BOUNDRYSIZEHALF);
                _boundryMax = new Point3D(BOUNDRYSIZEHALF, BOUNDRYSIZEHALF, BOUNDRYSIZEHALF);

                _world           = new World();
                _world.Updating += new EventHandler <WorldUpdatingArgs>(World_Updating);

                _world.SetCollisionBoundry(_boundryMin, _boundryMax);

                #endregion
                #region Materials

                _materialManager = new MaterialManager(_world);

                // Wall
                Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .1d;
                _material_Wall      = _materialManager.AddMaterial(material);

                // Ball
                material       = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Ball = _materialManager.AddMaterial(material);

                #endregion
                #region Trackball

                // Trackball
                _trackball                       = new TrackBallRoam(_camera);
                _trackball.KeyPanScale           = 15d;
                _trackball.EventSource           = grdViewPort; //NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
                _trackball.AllowZoomOnMouseWheel = true;
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft));
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.Keyboard_ASDW_In));
                _trackball.ShouldHitTestOnOrbit = true;
                //_trackball.UserMovedCamera += new EventHandler<UserMovedCameraArgs>(Trackball_UserMovedCamera);
                //_trackball.GetOrbitRadius += new EventHandler<GetOrbitRadiusArgs>(Trackball_GetOrbitRadius);

                #endregion

                #region Chased Ball

                _chasedBall = new ChasedBall();

                _chasedBall.MotionType_Position    = MotionType_Position.Stop;
                _chasedBall.MotionType_Orientation = MotionType_Orientation.Stop;

                _chasedBall.BoundrySizeChanged += new EventHandler(ChasedBall_BoundrySizeChanged);

                // Ball visual
                _chasedBallVisual           = GetChaseBallVisual_Position();
                _chasedBallTransform        = new TranslateTransform3D();
                _chasedBallVisual.Transform = _chasedBallTransform;
                _viewport.Children.Add(_chasedBallVisual);

                // Direction Visual
                var directionVisual = GetChaseBallVisual_Orientation();
                _chasedDirectionModel  = directionVisual.Item1;
                _chasedDirectionVisual = directionVisual.Item2;
                _viewport.Children.Add(_chasedDirectionVisual);

                // Panels (the act of instantiating them will update the ball's properties)
                pnlChasePosition.Content = new ChasedPosition(_chasedBall)
                {
                    Foreground = Brushes.White,
                };

                pnlChaseOrientation.Content = new ChasedOrientation(_chasedBall)
                {
                    Foreground = Brushes.White,
                };

                #endregion
                #region Debug Visuals

                // Put these on the viewport before the ball so that it is propertly semitransparent

                //TODO: Draw the bounding box.  Use XYZ colors.  This will help the user stay oriented

                #endregion
                #region Body Ball

                _bodyBall = new BodyBall(_world);

                //_bodyBall.PhysicsBody.AngularDamping = new Vector3D(.0001, .0001, .0001);
                //_bodyBall.PhysicsBody.AngularVelocity = new Vector3D(0, 0, 4 * Math.PI);

                _viewport.Children.AddRange(_bodyBall.Visuals3D);

                #endregion

                RedrawBoundry();

                _world.UnPause();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }