Example #1
0
        public CameraController(Camera c, IListLayout l, PointLight p)
        {
            camera = (ProjectionCamera)c;
            layout = l;
            light = p;

            try
            {
                Transform3DGroup group = camera.Transform as Transform3DGroup;
                RotateTransform3D rot = group.Children[0] as RotateTransform3D;
                cameraRotX = rot.Rotation as AxisAngleRotation3D;
                rot = group.Children[1] as RotateTransform3D;
                cameraRotY = rot.Rotation as AxisAngleRotation3D;
                rot = group.Children[2] as RotateTransform3D;
                cameraRotZ = rot.Rotation as AxisAngleRotation3D;
            }
            catch (Exception )
            {
                System.Diagnostics.Debug.WriteLine("camera transformations are wrong!!!");
            }
            try
            {
                Transform3DGroup group = light.Transform as Transform3DGroup;
                RotateTransform3D rot = group.Children[0] as RotateTransform3D;
                lightRotX = rot.Rotation as AxisAngleRotation3D;
                rot = group.Children[1] as RotateTransform3D;
                lightRotY = rot.Rotation as AxisAngleRotation3D;
                rot = group.Children[2] as RotateTransform3D;
                lightRotZ = rot.Rotation as AxisAngleRotation3D;
            }
            catch (Exception )
            {
                System.Diagnostics.Debug.WriteLine("light transformations are wrong!!!");
            }
        }
Example #2
0
        private void AdjustLightIntensity(System.Windows.Media.Media3D.PointLight pointLight, double time)
        {
            Point3D lightPosition = pointLight.Position;

            double distanceFromCenter = Math.Sqrt(lightPosition.X * lightPosition.X + lightPosition.Z * lightPosition.Z);

            double maxDistance = Math.Sqrt(BoxVisual3D.Size.X * BoxVisual3D.Size.X + BoxVisual3D.Size.Z * BoxVisual3D.Size.Z);

            double relativeDistance = distanceFromCenter / maxDistance;

            // Multiply relativeDistance with 2 instead of 2 to get two cos cycles on the whole range
            // device time by 2 to get one cycle per 2 seconds
            double t = relativeDistance * 3 - time * 0.5;

            // Use Cosinus to start with 1 at the center
            // adjust to make the value between 0 and 1
            double lightIntensity = (Math.Cos(t * 2.0 * Math.PI) + 1.0) * 0.5;

            lightIntensity *= MaxLightIntensity;

            Color lightColor = Colors.White;

            lightColor = Color.FromRgb((byte)(lightColor.R * lightIntensity), (byte)(lightColor.G * lightIntensity), (byte)(lightColor.B * lightIntensity));

            pointLight.Color = lightColor;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StructureControl"/> class and sets up visual elements for rendering.
        /// </summary>
        /// <param name="pdbViewer">The PDB viewer.</param>
        internal StructureControl(PdbViewer pdbViewer)
        {
            this.pdbViewer = pdbViewer;

            NameScope.SetNameScope(this, new NameScope());

            this.viewport = new Viewport3D();
            this.viewport.ClipToBounds = true;
            this.Children.Add(this.viewport);

            this.camera = new PerspectiveCamera();
            this.camera.Position = new Point3D(0, 0, cameraOffset);
            this.viewport.Camera = this.camera;

            ModelVisual3D lightingVisual = new ModelVisual3D();
            this.viewport.Children.Add(lightingVisual);

            Model3DGroup lightingModel = new Model3DGroup();
            lightingVisual.Content = lightingModel;

            PointLight pointLight = new PointLight(Colors.White, new Point3D(-4, 4, 8));
            lightingModel.Children.Add(pointLight);

            AmbientLight ambientLight = new AmbientLight(Color.FromRgb(32, 32, 32));
            lightingModel.Children.Add(ambientLight);

            this.moleculeVisual = new ModelVisual3D();
            viewport.Children.Add(this.moleculeVisual);

            Transform3DGroup transformGroup = new Transform3DGroup();
            this.moleculeVisual.Transform = transformGroup;

            this.translateTransform = new TranslateTransform3D();
            transformGroup.Children.Add(this.translateTransform);

            this.scaleTransform = new ScaleTransform3D();
            transformGroup.Children.Add(this.scaleTransform);

            this.rotateTransform = new RotateTransform3D();
            this.rotateTransform.Rotation = new QuaternionRotation3D();
            transformGroup.Children.Add(this.rotateTransform);

            this.selectionRectangle = new Rectangle();
            this.selectionRectangle.Stroke = Brushes.White;
            this.selectionRectangle.Fill = new SolidColorBrush(Color.FromArgb(32, 255, 255, 255));
            this.selectionRectangle.Visibility = Visibility.Hidden;
            this.Children.Add(this.selectionRectangle);

            this.testLabel = new Label();
            this.testLabel.Foreground = Brushes.White;
            this.testLabel.FontSize = 20;
            this.testLabel.HorizontalAlignment = HorizontalAlignment.Left;
            this.testLabel.VerticalAlignment = VerticalAlignment.Center;
            this.Children.Add(this.testLabel);

            this.clip = 1;
            this.slab = 0;
            this.UpdateClipping();
        }
Example #4
0
        private void CreateLights()
        {
            var lightsModelGroup = new Model3DGroup();

            double totalWidth  = BoxVisual3D.Size.X;
            double totalHeight = BoxVisual3D.Size.Z;

            double usedWidth  = totalWidth * 0.9;
            double usedHeight = totalHeight * 0.9;

            double halfWidth  = usedWidth / 2;
            double halfHeight = usedHeight / 2;


            double xStep = usedWidth / (double)XLightsCount;
            double yStep = usedHeight / (double)YLightsCount;

            double xStart = -halfWidth + xStep / 2;
            double yStart = -halfHeight + yStep / 2;

            double lightHeight = BoxVisual3D.CenterPosition.Y + BoxVisual3D.Size.Y / 2 + 5;

            double xPos = xStart;

            for (int x = 0; x < XLightsCount; x++)
            {
                double yPos = yStart;

                for (int y = 0; y < YLightsCount; y++)
                {
                    Point3D lightPosition = new Point3D(xPos, lightHeight, yPos);

                    Color lightColor = Colors.White;
                    lightColor = Color.FromRgb((byte)(lightColor.R * MaxLightIntensity), (byte)(lightColor.G * MaxLightIntensity), (byte)(lightColor.B * MaxLightIntensity));

                    var pointLight = new System.Windows.Media.Media3D.PointLight(lightColor, lightPosition);
                    pointLight.Range = xStep * 6; // Defining the range improves performance with skipping lighting calculations for pixels that are out of range

                    lightsModelGroup.Children.Add(pointLight);

                    yPos += yStep;
                }

                xPos += xStep;
            }

            LightsModelVisual.Content = lightsModelGroup;

            AdjustAllLightsIntensity(0);
        }
Example #5
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 9 "..\..\MainWindow.xaml"
                ((View.MainWindow)(target)).KeyDown += new System.Windows.Input.KeyEventHandler(this.MainWindow_KeyDown);

            #line default
            #line hidden

            #line 9 "..\..\MainWindow.xaml"
                ((View.MainWindow)(target)).Closing += new System.ComponentModel.CancelEventHandler(this.MainWindow_Closing);

            #line default
            #line hidden
                return;

            case 2:
                this.viewport = ((System.Windows.Controls.Viewport3D)(target));

            #line 15 "..\..\MainWindow.xaml"
                this.viewport.MouseMove += new System.Windows.Input.MouseEventHandler(this.Viewport_MouseMove);

            #line default
            #line hidden

            #line 15 "..\..\MainWindow.xaml"
                this.viewport.LostFocus += new System.Windows.RoutedEventHandler(this.viewport_LostFocus);

            #line default
            #line hidden
                return;

            case 3:
                this.cameraMain = ((System.Windows.Media.Media3D.PerspectiveCamera)(target));
                return;

            case 4:
                this.lightAmbient = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 5:
                this.lightKey = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 6:
                this.lightSide = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 7:
                this.lightPoint = ((System.Windows.Media.Media3D.PointLight)(target));
                return;

            case 8:
                this.modelBackground = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 9:
                this.modelFloor = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 10:
                this.modelPlayCursor = ((System.Windows.Media.Media3D.ModelUIElement3D)(target));
                return;

            case 11:
                this.rotatorPointer = ((System.Windows.Media.Media3D.RotateTransform3D)(target));
                return;

            case 12:
                this.translatorPointer = ((System.Windows.Media.Media3D.TranslateTransform3D)(target));
                return;

            case 13:
                this.groupPlayers3D = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 14:
                this.groupFood3D = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 15:

            #line 152 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.DockPanel)(target)).Loaded += new System.Windows.RoutedEventHandler(this.MainWindow_Loaded);

            #line default
            #line hidden
                return;

            case 16:
                this.lblPlayerName = ((System.Windows.Controls.Label)(target));
                return;

            case 17:
                this.lblMass = ((System.Windows.Controls.Label)(target));
                return;

            case 18:
                this.lblFoodCount = ((System.Windows.Controls.Label)(target));
                return;

            case 19:
                this.lblPlayerCount = ((System.Windows.Controls.Label)(target));
                return;

            case 20:
                this.lblPlayerPosition = ((System.Windows.Controls.Label)(target));
                return;

            case 21:
                this.bttnDisconnect = ((System.Windows.Controls.Button)(target));

            #line 188 "..\..\MainWindow.xaml"
                this.bttnDisconnect.Click += new System.Windows.RoutedEventHandler(this.DisconnectButton_Clicked);

            #line default
            #line hidden
                return;

            case 22:
                this.txtbxMessages = ((System.Windows.Controls.TextBox)(target));
                return;
            }
            this._contentLoaded = true;
        }
