コード例 #1
0
ファイル: SwarmBay.cs プロジェクト: charlierix/AsteroidMiner
        //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));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.SwarmBay));
            material.Children.Add(diffuse);

            specular = WorldColors.SwarmBaySpecular;
            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;
            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;
        }
コード例 #2
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);
        }
コード例 #3
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);
            }
コード例 #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);

                List<Point3D[]> innerLines, outerLines;
                _world.SetCollisionBoundry(out innerLines, out outerLines, _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);
            }
        }
コード例 #5
0
        public void AddLine(Point3D start, Point3D stop, double thickness)
        {
            //bool addedOne = false;

            if (_lineCount == null)
            {
                throw new InvalidOperationException("Must call BeginAddingLines before calling AddLine");
            }
            else if (_lineCount.Value > _lines.Count)
            {
                throw new ApplicationException("_lineCount fell out of sync");
            }
            else if (_lineCount.Value == _lines.Count)
            {
                // Create a new line
                BillboardLine3D line = new BillboardLine3D(false, _shouldSpin, _areFromToPointsUpdatedOnRegularInterval);
                line.Material = _material;

                _lines.Add(line);
                //addedOne = true;
            }

            _lineCount = _lineCount.Value + 1;

            // Whatever line was at this index now gets this position
            _lines[_lineCount.Value - 1].SetPoints(start, stop, thickness);

            //if (addedOne)
            if(_lineCount.Value > _geometry.Children.Count)
            {
                // This must be done last.  Otherwise, when the computer is stressed, the line will get rendered before it is positioned
                _geometry.Children.Add(_lines[_lineCount.Value - 1].Model);
            }
        }