Example #6
0
        public void ResetLights()
        {
            //<AmbientLight Color="White" />
            //<DirectionalLight Color="White" Direction="-1,-1,-1" />
            //<PointLight Color="White" ConstantAttenuation="1" LinearAttenuation="1" Position="0,0,0" QuadraticAttenuation="1" Range="0" />
            //<SpotLight Color="White" ConstantAttenuation="1" Direction="-1,-1,-1" InnerConeAngle="10" LinearAttenuation="1" OuterConeAngle="10" Position="0,0,0" QuadraticAttenuation="1" Range="0" />
            lights.Children.Clear () ;

            MItDag dagIterator =new MItDag (MItDag.TraversalType.kDepthFirst, MFn.Type.kLight) ;
            for ( ; !dagIterator.isDone ; dagIterator.next () ) {
                MDagPath lightPath =new MDagPath () ;
                dagIterator.getPath (lightPath) ;

                MFnLight light =new MFnLight (lightPath) ;
                bool isAmbient =light.lightAmbient ;
                MColor mcolor =light.color ;
                Color color =Color.FromScRgb (1.0f, mcolor.r, mcolor.g, mcolor.b) ;
                if ( isAmbient ) {
                    AmbientLight ambient =new AmbientLight (color) ;
                    lights.Children.Add (ambient) ;
                    continue ;
                }

                MFloatVector lightDirection =light.lightDirection (0, MSpace.Space.kWorld) ;
                Vector3D direction =new Vector3D (lightDirection.x, lightDirection.y, lightDirection.z) ;
                bool isDiffuse =light.lightDiffuse ;
                try {
                    MFnDirectionalLight dirLight =new MFnDirectionalLight (lightPath) ;
                    DirectionalLight directional =new DirectionalLight (color, direction) ;
                    lights.Children.Add (directional) ;
                    continue ;
                } catch {
                }

                MObject transformNode =lightPath.transform ;
                MFnDagNode transform =new MFnDagNode (transformNode) ;
                MTransformationMatrix matrix =new MTransformationMatrix (transform.transformationMatrix) ;
                double [] threeDoubles =new double [3] ;
                int rOrder =0 ; //MTransformationMatrix.RotationOrder rOrder ;
                matrix.getRotation (threeDoubles, out rOrder, MSpace.Space.kWorld) ;
                matrix.getScale (threeDoubles, MSpace.Space.kWorld) ;
                MVector pos =matrix.getTranslation (MSpace.Space.kWorld) ;
                Point3D position =new Point3D (pos.x, pos.y, pos.z) ;
                try {
                    MFnPointLight pointLight =new MFnPointLight (lightPath) ;
                    PointLight point =new PointLight (color, position) ;
                    //point.ConstantAttenuation =pointLight. ; // LinearAttenuation / QuadraticAttenuation
                    //point.Range =pointLight.rayDepthLimit ;
                    lights.Children.Add (point) ;
                    continue ;
                } catch {
                }

                try {
                    MFnSpotLight spotLight =new MFnSpotLight (lightPath) ;
                    MAngle InnerConeAngle =new MAngle (spotLight.coneAngle) ;
                    MAngle OuterConeAngle =new MAngle (spotLight.penumbraAngle) ;
                    SpotLight spot =new SpotLight (color, position, direction, OuterConeAngle.asDegrees, InnerConeAngle.asDegrees) ;
                    spot.ConstantAttenuation =spotLight.dropOff ; // LinearAttenuation / QuadraticAttenuation
                    //spot.Range =spotLight.rayDepthLimit ;
                    lights.Children.Add (spot) ;
                    continue ;
                } catch {
                }
            }
        }
        public void Add(DesignPart part)
        {
            HideModifiers();

            _parts.Add(part);

            part.Part3D.IsSelected = true;

            if (_parts.Count > 1)
            {
                _orientation = _options.DefaultOrientation;
            }

            //No need to listen to this event anymore, the transform changed is now called directly by this class's propert sets
            //part.Part3D.TransformChanged += new EventHandler(Part3D_TransformChanged);

            // Point Light
            PointLight pointLight = new PointLight();
            pointLight.Color = _options.EditorColors.SelectionLightColor;
            pointLight.QuadraticAttenuation = 1d;
            pointLight.Range = 10d;
            ModelVisual3D pointLightModel = new ModelVisual3D();
            pointLightModel.Content = pointLight;
            _viewport.Children.Add(pointLightModel);
            _pointLights.Add(pointLightModel);

            if (!this.IsLocked)
            {
                ShowModifiers();
            }

            // Move the visuals to be relative to the part
            TransformChanged();
        }
Example #8
0
        private static void GetModel_Rod_Moon(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            const double PERCENT = 1;

            Random rand = StaticRandom.GetRandomForThread();
            var from = dna.KeyValues;
            var to = finalDNA.KeyValues;

            #region Shaft

            GeometryModel3D shaft = new GeometryModel3D();

            shaft.Material = materials.Handle_Moon;
            shaft.BackMaterial = shaft.Material;

            double maxRad1 = WeaponDNA.GetKeyValue("maxRad1", from, to, rand.NextDouble(.7, 1.02));
            double maxRad2 = WeaponDNA.GetKeyValue("maxRad2", from, to, rand.NextDouble(.7, 1.02));
            double maxRad12 = Math.Max(maxRad1, maxRad2);       // this is used in several places

            List<TubeRingBase> rings = new List<TubeRingBase>();

            rings.Add(new TubeRingRegularPolygon(0, false, maxRad1 * .4, maxRad1 * .4, true));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube1", from, to, rand.NextPercent(.25, PERCENT)), false, maxRad1 * .8, maxRad1 * .8, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube2", from, to, rand.NextPercent(.3, PERCENT)), false, maxRad1 * .85, maxRad1 * .85, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube3", from, to, rand.NextPercent(.75, PERCENT)), false, maxRad1 * .6, maxRad1 * .6, false));

            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube4", from, to, rand.NextPercent(20, PERCENT)), false, maxRad2 * .8, maxRad2 * .8, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube5", from, to, rand.NextPercent(1, PERCENT)), false, maxRad2 * .9, maxRad2 * .9, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube6", from, to, rand.NextPercent(1, PERCENT)), false, maxRad2 * 1, maxRad2 * 1, false));
            rings.Add(new TubeRingDome(WeaponDNA.GetKeyValue("tube7", from, to, rand.NextPercent(2.5, PERCENT)), false, 4));

            rings = TubeRingBase.FitNewSize(rings, maxRad12 * dna.Radius, maxRad12 * dna.Radius, dna.Length);

            shaft.Geometry = UtilityWPF.GetMultiRingedTube(10, rings, true, true, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90)));      // the tube builds along z, but this class wants along x

            #endregion

            // Number of gems
            int numIfNew = 0;
            if (rand.NextDouble() > .66d)       // only 33% will get gems
            {
                // Of the handles with gems, only 5% will get 2
                numIfNew = rand.NextDouble() > .95 ? 2 : 1;
            }

            int numGems = Convert.ToInt32(WeaponDNA.GetKeyValue("numGems", from, to, numIfNew));

            if (numGems == 0)
            {
                geometries.Children.Add(shaft);
                return;
            }

            #region Gems

            List<double> percents = new List<double>();

            for (int cntr = 0; cntr < numGems; cntr++)
            {
                string keyPrefix = "gem" + cntr.ToString();

                // Get a placement for this gem
                double percentIfNew = 0;
                do
                {
                    percentIfNew = rand.NextDouble(.15, .85);

                    if (percents.Count == 0)
                    {
                        break;
                    }
                } while (percents.Any(o => Math.Abs(percentIfNew - o) < .15));

                double percent = WeaponDNA.GetKeyValue(keyPrefix + "Percent", from, to, percentIfNew);

                percents.Add(percent);

                // Gem
                GeometryModel3D gem = new GeometryModel3D();

                gem.Material = materials.Handle_MoonGem;
                gem.BackMaterial = gem.Material;

                double width = WeaponDNA.GetKeyValue(keyPrefix + "Width", from, to, rand.NextDouble(maxRad12 * 1d, maxRad12 * 1.4d));

                gem.Geometry = UtilityWPF.GetSphere_LatLon(5, dna.Radius * width);
                Point3D position = new Point3D((dna.Length * percent) - (dna.Length / 2d), 0, 0);
                gem.Transform = new TranslateTransform3D(position.ToVector());

                // Light
                PointLight pointLight = new PointLight(materials.Handle_MoonGemLight, position);
                UtilityWPF.SetAttenuation(pointLight, dna.Radius * 120d, .1d);

                geometries.Children.Add(pointLight);
                geometries.Children.Add(gem);
            }

            // Adding this after so that you don't see the shaft through the gems
            geometries.Children.Add(shaft);

            #endregion
        }
Example #9
0
        private void CreateVisual()
        {
            _modelGroup = new Model3DGroup();

            #region Light

            Color lightColor = UtilityWPF.ColorFromHex("FF0000");
            _light = new PointLight(lightColor, new Point3D(0, 0, 0));
            UtilityWPF.SetAttenuation(_light, _bot.Radius * .01, .1d);

            _modelGroup.Children.Add(_light);

            #endregion

            ////TODO: Don't just make one graphic.  Make sprites, a light - maybe like a fountain
            //DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("40808080")));

            //GeometryModel3D geometry = new GeometryModel3D();
            //geometry.Material = material;
            //geometry.BackMaterial = material;
            ////geometry.Geometry = UtilityWPF.GetSphere(2, 1);
            //geometry.Geometry = UtilityWPF.GetCylinder_AlongX(10, 1, .75);

            _scale = new ScaleTransform3D(1, 1, 1);
            //geometry.Transform = _scale;

            //_modelGroup.Children.Add(geometry);

            Transform3DGroup transform = new Transform3DGroup();

            _rotate = new QuaternionRotation3D(Quaternion.Identity);
            transform.Children.Add(new RotateTransform3D(_rotate));

            _translate = new TranslateTransform3D(0, 0, 0);
            transform.Children.Add(_translate);

            _modelGroup.Transform = transform;

            // Visual
            _visual = new ModelVisual3D()
            {
                Content = _modelGroup
            };

            _bot.PhysicsBody.BodyMoved += PhysicsBody_BodyMoved;
        }
Example #10
0
        public static Model3D GetNewVisual(MineralType mineralType, SharedVisuals sharedVisuals = null, double scale = 1d)
        {
            if (sharedVisuals == null)
            {
                sharedVisuals = _sharedVisuals.Value;
            }

            MineralStats stats = GetSettingsForMineralType(mineralType);

            Model3DGroup retVal = new Model3DGroup();

            // Material
            MaterialGroup materials = new MaterialGroup();
            if (stats.DiffuseColor.A > 0)
            {
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(stats.DiffuseColor)));
            }

            if (stats.SpecularColor.A > 0)
            {
                materials.Children.Add(new SpecularMaterial(new SolidColorBrush(stats.SpecularColor), stats.SpecularPower));
            }

            if (stats.EmissiveColor.A > 0)
            {
                materials.Children.Add(new EmissiveMaterial(new SolidColorBrush(stats.EmissiveColor)));
            }

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry = sharedVisuals.GetMineralMesh(mineralType);

            retVal.Children.Add(geometry);

            if (mineralType == MineralType.Rixium)
            {
                #region Rixium Visuals

                // These need to be added after the main crystal, because they are semitransparent

                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, -.6), .38, .5, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, -.3), .44, .75, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, 0), .5, 1, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, .3), .44, .75, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, .6), .38, .5, sharedVisuals));

                //TODO:  Look at the global lighting options
                PointLight pointLight = new PointLight();
                pointLight.Color = Color.FromArgb(255, 54, 147, 168);
                pointLight.Range = 20;
                pointLight.LinearAttenuation = .33;
                retVal.Children.Add(pointLight);

                #endregion
            }

            geometry.Transform = new ScaleTransform3D(scale, scale, scale);

            return retVal;
        }
Example #11
0
        private void InitializeLight()
        {
            _hoverLight = new PointLight(Colors.White, new Point3D(0, 0, 0));
            UtilityWPF.SetAttenuation(_hoverLight, _camera.Position.ToVector().Length * 2d, .95d);

            _selectedLight = new AmbientLight(UtilityWPF.ColorFromHex("808080"));
        }
Example #12
0
        public Window2(CModel cmodel, bool bDebugging)
        {
            InitializeComponent();

              if (cmodel != null)
              {
              Model3DGroup gr = new Model3DGroup();
              //gr.Children.Add(new AmbientLight());

              // Default color
              SolidColorBrush brushDefault = new SolidColorBrush(Color.FromRgb(255, 0, 0));

              EGCS eGCS = EGCS.eGCSLeftHanded;
              //EGCS eGCS = EGCS.eGCSRightHanded;

              // Global coordinate system - axis
              ScreenSpaceLines3D sAxisX_3D = new ScreenSpaceLines3D();
              ScreenSpaceLines3D sAxisY_3D = new ScreenSpaceLines3D();
              ScreenSpaceLines3D sAxisZ_3D = new ScreenSpaceLines3D();
              Point3D pGCS_centre = new Point3D(0,0,0);
              Point3D pAxisX = new Point3D(1, 0, 0);
              Point3D pAxisY = new Point3D(0, 1, 0);
              Point3D pAxisZ = new Point3D(0, 0, 1);

              sAxisX_3D.Points.Add(pGCS_centre);
              sAxisX_3D.Points.Add(pAxisX);
              sAxisX_3D.Color = Colors.Red;
              sAxisX_3D.Thickness = 2;

              sAxisY_3D.Points.Add(pGCS_centre);
              sAxisY_3D.Points.Add(pAxisY);
              sAxisY_3D.Color = Colors.Green;
              sAxisY_3D.Thickness = 2;

              sAxisZ_3D.Points.Add(pGCS_centre);
              sAxisZ_3D.Points.Add(pAxisZ);
              sAxisZ_3D.Color = Colors.Blue;
              sAxisZ_3D.Thickness = 2;

              //I made ViewPort public property to Access ViewPort object inside TrackPort3D
              //to ViewPort add 3 children (3 axis)
              _trackport.ViewPort.Children.Add(sAxisX_3D);
              _trackport.ViewPort.Children.Add(sAxisY_3D);
              _trackport.ViewPort.Children.Add(sAxisZ_3D);

              // Check that real model exists and create model geometry
              if (cmodel != null)
              {
              if (cmodel.m_arrMembers != null) // Some members exist
              {
                  // Auxialiary for generation of colors numbers
                  float j = 0;

                  // Model Group of Members
                  // Prepare member model
                  for (int i = 0; i < cmodel.m_arrMembers.Length; i++) // !!! BUG pocet prvkov sa nacitava z xls aj z prazdnych riadkov pokial su nejako formatovane / nie default
                  {
                      if (cmodel.m_arrMembers[i] != null &&
                          cmodel.m_arrMembers[i].NodeStart != null &&
                          cmodel.m_arrMembers[i].NodeEnd != null &&
                          cmodel.m_arrMembers[i].CrScStart != null) // Member object is valid (not empty)
                      {
                          if (bDebugging)
                          {
                              System.Console.Write("\n" + "Member ID:" + (i + 1).ToString() + "\n"); // Write Member ID in console window
                              System.Console.Write("Start Node ID:" + cmodel.m_arrMembers[i].NodeStart.ID.ToString() + "\n"); // Write Start Node ID and coordinates in console window
                              System.Console.Write(cmodel.m_arrMembers[i].NodeStart.X.ToString() + "\t" + cmodel.m_arrMembers[i].NodeStart.Y.ToString() + "\t" + cmodel.m_arrMembers[i].NodeStart.Z.ToString() + "\n");
                              System.Console.Write("End Node ID:" + cmodel.m_arrMembers[i].NodeEnd.ID.ToString() + "\n");     // Write   End Node ID and coordinates in console window
                              System.Console.Write(cmodel.m_arrMembers[i].NodeEnd.X.ToString() + "\t" + cmodel.m_arrMembers[i].NodeEnd.Y.ToString() + "\t" + cmodel.m_arrMembers[i].NodeEnd.Z.ToString() + "\n\n");

                              cmodel.m_arrMembers[i].BIsDebugging = bDebugging;
                          }

                          if (cmodel.m_arrMembers[i].CrScStart.CrScPointsOut != null) // CCrSc is abstract without geometrical properties (dimensions), only centroid line could be displayed
                          {
                              // Member material color
                              byte R = (byte)(250);
                              byte G = (byte)(240);
                              byte B = (byte)(230);

                              SolidColorBrush br = new SolidColorBrush(Color.FromRgb(R, G, B)); // Material color
                              br.Opacity = 0.8;

                              // Set different color for each member
                              bool bDiffMemberColors = false;

                              if (bDiffMemberColors)
                              {
                                  if (j < 20) // 20*10 = 200, 200 + 55 - 255 (maxium number of color)
                                  {
                                      br.Color = Color.FromRgb((byte)(55 + j * 10), (byte)(55 + j * 7), (byte)(55 + j * 5));
                                      j++;
                                  }
                                  else
                                  {
                                      j = 0;
                                  }
                              }

                              bool bFastRendering = false;

                              if (bFastRendering ||
                                  (cmodel.m_arrMembers[i].CrScStart.TriangleIndicesFrontSide == null ||
                                      cmodel.m_arrMembers[i].CrScStart.TriangleIndicesShell == null ||
                                      cmodel.m_arrMembers[i].CrScStart.TriangleIndicesBackSide == null)
                                   ) // Check if are particular surfaces defined
                              {
                                  // Create Member model - one geometry model
                                  // GeometryModel3D memberModel3D;
                                  // Add current member model to the model group
                                  gr.Children.Add((Model3D)cmodel.m_arrMembers[i].getG_M_3D_Member(eGCS, br));
                              }
                              else
                              {
                                  // Create Member model - consist of 3 geometry models (member is one model group)
                                  // Model3DGroup memberModel3D;
                                  // Add current member model to the model group

                                  SolidColorBrush br1 = new SolidColorBrush(Color.FromRgb(255, 64, 64)); // Material color - Front Side (red)
                                  SolidColorBrush br2 = new SolidColorBrush(Color.FromRgb(141, 238, 238)); // Material color - Shell (red)
                                  SolidColorBrush br3 = new SolidColorBrush(Color.FromRgb(238, 154, 73)); // Material color - Back Side (orange)
                                  br1.Opacity = br3.Opacity = 0.8;
                                  br2.Opacity = 0.4;
                                  gr.Children.Add(cmodel.m_arrMembers[i].getM_3D_G_Member(eGCS, br1, br2, br3));
                              }
                          }
                          else
                          {
                          // Display axis line, member is not valid to display in 3D
                          }
                      }
                  }
              }

              if (cmodel.m_arrGOAreas != null) // Some areas exist
              {
                  // Model Groups of Areas

              }

              if (cmodel.m_arrGOVolumes != null) // Some volumes exist
              {
                  // Model Groups of Volumes
                  for (int i = 0; i < cmodel.m_arrGOVolumes.Length; i++)
                  {
                      if (cmodel.m_arrGOVolumes[i] != null &&
                          cmodel.m_arrGOVolumes[i].m_pControlPoint != null &&
                          cmodel.m_arrGOVolumes[i].BIsDisplayed == true) // Volume object is valid (not empty) and should be displayed
                      {
                          // Get shape - prism , sphere, ...
                          gr.Children.Add(cmodel.m_arrGOVolumes[i].CreateM_3D_G_Volume_8Edges()); // Add solid to model group
                      }
                  }
              }

              if (cmodel.m_arrGOStrWindows != null) // Some windows exist
              {
                  // Model Groups of Windows
                  for (int i = 0; i < cmodel.m_arrGOStrWindows.Length; i++)
                  {
                      if (cmodel.m_arrGOStrWindows[i] != null &&
                          cmodel.m_arrGOStrWindows[i].m_pControlPoint != null &&
                          cmodel.m_arrGOStrWindows[i].BIsDisplayed == true) // Volume object is valid (not empty) and should be displayed
                      {
                          if (cmodel.m_arrGOStrWindows[i].EShapeType == EWindowShapeType.eClassic)
                              gr.Children.Add(cmodel.m_arrGOStrWindows[i].CreateM_3D_G_Window()); // Add solid to model group
                          else
                          {
                              //Exception - not implemented
                          }
                      }
                  }
              }

              if (cmodel.m_arrNSupports != null) // Some nodal supports exist
              {
                  // Model Groups of Nodal Suports
                  for (int i = 0; i < cmodel.m_arrNSupports.Length; i++)
                  {
                      if (cmodel.m_arrNSupports[i] != null && cmodel.m_arrNSupports[i].BIsDisplayed == true) // Support object is valid (not empty) and should be displayed
                      {
                          gr.Children.Add(cmodel.m_arrNSupports[i].CreateM_3D_G_NSupport()); // Add solid to model group

                          // Set support for all assigned nodes

                      }
                  }
              }

              if (cmodel.m_arrNReleases != null) // Some member release exist
              {
                  // Model Groups of Member Releases
                  for (int i = 0; i < cmodel.m_arrNReleases.Length; i++)
                  {
                      if (cmodel.m_arrNReleases[i] != null && cmodel.m_arrNReleases[i].BIsDisplayed == true) // Support object is valid (not empty) and should be displayed
                      {
                          /*
                          for (int j = 0; j < cmodel.m_arrNReleases[i].m_iMembCollection.Length; j++) // Set release for all assigned members (member nodes)
                          {
                              Model3DGroup model_gr = new Model3DGroup();
                              model_gr = cmodel.m_arrNReleases[i].CreateM_3D_G_MNRelease();
                              // Transform modelgroup from LCS to GCS
                              model_gr = cmodel.m_arrNReleases[i].Transform3D_OnMemberEntity_fromLCStoGCS(model_gr, cmodel.m_arrMembers[cmodel.m_arrNReleases[i].m_iMembCollection[j]]);

                              gr.Children.Add(model_gr); // Add Release to model group
                          }*/

                          Model3DGroup model_gr = new Model3DGroup();
                          model_gr = cmodel.m_arrNReleases[i].CreateM_3D_G_MNRelease();
                          // Transform modelgroup from LCS to GCS
                          model_gr = cmodel.m_arrNReleases[i].Transform3D_OnMemberEntity_fromLCStoGCS(model_gr, cmodel.m_arrNReleases[i].Member);

                          gr.Children.Add(model_gr); // Add Release to model group

                      }
                  }
              }

              if (cmodel.m_arrNLoads != null) // Some nodal loads exist
              {
                  // Model Groups of Nodal Loads
                  for (int i = 0; i < cmodel.m_arrNLoads.Length; i++)
                  {
                      if (cmodel.m_arrNLoads[i] != null && cmodel.m_arrNLoads[i].BIsDisplayed == true) // Load object is valid (not empty) and should be displayed
                      {
                          gr.Children.Add(cmodel.m_arrNLoads[i].CreateM_3D_G_Load()); // Add to model group

                          // Set load for all assigned nodes

                      }
                  }
              }

              if (cmodel.m_arrMLoads != null) // Some member loads exist
              {
                  // Model Groups of Member Loads
                  for (int i = 0; i < cmodel.m_arrMLoads.Length; i++)
                  {
                      if (cmodel.m_arrMLoads[i] != null && cmodel.m_arrMLoads[i].BIsDisplayed == true) // Load object is valid (not empty) and should be displayed
                      {
                          Model3DGroup model_gr = new Model3DGroup();
                          model_gr = cmodel.m_arrMLoads[i].CreateM_3D_G_Load();
                          // Transform modelgroup from LCS to GCS
                          model_gr = cmodel.m_arrMLoads[i].Transform3D_OnMemberEntity_fromLCStoGCS(model_gr, cmodel.m_arrMLoads[i].Member);

                          gr.Children.Add(model_gr); // Add Release to model group

                          // Set load for all assigned member

                      }
                  }
              }

              /*
                The following lights derive from the base class Light:
                AmbientLight : Provides ambient lighting that illuminates all objects uniformly regardless of their location or orientation.
                DirectionalLight : Illuminates like a distant light source. Directional lights have a Direction specified as a Vector3D, but no specified location.
                PointLight : Illuminates like a nearby light source. PointLights have a position and cast light from that position. Objects in the scene are illuminated depending on their position and distance with respect to the light. PointLightBase exposes a Range property, which determines a distance beyond which models will not be illuminated by the light. PointLight also exposes attenuation properties which determine how the light's intensity diminishes over distance. You can specify constant, linear, or quadratic interpolations for the light's attenuation.
                SpotLight : Inherits from PointLight. Spotlights illuminate like PointLight and have both position and direction. They project light in a cone-shaped area set by InnerConeAngle and OuterConeAngle properties, specified in degrees.
              */

              // Directional Light
              DirectionalLight Dir_Light = new DirectionalLight();
              Dir_Light.Color = Colors.White;
              Dir_Light.Direction = new Vector3D(0, 0, -1);
              gr.Children.Add(Dir_Light);

              // Point light values
              PointLight Point_Light = new PointLight();
              Point_Light.Position = new Point3D(0, 0, 30);
              Point_Light.Color = System.Windows.Media.Brushes.White.Color;
              Point_Light.Range = 30.0;
              Point_Light.ConstantAttenuation=0;
              Point_Light.LinearAttenuation=0;
              Point_Light.QuadraticAttenuation = 0.2f;
              Point_Light.ConstantAttenuation = 5.0;
              gr.Children.Add(Point_Light);

              SpotLight Spot_Light = new SpotLight();
              Spot_Light.InnerConeAngle = 30;
              Spot_Light.OuterConeAngle = 30;
              Spot_Light.Color = System.Windows.Media.Brushes.White.Color;
              Spot_Light.Direction = new Vector3D(0, 0, -1);
              Spot_Light.Position = new Point3D(8.5, 8.5, 20);
              Spot_Light.Range = 30;
              gr.Children.Add(Spot_Light);

              //Set Ambient Light
              AmbientLight Ambient_Light = new AmbientLight();
              Ambient_Light.Color = Color.FromRgb(250, 250, 230);
              gr.Children.Add(new AmbientLight());

              if (cmodel.m_arrGOLines != null) // Some lines exist
              {
                  Point3D solidCenter = new Point3D(-5, 0, 0);

                  float fa = 0.5f;

                  Point3D p0 = new Point3D(-fa, -fa, -fa);
                  Point3D p1 = new Point3D(fa, -fa, -fa);
                  Point3D p2 = new Point3D(fa, fa, -fa);
                  Point3D p3 = new Point3D(-fa, fa, -fa);
                  Point3D p4 = new Point3D(-fa, -fa, fa);
                  Point3D p5 = new Point3D(fa, -fa, fa);
                  Point3D p6 = new Point3D(fa, fa, fa);
                  Point3D p7 = new Point3D(-fa, fa, fa);

                  // Lines

                  ScreenSpaceLines3D line1 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line2 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line3 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line4 = new ScreenSpaceLines3D();

                  Color lineColor = Color.FromRgb(250, 30, 30);
                  line1.Color = lineColor;
                  line1.Points.Add(p0);
                  line1.Points.Add(p1);

                  line2.Color = lineColor;
                  line2.Points.Add(p1);
                  line2.Points.Add(p2);

                  line3.Color = lineColor;
                  line3.Points.Add(p2);
                  line3.Points.Add(p3);

                  line4.Color = lineColor;
                  line4.Points.Add(p3);
                  line4.Points.Add(p0);

                  _trackport.ViewPort.Children.Add(line1);
                  _trackport.ViewPort.Children.Add(line2);
                  _trackport.ViewPort.Children.Add(line3);
                  _trackport.ViewPort.Children.Add(line4);

                  ScreenSpaceLines3D line5 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line6 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line7 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line8 = new ScreenSpaceLines3D();

                  line5.Color = lineColor;
                  line5.Points.Add(p4);
                  line5.Points.Add(p5);

                  line6.Color = lineColor;
                  line6.Points.Add(p5);
                  line6.Points.Add(p6);

                  line7.Color = lineColor;
                  line7.Points.Add(p6);
                  line7.Points.Add(p7);

                  line8.Color = lineColor;
                  line8.Points.Add(p7);
                  line8.Points.Add(p4);

                  _trackport.ViewPort.Children.Add(line5);
                  _trackport.ViewPort.Children.Add(line6);
                  _trackport.ViewPort.Children.Add(line7);
                  _trackport.ViewPort.Children.Add(line8);

                  ScreenSpaceLines3D line09 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line10 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line11 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line12 = new ScreenSpaceLines3D();

                  line09.Color = lineColor;
                  line09.Points.Add(p0);
                  line09.Points.Add(p4);

                  line10.Color = lineColor;
                  line10.Points.Add(p1);
                  line10.Points.Add(p5);

                  line11.Color = lineColor;
                  line11.Points.Add(p2);
                  line11.Points.Add(p6);

                  line12.Color = lineColor;
                  line12.Points.Add(p3);
                  line12.Points.Add(p7);

                  _trackport.ViewPort.Children.Add(line09);
                  _trackport.ViewPort.Children.Add(line10);
                  _trackport.ViewPort.Children.Add(line11);
                  _trackport.ViewPort.Children.Add(line12);
              }
              }

              // Get model centre
              float fTempMax_X;
              float fTempMin_X;
              float fTempMax_Y;
              float fTempMin_Y;
              float fTempMax_Z;
              float fTempMin_Z;

              CalculateModelLimits(cmodel, out fTempMax_X, out fTempMin_X, out fTempMax_Y, out fTempMin_Y, out fTempMax_Z, out fTempMin_Z);

              float fModel_Length_X = fTempMax_X - fTempMin_X;
              float fModel_Length_Y = fTempMax_Y - fTempMin_Y;
              float fModel_Length_Z = fTempMax_Z - fTempMin_Z;

              Point3D pModelGeomCentre = new Point3D(fModel_Length_X / 2.0f, fModel_Length_Y / 2.0f, fModel_Length_Z / 2.0f);

              Point3D cameraPosition = new Point3D(pModelGeomCentre.X, pModelGeomCentre.Y + 300, pModelGeomCentre.Z + 100);

              //SolidColorBrush brush = new SolidColorBrush(Color.FromRgb(255, 255, 0));
              //GeometryModel3D model = getGeometryModel3D(brush, obj_CrSc, new Point3D(10, 10, 10), new Point3D(500, 300, 200));
              //gr.Children.Add(model);

              ////Point3D cameraPosition = ((MeshGeometry3D)model.Geometry).Positions[0];
              ////cameraPosition.Z -= 1000;

              //brush = new SolidColorBrush(Color.FromRgb(0, 255, 0));
              //model = getGeometryModel3D(brush, obj_CrSc, new Point3D(110, 110, 10), new Point3D(600, 400, 200));
              //gr.Children.Add(model);

              //IMPORTANT: this is the best way to do it, but we can't use it because of trackball
              //because camera is set by trackball Transform this.Camera.Transform = _trackball.Transform;
              //and headlite too:  this.Headlight.Transform = _trackball.Transform;

              _trackport.PerspectiveCamera.Position = cameraPosition;
              //_trackport.PerspectiveCamera.LookDirection = new Vector3D(cameraPosition.X, cameraPosition.Y, cameraPosition.Z - 100);

              _trackport.PerspectiveCamera.LookDirection = new Vector3D(0, -1, -0.2);

              _trackport.Model = (Model3D)gr;

              _trackport.SetupScene();
              }
        }
Example #13
0
        private void InitializeGraphics()
        {
            // Declare scene objects.
             m_Model3DGroup = new Model3DGroup();

             // Set up camera
             var camera = new PerspectiveCamera
             {
            Position = new Point3D(1, 5, -40),
            LookDirection = new Vector3D(-1, -5, 20),
            FieldOfView = 120
             };
             XViewport.Camera = camera;

             // Set up lights
             var ambientLight = new AmbientLight
             {
            Color = AMBIENT_LIGHT
             };
             m_Model3DGroup.Children.Add(ambientLight);

             var pointLight = new PointLight
             {
            Color = POINT_LIGHT,
            Position = new Point3D(10, 20, -10)
             };
             m_Model3DGroup.Children.Add(pointLight);

             // Add the geometry model to the viewport
             m_ModelVisual3D = new ModelVisual3D { Content = m_Model3DGroup };
             XViewport.Children.Add(m_ModelVisual3D);
             m_Lorenz = new LorenzVisual(new Point3D(75, 75, 100));
             XViewport.Children.Add(m_Lorenz);
        }
        public TrackballGrabber(FrameworkElement eventSource, Viewport3D viewport, double sphereRadius, Color hoverLightColor)
        {
            if (viewport.Camera == null || !(viewport.Camera is PerspectiveCamera))
            {
                throw new ArgumentException("This class requires a perspective camera to be tied to the viewport");
            }

            _eventSource = eventSource;
            _viewport = viewport;
            _camera = (PerspectiveCamera)viewport.Camera;

            this.SyncedLights = new List<Model3D>();

            this.HoverVisuals = new ObservableCollection<Visual3D>();
            this.HoverVisuals.CollectionChanged += HoverVisuals_CollectionChanged;

            _eventSource.MouseEnter += new System.Windows.Input.MouseEventHandler(EventSource_MouseEnter);
            _eventSource.MouseLeave += new System.Windows.Input.MouseEventHandler(EventSource_MouseLeave);
            _eventSource.MouseDown += new System.Windows.Input.MouseButtonEventHandler(EventSource_MouseDown);
            _eventSource.MouseUp += new System.Windows.Input.MouseButtonEventHandler(EventSource_MouseUp);
            _eventSource.MouseMove += new System.Windows.Input.MouseEventHandler(EventSource_MouseMove);

            #region Sphere

            // Material
            _sphereMaterials = new MaterialGroup();
            _sphereMaterials.Children.Add(new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(25, 255, 255, 255))));

            // This gets added/removed on mouse enter/leave
            _sphereMaterialHover = new SpecularMaterial(new SolidColorBrush(Color.FromArgb(64, 128, 128, 128)), 33d);

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = _sphereMaterials;
            geometry.BackMaterial = _sphereMaterials;
            geometry.Geometry = UtilityWPF.GetSphere_LatLon(20, sphereRadius);

            // Model Visual
            _sphereModel = new ModelVisual3D();
            _sphereModel.Content = geometry;

            // Add it
            _viewport.Children.Add(_sphereModel);

            #endregion
            #region Hover Light

            // Light
            PointLight hoverLight = new PointLight();
            hoverLight.Color = hoverLightColor;
            hoverLight.Range = sphereRadius * 10;

            _hoverLight = new ModelVisual3D();
            _hoverLight.Content = hoverLight;

            #endregion
        }
Example #15
0
        /// <summary>
        /// Set the properties, then call create
        /// NOTE:  This adds itself to the viewport and world.  In the future, that should be handled by the caller
        /// </summary>
        public void CreateBot(Viewport3D viewport, SharedVisuals sharedVisuals, World world, Point3D worldPosition)
        {
            _viewport = viewport;

            // Thruster
            _origThrustDirection = new Vector3D(0, 4, 0);
            _thruster = new ThrustLine(_viewport, sharedVisuals, _origThrustDirection, new Vector3D(0, 0, 0));

            MaterialGroup material = null;
            GeometryModel3D geometry = null;
            ModelVisual3D model = null;

            #region Interior Extra Visuals

            // These are visuals that will stay oriented to the ship, but don't count in collision calculations

            #region Core

            // Neutral
            _coreMaterialNeutral = new MaterialGroup();
            _coreMaterialNeutral.Children.Add(new DiffuseMaterial(Brushes.DimGray));
            _coreMaterialNeutral.Children.Add(new SpecularMaterial(Brushes.DimGray, 75d));

            // Attack
            _coreMaterialAttack = new MaterialGroup();
            _coreMaterialAttack.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Red, UtilityWPF.AlphaBlend(Colors.Black, Colors.DimGray, .5), .15d))));
            _coreMaterialAttack.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 255, 128, 128)), 100d));

            _lightAttack = new PointLight();
            _lightAttack.Color = Color.FromArgb(255, 96, 0, 0);
            _lightAttack.Position = new Point3D(0, 0, 0);
            _lightAttack.Range = _radius * 3;

            // Geometry Model
            _coreGeometry = new GeometryModel3D();
            _coreGeometry.Material = _coreMaterialNeutral;
            _coreGeometry.BackMaterial = _coreMaterialNeutral;
            _coreGeometry.Geometry = UtilityWPF.GetSphere_LatLon(5, _radius * .4, _radius * .4, _radius * .4);
            _coreGeometry.Transform = new TranslateTransform3D(0, 0, 0);

            // Model Visual
            _core = new ModelVisual3D();
            _core.Content = _coreGeometry;

            //NOTE: model.Transform is set to the physics body's transform every frame

            // Add to the viewport
            _viewport.Children.Add(_core);

            #endregion

            #endregion

            #region WPF Model

            // Material
            //NOTE:  There seems to be an issue with drawing objects inside a semitransparent object - I think they have to be added in a certain order or something
            Brush skinBrush = new SolidColorBrush(Color.FromArgb(25, 255, 255, 255));  // making the skin semitransparent, so you can see the components inside

            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(skinBrush));
            material.Children.Add(new SpecularMaterial(Brushes.White, 75d));     // more reflective (and white light)

            MaterialGroup backMaterial = new MaterialGroup();
            backMaterial.Children.Add(new DiffuseMaterial(skinBrush));
            backMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 20, 20, 20)), 10d));       // dark light, and not very reflective

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = backMaterial;
            geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, _radius, _radius, _radius);

            // Transform
            Transform3DGroup transform = new Transform3DGroup();		// rotate needs to be added before translate
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0)));
            transform.Children.Add(new TranslateTransform3D(worldPosition.ToVector()));

            // Model Visual
            model = new ModelVisual3D();
            model.Content = geometry;
            model.Transform = transform;

            // Add to the viewport
            _viewport.Children.Add(model);

            #endregion
            #region Physics Body

            // Make a physics body that represents this shape
            this.PhysicsBody = new ConvexBody3D(world, model);

            this.PhysicsBody.Mass = Convert.ToSingle(this.Mass);

            this.PhysicsBody.LinearDamping = .01f;
            //this.PhysicsBody.AngularDamping = new Vector3D(.01f, .01f, .01f);
            //this.PhysicsBody.AngularDamping = new Vector3D(.01f, .01f, 100000f);		// this doesn't work.  probably to to cap the z back to zero, and any spin to zero
            this.PhysicsBody.AngularDamping = new Vector3D(10f, 10f, 10f);

            this.PhysicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce);
            //this.PhysicsBody.NewtonBody.ApplyForceAndTorque

            #endregion

            #region Exterior Extra Visuals

            // There is a bug in WPF where visuals added after a semitransparent one won't show inside.  So if you want to add exterior
            // bits, this would be the place

            #endregion

            _thruster.IsFiring = true;
        }
Example #16
0
        private static Tuple<Model3DGroup, Model3DGroup> GetModel(BotShellColorsDNA colors, double radius)
        {
            //TODO: Maybe throw some other debris in the nest

            Model3DGroup retVal = new Model3DGroup();

            #region Light

            // Light
            Color lightColor = UtilityWPF.ColorFromHex(colors.Light);
            PointLight pointLight = new PointLight(lightColor, new Point3D(0, 0, 0));
            UtilityWPF.SetAttenuation(pointLight, radius * 2d, .1d);

            retVal.Children.Add(pointLight);

            #endregion

            #region Bowl

            //-------- outer bowl

            // Material
            MaterialGroup material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("8C8174"))));
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("40736355")), 5d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;

            List<TubeRingBase> rings = new List<TubeRingBase>();
            rings.Add(new TubeRingDome(0, false, 3));
            rings.Add(new TubeRingRegularPolygon(radius * .4, false, radius, radius, false));
            rings.Add(new TubeRingRegularPolygon(radius * .1, false, radius * .9, radius * .9, false));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(20, rings, true, true, new TranslateTransform3D(0, 0, radius * -.3));

            retVal.Children.Add(geometry);


            //-------- inner bowl

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("A6998A"))));
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("80C2A78F")), 2d));

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;

            rings = new List<TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0, false, radius * .9, radius * .9, false));
            rings.Add(new TubeRingDome(radius * -.4, false, 5));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(20, rings, true, false, new TranslateTransform3D(0, 0, (radius * .25) + (radius * -.3)));

            retVal.Children.Add(geometry);

            #endregion

            // Make a bucket to add egg visuals into
            Model3DGroup eggs = new Model3DGroup();
            retVal.Children.Add(eggs);

            return Tuple.Create(retVal, eggs);
        }
Example #17
0
 public virtual void Load(Loader l, Instruction i)
 {
     switch (i.Type)
     {
         case "name":
             Name = i.String();
             break;
         case "dim":
             int width = i.Int(), height = i.Int(), length = i.Int();
             Dimension = new Dimension3D(width, height, length);
             models = new Model[width, height, length];
             break;
         case "m": // Model
             {
                 Position3D pos = i.Position3D();
                 ModelTemplate mt = Game.Get<ModelTemplate>(i.String());
                 Model m = new Model(mt);
                 AddModel(m, pos);
                 ProcessModelArgs(i, m);
             }
             break;
         case "r": // Range (multiple models)
             {
                 Position3D origin = i.Position3D();
                 Dimension3D dim = i.Dimension3D();
                 ModelTemplate mt = Game.Get<ModelTemplate>(i.String());
                 origin.ForEachInRange(dim, (loc) =>
                 {
                     Model m = new Model(mt);
                     AddModel(m, loc);
                 });
             }
             break;
         case "a": // Actor
             {
                 Position3D pos = i.Position3D();
                 ActorTemplate at = Game.Get<ActorTemplate>(i.String());
                 Actor actor = new Actor(at);
                 AddActor(actor);
                 ProcessModelArgs(i, actor);
             }
             break;
         case "dl": // Directional light
             {
                 Light light = new DirectionalLight(i.Color(), i.Vector3D());
                 Lamp ls = new Lamp(light);
                 AddLamp(ls);
                 if (i.HasNext)
                     namedElements[i.String()] = ls;
             }
             break;
         case "pl": // Point light
             {
                 Light light = new PointLight(i.Color(), i.Point3D());
                 Lamp ls = new Lamp(light);
                 AddLamp(ls);
                 if (i.HasNext)
                     namedElements[i.String()] = ls;
             }
             break;
         case "al": // Ambient light
             {
                 Light light = new AmbientLight(i.Color());
                 Lamp ls = new Lamp(light);
                 AddLamp(ls);
                 if (i.HasNext)
                     namedElements[i.String()] = ls;
             }
             break;
     }
 }
Example #18
0
        public void CreateMineral(MaterialManager materialManager, Map map, SharedVisuals sharedVisuals, Vector3D position, bool randomOrientation, double volumeInCubicMeters)
        {
            _map = map;
            _sharedVisuals = sharedVisuals;

            if (_mineralType == MineralType.Custom)
            {
                #region Validate

                if (_numSides < 3)
                {
                    throw new ApplicationException("The number of sides must at least be 3");
                }

                if (_rings.Count == 0)
                {
                    throw new ApplicationException("Need at least one ring");
                }

                #endregion
            }
            else
            {
                // Overwrite my public properties based on the mineral type
                StoreSettingsForMineralType(volumeInCubicMeters);
            }

            RotateTransform3D randomRotation = null;
            if (randomOrientation)
            {
                randomRotation = new RotateTransform3D(new AxisAngleRotation3D(Math3D.GetRandomVector_Spherical(1d), Math1D.GetNearZeroValue(360d)));
            }

            if (_mineralType == MineralType.Rixium)
            {
                #region Rixium Visuals

                Model3DGroup ringModels = new Model3DGroup();

                ringModels.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, -.6), .38, .5, randomRotation));
                ringModels.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, -.3), .44, .75, randomRotation));
                ringModels.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, 0), .5, 1, randomRotation));
                ringModels.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, .3), .44, .75, randomRotation));
                ringModels.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, .6), .38, .5, randomRotation));

                //TODO:  Look at the global lighting options
                PointLight pointLight = new PointLight();
                pointLight.Color = Color.FromArgb(255, 54, 147, 168);
                pointLight.Range = 20;
                pointLight.LinearAttenuation = .33;
                ringModels.Children.Add(pointLight);

                ModelVisual3D ringModel = new ModelVisual3D();        // this is the expensive one, so as few of these should be made as possible
                ringModel.Content = ringModels;

                _visuals.Add(ringModel);
                _map.Viewport.Children.Add(ringModel);

                #endregion
            }

            #region WPF Model

            // Material
            MaterialGroup materials = new MaterialGroup();
            if (_diffuseColor.A > 0)
            {
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(_diffuseColor)));
            }

            if (_specularColor.A > 0)
            {
                materials.Children.Add(new SpecularMaterial(new SolidColorBrush(_specularColor), _specularPower));
            }

            if (_emissiveColor.A > 0)
            {
                materials.Children.Add(new EmissiveMaterial(new SolidColorBrush(_emissiveColor)));
            }

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = materials;
            geometry.BackMaterial = materials;

            if (_mineralType == MineralType.Custom)
            {
                geometry.Geometry = UtilityWPF.GetMultiRingedTube_ORIG(_numSides, _rings, false, true);
            }
            else
            {
                geometry.Geometry = _sharedVisuals.GetMineralMesh(_mineralType);
            }
            if (randomOrientation)
            {
                geometry.Transform = randomRotation;
            }

            // Model Visual
            ModelVisual3D model = new ModelVisual3D();
            model.Content = geometry;
            model.Transform = new TranslateTransform3D(position);

            // Add to the viewport
            _visuals.Add(model);
            _map.Viewport.Children.Add(model);

            #endregion

            #region Physics Body

            // Make a physics body that represents this shape
            _physicsBody = new ConvexBody3D(_map.World, model);

            _physicsBody.MaterialGroupID = materialManager.MineralMaterialID;

            _physicsBody.NewtonBody.UserData = this;

            _physicsBody.Mass = Convert.ToSingle(_mass);

            _physicsBody.LinearDamping = .01f;
            _physicsBody.AngularDamping = new Vector3D(.01f, .01f, .01f);
            _physicsBody.Override2DEnforcement_Rotation = true;

            _physicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce);

            #endregion

            // Add to the map
            _map.AddItem(this);
        }
Example #19
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.Window = ((WpfPhotoAlbum.MainWindow)(target));
                return;

            case 2:
                this.Storyboard1_BeginStoryboard = ((System.Windows.Media.Animation.BeginStoryboard)(target));
                return;

            case 3:
                this.LayoutRoot = ((System.Windows.Controls.Grid)(target));
                return;

            case 4:
                this.image10 = ((System.Windows.Controls.Image)(target));
                return;

            case 5:
                this.image9 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 6:
                this.image9ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 7:
                this.image9Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 8:
                this.AmbientContainer5 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 9:
                this.Ambient5 = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 10:
                this.DirectionalContainer5 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 11:
                this.Directional5 = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 12:
                this.image8 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 13:
                this.image8ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 14:
                this.image8Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 15:
                this.AmbientContainer4 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 16:
                this.Ambient4 = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 17:
                this.DirectionalContainer4 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 18:
                this.Directional4 = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 19:
                this.image7 = ((System.Windows.Controls.Image)(target));
                return;

            case 20:
                this.image6 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 21:
                this.image6ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 22:
                this.image6Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 23:
                this.AmbientContainer3 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 24:
                this.Ambient3 = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 25:
                this.DirectionalContainer3 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 26:
                this.Directional3 = ((System.Windows.Media.Media3D.PointLight)(target));
                return;

            case 27:
                this.image5 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 28:
                this.image5ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 29:
                this.image5Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 30:
                this.AmbientContainer2 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 31:
                this.Ambient2 = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 32:
                this.DirectionalContainer2 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 33:
                this.Directional2 = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 34:
                this.image4 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 35:
                this.image4ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 36:
                this.image4Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 37:
                this.AmbientContainer1 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 38:
                this.Ambient1 = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 39:
                this.DirectionalContainer1 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 40:
                this.Directional1 = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 41:
                this.image3 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 42:
                this.orthographicCamera = ((System.Windows.Media.Media3D.OrthographicCamera)(target));
                return;

            case 43:
                this.image3ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 44:
                this.image3Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 45:
                this.AmbientContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 46:
                this.Ambient = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 47:
                this.DirectionalContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 48:
                this.Directional = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 49:
                this.image2 = ((System.Windows.Controls.Image)(target));
                return;

            case 50:
                this.image1 = ((System.Windows.Controls.Image)(target));
                return;

            case 51:
                this.rectangle1 = ((System.Windows.Shapes.Rectangle)(target));

            #line 732 "..\..\MainWindow.xaml"
                this.rectangle1.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Rectangle_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 52:
                this.rectangle2 = ((System.Windows.Shapes.Rectangle)(target));

            #line 745 "..\..\MainWindow.xaml"
                this.rectangle2.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Rectangle_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 53:
                this.rectangle3 = ((System.Windows.Shapes.Rectangle)(target));

            #line 758 "..\..\MainWindow.xaml"
                this.rectangle3.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Rectangle_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 54:
                this.textblock1 = ((System.Windows.Controls.TextBlock)(target));
                return;
            }
            this._contentLoaded = true;
        }
Example #20
0
        private void CreateVisual()
        {
            //NOTE:  I am not adding this to this.Body.Visuals, because I need to scale the visual as well (also, this class removes the visual when update reaches zero)

            _isExplode = _forceAtCenter > 0d;

            // Figure out colors
            Color reflectColor, lightColor;
            if (_isExplode)
            {
                // Explode
                _baseColor = Colors.Coral;
                reflectColor = Colors.Gold;
                lightColor = Color.FromArgb(128, 252, 255, 136);
            }
            else
            {
                // Implode
                _baseColor = Colors.CornflowerBlue;
                reflectColor = Colors.DarkOrchid;
                lightColor = Color.FromArgb(128, 183, 190, 255);
            }

            // Shell
            _visual = GetWPFModel(out _material, _baseColor, reflectColor, 30d, _visualStartRadius, this.Position);		// I want to keep this pretty close to the original method, so I'll let it build a full ModelVisual, and I'll pull the model out of that

            Model3DGroup models = new Model3DGroup();
            models.Children.Add(_visual.Content);

            // Light
            _pointLight = new PointLight();
            _pointLight.Color = lightColor;
            _pointLight.Range = _visualStartRadius * 2;		// radius will eventually overtake this, then it will be set to radius
            _pointLight.QuadraticAttenuation = .33;
            models.Children.Add(_pointLight);

            // Now store the group instead
            _visual.Content = models;

            _viewport.Children.Add(_visual);
        }
        private void MakeModel(double x, double y, double z, string _currentMovingBlack)
        {
            double from = 0.0, to = 0.0;
            double Rx = 1, Ry = -0.5, Rz = -1, Ra = 180;
            if (_currentMovingBlack.Equals("is SnowBoard Jump"))
            {
            }
            else if (_currentMovingBlack.Equals("Turn Left"))
            {
                x = 1; y = 1; z = 1; from = 0; to = 45;
            }
            else if (_currentMovingBlack.Equals("Turn Right"))
            {
                x = 0; y = -1; z = -1; from = 0; to = 45;
            }
            else if (_currentMovingBlack.Equals("Accel"))
            {
                x = 3; y = -1; z = 0; from = 0; to = 60;
            }
            else if (_currentMovingBlack.Equals("Break"))
            {
                x = -3; y = 1; z = 0; from = 0; to = 80;
            }
            else if (_currentMovingBlack.Equals("fell down gear"))
            {
                Rx = 3; Ry = -1; Rz = -1; Ra = 90;
                x = 4; y = -2; z = 1; from = 0; to = 100;
                ctrVM.ContainTooltip = "팔을 땅방향으로 90도 꺽어 내리는 동작";
            }
            else if (_currentMovingBlack.Equals("Gear Move to Right"))
            {
                Rx = 3; Ry = -1; Rz = -1; Ra = 90;
                x = -1; y = -1; z = -11;
                from = 0; to = 100;
                ctrVM.ContainTooltip = "팔을 오른쪽 안쪽으로 90도 꺽는 동작";
            }
            else if (_currentMovingBlack.Equals("Gear Move to Left"))
            {
                Rx = 3; Ry = -1; Rz = -1; Ra = 90;
                x = -1; y = -1; z = 11;
                from = 0; to = 100;
                ctrVM.ContainTooltip = "팔을 왼쪽 바깥쪽으로 90도 꺽는 동작";
            }
            else if (_currentMovingBlack.Equals("Gear Rotate Clockwise"))
            {
                Rx = 3; Ry = -1; Rz = -1; Ra = 90;
                x = -3; y = -3; z = -1; from = 0; to = 60;
                ctrVM.ContainTooltip = "손목을 시계방향으로 90도 꺽는 동작";
            }
            else if (_currentMovingBlack.Equals("Gear Rotate CounterClockWise"))
            {
                Rx = 3; Ry = -1; Rz = -1; Ra = 90;
                x = 6; y = 6; z = 1; from = 0; to = 60;
                ctrVM.ContainTooltip = "손목을 반시계방향으로 90도 꺽는 동작";
            }
            else if (_currentMovingBlack.Equals("Is Shot"))
            {
                Rx = 16; Ry = 0; Rz = -1; Ra = 180;
                x = -12; y = 6; z = 6;
                from = 0; to = 210;
                ctrVM.ContainTooltip = "골프채를 잡고 스윙하는 팔 동작";
            }
            else
            {
                ctrVM.ContainTooltip = "선택된 애니메이션이 없습니다.";
            }

            ax3d = new AxisAngleRotation3D(new Vector3D(Rx, Ry, Rz), Ra);
            myRotateTransform = new RotateTransform3D(ax3d);
            transform3DGroup.Children.Add(myRotateTransform);

            ax3d2 = new AxisAngleRotation3D(new Vector3D(x, y, z), 0);
            myRotateTransform2 = new RotateTransform3D(ax3d2);
            transform3DGroup.Children.Add(myRotateTransform2);
            transT3D = new TranslateTransform3D(0, 0, 0);
            transform3DGroup.Children.Add(transT3D);
            model.Transform = transform3DGroup;

            modelV3D = new ModelVisual3D();
            modelV3D.Content = model;
            helixV3D = new Viewport3D();
            makeCamera();

            var mesh = new MeshGeometry3D();
            modelScull = new GeometryModel3D();
            modelScull = (GeometryModel3D)model.Children[0];
            mesh = (MeshGeometry3D)modelScull.Geometry;

            var model2 = new GeometryModel3D();
            var group = new Model3DGroup();
            group.Transform = transform3DGroup;
            var myBrush = new ImageBrush();
            myBrush.ImageSource = new BitmapImage(new Uri("../../ObjectFile/texture.jpg", UriKind.Relative));
            material = new DiffuseMaterial(myBrush);
            model2 = new GeometryModel3D(mesh, material);
            model2.BackMaterial = new DiffuseMaterial(new SolidColorBrush(Color.FromRgb(200, 149, 121)));
            group.Children.Add(model2);


            light = new PointLight(Colors.White, new Point3D(15, 0, 0));
            group.Children.Add(light);
            light = new PointLight(Colors.White, new Point3D(0, 15, 0));
            group.Children.Add(light);
            light = new PointLight(Colors.White, new Point3D(0, 0, 15));
            group.Children.Add(light);
            light = new PointLight(Colors.White, new Point3D(-15, 0, 0));
            group.Children.Add(light);
            light = new PointLight(Colors.White, new Point3D(0, -15, 0));
            group.Children.Add(light);
            light = new PointLight(Colors.White, new Point3D(0, 0, -15));
            group.Children.Add(light);
            light = new PointLight(Colors.White, new Point3D(10, 5, 10));
            group.Children.Add(light);
            light = new PointLight(Colors.White, new Point3D(0, 0, 0));
            group.Children.Add(light);

            var Model = new ModelVisual3D();
            Model.Content = group;
            helixV3D.Children.Add(Model);
            conGrid.Children.Add(helixV3D);

            string _propertyPath = "rotate";
            if (_currentMovingBlack.Equals("is SnowBoard Jump"))
            {
                _propertyPath = "trans";
            }
            MakeAnimation(_propertyPath, _currentMovingBlack, from, to);
        }
Example #22
0
        /// <summary>
        /// Set the properties, then call create
        /// NOTE:  This adds itself to the viewport and world.  In the future, that should be handled by the caller
        /// </summary>
        protected void CreateBot(Viewport3D viewport, SharedVisuals sharedVisuals, World world, Point3D worldPosition)
        {
            _viewport = viewport;
            _sharedVisuals = sharedVisuals;
            _world = world;

            // Thruster
            _origThrustDirection = new Vector3D(0, _thrustForce, 0);
            _thruster = new ThrustLine(_viewport, sharedVisuals, _origThrustDirection, new Vector3D(0, 0, 0));
            _thruster.LineMaxLength = this.ThrustLineStandardLength * _thrustLineMultiplier;

            MaterialGroup material = null;
            GeometryModel3D geometry = null;
            ModelVisual3D model = null;

            _visuals = new List<ModelVisual3D>();

            #region Interior Extra Visuals

            // These are visuals that will stay oriented to the ship, but don't count in collision calculations

            #region Core

            // Neutral
            _coreMaterialNeutral = new MaterialGroup();
            _coreMaterialNeutralColor = new DiffuseMaterial(new SolidColorBrush(_coreColor));
            _coreMaterialNeutral.Children.Add(_coreMaterialNeutralColor);
            _coreMaterialNeutral.Children.Add(new SpecularMaterial(Brushes.DimGray, 75d));

            // Attack
            _coreMaterialAttack = new MaterialGroup();
            _coreMaterialAttack.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Red, UtilityWPF.AlphaBlend(Colors.Black, Colors.DimGray, .5), .15d))));
            _coreMaterialAttack.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 255, 128, 128)), 100d));

            _lightAttack = new PointLight();
            _lightAttack.Color = Color.FromArgb(255, 96, 0, 0);
            _lightAttack.Position = new Point3D(0, 0, 0);
            _lightAttack.Range = _radius * 3;

            // Geometry Model
            _coreGeometry = new GeometryModel3D();
            _coreGeometry.Material = _coreMaterialNeutral;
            _coreGeometry.BackMaterial = _coreMaterialNeutral;
            _coreGeometry.Geometry = UtilityWPF.GetSphere_LatLon(5, _radius * .4, _radius * .4, _radius * .4);
            _coreGeometry.Transform = new TranslateTransform3D(0, 0, 0);

            // Model Visual
            _core = new ModelVisual3D();
            _core.Content = _coreGeometry;

            //NOTE: model.Transform is set to the physics body's transform every frame

            _visuals.Add(_core);

            // Add to the viewport
            _viewport.Children.Add(_core);

            #endregion

            #endregion

            #region Glass Shell

            // Material
            //NOTE:  There seems to be an issue with drawing objects inside a semitransparent object - I think they have to be added in a certain order or something
            Brush skinBrush = new SolidColorBrush(Color.FromArgb(25, 255, 255, 255));  // making the skin semitransparent, so you can see the components inside

            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(skinBrush));
            material.Children.Add(new SpecularMaterial(Brushes.White, 75d));     // more reflective (and white light)

            MaterialGroup backMaterial = new MaterialGroup();
            backMaterial.Children.Add(new DiffuseMaterial(skinBrush));
            backMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 20, 20, 20)), 10d));       // dark light, and not very reflective

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = backMaterial;
            geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, _radius, _radius, _radius);

            // Transform
            Transform3DGroup transform = new Transform3DGroup();		// rotate needs to be added before translate
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0)));
            transform.Children.Add(new TranslateTransform3D(worldPosition.ToVector()));

            // Model Visual
            model = new ModelVisual3D();
            model.Content = geometry;
            model.Transform = transform;

            _visuals.Add(model);

            // Add to the viewport
            _viewport.Children.Add(model);

            #endregion
            #region Physics Body

            // Make a physics body that represents this shape
            _physicsBody = new ConvexBody3D(world, model);

            //NOTE:  Not setting material _physicsBody.MaterialGroupID, so it takes the default material

            _physicsBody.NewtonBody.UserData = this;

            _physicsBody.Mass = Convert.ToSingle(this.Mass);

            _physicsBody.LinearDamping = .01f;
            _physicsBody.AngularDamping = new Vector3D(10f, 10f, 10f);   // fairly heavy damping (the bot doesn't try to cancel its spin, so I'll let Newt do it for me)

            _physicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce);

            #endregion

            #region Exterior Extra Visuals

            // There is a bug in WPF where visuals added after a semitransparent one won't show inside.  So if you want to add exterior
            // bits that aren't visible inside, this would be the place

            #endregion

            _thruster.IsFiring = true;

            // Show the proper core
            this.IsAttacking = _isAttacking;
        }
Example #23
0
        /// <summary>
        /// Add a non-directional point light source.
        /// </summary>
        /// <param name="shapeName">The 3DView object.</param>
        /// <param name="colour">The light colour.</param>
        /// <param name="xPos">The x position of the light.</param>
        /// <param name="yPos">The y position of the light.</param>
        /// <param name="zPos">The z position of the light.</param>
        /// <param name="range">The light range.</param>
        /// <returns>The 3DView Light name.</returns>
        public static Primitive AddPointLight(Primitive shapeName, Primitive colour, Primitive xPos, Primitive yPos, Primitive zPos, Primitive range)
        {
            UIElement obj;

            try
            {
                if (_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        try
                        {
                            if (obj.GetType() == typeof(Viewport3D))
                            {
                                Viewport3D viewport3D = (Viewport3D)obj;
                                ModelVisual3D modelVisual3D = (ModelVisual3D)viewport3D.Children[0];
                                Model3DGroup model3DGroup = (Model3DGroup)modelVisual3D.Content;

                                PointLight pointLight = new PointLight();
                                pointLight.Color = (Color)ColorConverter.ConvertFromString(colour);
                                pointLight.Position = new Point3D(xPos, yPos, zPos);
                                pointLight.Range = range;
                                pointLight.QuadraticAttenuation = 1;

                                string name = getLightingName();
                                Lightings.Add(new Lighting(name, pointLight));
                                model3DGroup.Children.Add(pointLight);
                                return name;
                            }
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        }
                        return "";
                    });
                    return FastThread.InvokeWithReturn(ret).ToString();
                }
                else
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "";
        }