Esempio n. 1
0
        private static void InnerConeAnglePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            SpotLight target = ((SpotLight)d);


            target.PropertyChanged(InnerConeAngleProperty);
        }
Esempio n. 2
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.listBox = ((System.Windows.Controls.ListBox)(target));

            #line 18 "..\..\..\3DControl.xaml"
                this.listBox.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.listBox_SelectionChanged);

            #line default
            #line hidden
                return;

            case 2:
                this.button5 = ((System.Windows.Controls.Button)(target));
                return;

            case 3:
                this.label1 = ((System.Windows.Controls.Label)(target));
                return;

            case 4:
                this.textBox1 = ((System.Windows.Controls.TextBox)(target));
                return;

            case 5:
                this.SenceGrid = ((System.Windows.Controls.Grid)(target));
                return;

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

            case 7:
                this.myPerspectiveCamera = ((System.Windows.Media.Media3D.PerspectiveCamera)(target));
                return;

            case 8:
                this.FurnitureContainer = ((System.Windows.Media.Media3D.ContainerUIElement3D)(target));
                return;

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

            case 10:
                this.ambientLight = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

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

            case 12:
                this.spotLight = ((System.Windows.Media.Media3D.SpotLight)(target));
                return;
            }
            this._contentLoaded = true;
        }
Esempio n. 3
0
        //------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------

        private static void DirectionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            SpotLight target = ((SpotLight)d);


            target.PropertyChanged(DirectionProperty);
        }
Esempio n. 4
0
        //public Light Lighting { get; private set; }
        public FullScene()
        {
            // Define the camera
            var camera = new PerspectiveCamera();
            camera.Position = new Point3D(0, .25, 10);
            camera.LookDirection = new Vector3D(0, 0, -1);

            //camera.LookDirection = new Vector3D(0, -.05, -1);
            camera.UpDirection = new Vector3D(0, 1, 0);
            camera.FieldOfView = 60;

            //var camera = new OrthographicCamera();
            //camera.Position = new Point3D(0, 0, 85);
            //camera.LookDirection = new Vector3D(0, -.05, -4);

            //camera.NearPlaneDistance = 0;
            //camera.FarPlaneDistance = 100;
            ColorConverter conv = new ColorConverter();
            var color = (Color)conv.ConvertFrom("#ffffff");
            //var ambient = new AmbientLight(color);
            var pos = new Point3D(0, 10, 10);
            var spotlight = new SpotLight();
            spotlight.Color = color;
            spotlight.Position = pos;
            spotlight.InnerConeAngle = 180;
            spotlight.OuterConeAngle = 90;
            spotlight.Direction = new Vector3D(pos.X * -1, pos.Y * -1, pos.Z * -1);

            // Define a lighting model
            // Collect the components
            this.modelGroup = new Model3DGroup();
            this.modelGroup.Children.Add(ambientLight);
            this.modelGroup.Children.Add(spotlight);

            ModelVisual3D visual = new ModelVisual3D();
            visual.Content = this.modelGroup;
            Viewport3D viewport = new Viewport3D();

            viewport.Children.Add(visual);
            viewport.Camera = camera;

            this.Viewport = viewport;
        }
Esempio n. 5
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.oldgrid = ((System.Windows.Controls.Grid)(target));
     return;
     case 2:
     this.grid1 = ((System.Windows.Controls.Grid)(target));
     return;
     case 3:
     this.roomName = ((System.Windows.Controls.Label)(target));
     return;
     case 4:
     this.label2 = ((System.Windows.Controls.Label)(target));
     return;
     case 5:
     this.comboBox1 = ((System.Windows.Controls.ComboBox)(target));
     
     #line 27 "..\..\..\..\DeviceMigrations\addposition.xaml"
     this.comboBox1.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.comboBox1_SelectionChanged);
     
     #line default
     #line hidden
     return;
     case 6:
     this.label1 = ((System.Windows.Controls.Label)(target));
     return;
     case 7:
     this.label3 = ((System.Windows.Controls.Label)(target));
     return;
     case 8:
     this.button3 = ((System.Windows.Controls.Button)(target));
     
     #line 38 "..\..\..\..\DeviceMigrations\addposition.xaml"
     this.button3.Click += new System.Windows.RoutedEventHandler(this.button3_Click);
     
     #line default
     #line hidden
     return;
     case 9:
     this.viewport1 = ((System.Windows.Controls.Viewport3D)(target));
     
     #line 41 "..\..\..\..\DeviceMigrations\addposition.xaml"
     this.viewport1.MouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.rightleftdown);
     
     #line default
     #line hidden
     return;
     case 10:
     this.myPerspectiveCamera = ((System.Windows.Media.Media3D.PerspectiveCamera)(target));
     return;
     case 11:
     this.FurnitureContainer2 = ((System.Windows.Media.Media3D.ContainerUIElement3D)(target));
     return;
     case 12:
     this.viewportLightsModelVisual3D = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
     return;
     case 13:
     this.ambientLight = ((System.Windows.Media.Media3D.AmbientLight)(target));
     return;
     case 14:
     this.directionalLight = ((System.Windows.Media.Media3D.DirectionalLight)(target));
     return;
     case 15:
     this.spotLight = ((System.Windows.Media.Media3D.SpotLight)(target));
     return;
     }
     this._contentLoaded = true;
 }
Esempio n. 6
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.textBox1 = ((System.Windows.Controls.TextBox)(target));
     return;
     case 2:
     this.textBox2 = ((System.Windows.Controls.TextBox)(target));
     return;
     case 3:
     this.textBox3 = ((System.Windows.Controls.TextBox)(target));
     return;
     case 4:
     this.viewport2 = ((System.Windows.Controls.Viewport3D)(target));
     return;
     case 5:
     this.myPerspectiveCamera = ((System.Windows.Media.Media3D.PerspectiveCamera)(target));
     return;
     case 6:
     this.FurnitureContainer3 = ((System.Windows.Media.Media3D.ContainerUIElement3D)(target));
     return;
     case 7:
     this.viewportLightsModelVisual3D = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
     return;
     case 8:
     this.ambientLight = ((System.Windows.Media.Media3D.AmbientLight)(target));
     return;
     case 9:
     this.directionalLight = ((System.Windows.Media.Media3D.DirectionalLight)(target));
     return;
     case 10:
     this.spotLight = ((System.Windows.Media.Media3D.SpotLight)(target));
     return;
     case 11:
     this.canvas = ((System.Windows.Controls.Canvas)(target));
     return;
     case 12:
     this.label2 = ((System.Windows.Controls.Label)(target));
     
     #line 54 "..\..\..\..\DeviceMigrations\addwindow.xaml"
     this.label2.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.upclick);
     
     #line default
     #line hidden
     return;
     case 13:
     this.label3 = ((System.Windows.Controls.Label)(target));
     
     #line 59 "..\..\..\..\DeviceMigrations\addwindow.xaml"
     this.label3.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.downclick);
     
     #line default
     #line hidden
     return;
     case 14:
     this.button2 = ((System.Windows.Controls.Button)(target));
     
     #line 67 "..\..\..\..\DeviceMigrations\addwindow.xaml"
     this.button2.Click += new System.Windows.RoutedEventHandler(this.button2_Click);
     
     #line default
     #line hidden
     return;
     }
     this._contentLoaded = true;
 }
Esempio n. 7
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.listBox = ((System.Windows.Controls.ListBox)(target));
     
     #line 18 "..\..\..\3DControl.xaml"
     this.listBox.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.listBox_SelectionChanged);
     
     #line default
     #line hidden
     return;
     case 2:
     this.button5 = ((System.Windows.Controls.Button)(target));
     return;
     case 3:
     this.label1 = ((System.Windows.Controls.Label)(target));
     return;
     case 4:
     this.textBox1 = ((System.Windows.Controls.TextBox)(target));
     return;
     case 5:
     this.SenceGrid = ((System.Windows.Controls.Grid)(target));
     return;
     case 6:
     this.viewport = ((System.Windows.Controls.Viewport3D)(target));
     return;
     case 7:
     this.myPerspectiveCamera = ((System.Windows.Media.Media3D.PerspectiveCamera)(target));
     return;
     case 8:
     this.FurnitureContainer = ((System.Windows.Media.Media3D.ContainerUIElement3D)(target));
     return;
     case 9:
     this.viewportLightsModelVisual3D = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
     return;
     case 10:
     this.ambientLight = ((System.Windows.Media.Media3D.AmbientLight)(target));
     return;
     case 11:
     this.directionalLight = ((System.Windows.Media.Media3D.DirectionalLight)(target));
     return;
     case 12:
     this.spotLight = ((System.Windows.Media.Media3D.SpotLight)(target));
     return;
     }
     this._contentLoaded = true;
 }
Esempio n. 8
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 {
                }
            }
        }
Esempio n. 9
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 CreateShip(MaterialManager materialManager, SharedVisuals sharedVisuals, Map map, ProgressBarGame progressBarCargo, ProgressBarGame progressBarFuel)
        {
            const double THRUSTLINELENGTH = .5d;
            const double THRUSTLINELENGTH_EXTRA = .75d;
            const double THRUSTLINELENGTH_TURN = .3;

            _sharedVisuals = sharedVisuals;
            _map = map;
            _progressBarCargo = progressBarCargo;
            _progressBarFuel = progressBarFuel;

            #region Thrusters

            // These need to be definded before the visuals are created
            double radians = Math1D.DegreesToRadians(225);
            _thrusterOffset_BottomLeft = new Vector3D(this.RadiusX * Math.Cos(radians), this.RadiusY * Math.Sin(radians), 0);
            radians = Math1D.DegreesToRadians(135);
            _thrusterOffset_TopLeft = new Vector3D(this.RadiusX * Math.Cos(radians), this.RadiusY * Math.Sin(radians), 0);

            radians = Math1D.DegreesToRadians(315);
            _thrusterOffset_BottomRight = new Vector3D(this.RadiusX * Math.Cos(radians), this.RadiusY * Math.Sin(radians), 0);
            radians = Math1D.DegreesToRadians(45);
            _thrusterOffset_TopRight = new Vector3D(this.RadiusX * Math.Cos(radians), this.RadiusY * Math.Sin(radians), 0);

            _thrustForce = 100d;
            _torqueballLeftRightThrusterForce = -10d;

            #region Define ThrustLines

            //NOTE: The ThrustLine class will add/remove visuals directly from the viewport.  There's no need for the map to get involved

            // The reference to the fuel tank will be made when I create the tank

            ThrustLine thrustLine;

            // Up
            _thrustLines.Add(Key.Up, new List<ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * _thrustForce, _thrusterOffset_BottomRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.Up].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * _thrustForce, _thrusterOffset_BottomLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.Up].Add(thrustLine);

            // W
            _thrustLines.Add(Key.W, new List<ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * (_thrustForce * 2d), _thrusterOffset_BottomRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_EXTRA;
            _thrustLines[Key.W].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * (_thrustForce * 2d), _thrusterOffset_BottomLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_EXTRA;
            _thrustLines[Key.W].Add(thrustLine);

            // Down
            _thrustLines.Add(Key.Down, new List<ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * _thrustForce, _thrusterOffset_TopRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.Down].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * _thrustForce, _thrusterOffset_TopLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.Down].Add(thrustLine);

            // S
            _thrustLines.Add(Key.S, new List<ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * (_thrustForce * 2d), _thrusterOffset_TopRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_EXTRA;
            _thrustLines[Key.S].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * (_thrustForce * 2d), _thrusterOffset_TopLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_EXTRA;
            _thrustLines[Key.S].Add(thrustLine);

            // Left
            _thrustLines.Add(Key.Left, new List<ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * _torqueballLeftRightThrusterForce, _thrusterOffset_BottomRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_TURN;
            _thrustLines[Key.Left].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * _torqueballLeftRightThrusterForce, _thrusterOffset_TopLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_TURN;
            _thrustLines[Key.Left].Add(thrustLine);

            // Right
            _thrustLines.Add(Key.Right, new List<ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * _torqueballLeftRightThrusterForce, _thrusterOffset_TopRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_TURN;
            _thrustLines[Key.Right].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * _torqueballLeftRightThrusterForce, _thrusterOffset_BottomLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_TURN;
            _thrustLines[Key.Right].Add(thrustLine);

            // A
            _thrustLines.Add(Key.A, new List<ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(-1, 0, 0) * _thrustForce, _thrusterOffset_TopRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.A].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(-1, 0, 0) * _thrustForce, _thrusterOffset_BottomRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.A].Add(thrustLine);

            // D
            _thrustLines.Add(Key.D, new List<ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(1, 0, 0) * _thrustForce, _thrusterOffset_TopLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.D].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(1, 0, 0) * _thrustForce, _thrusterOffset_BottomLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.D].Add(thrustLine);

            #endregion

            #endregion

            MaterialGroup material = null;
            GeometryModel3D geometry = null;
            Model3DGroup models = new Model3DGroup();
            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 Thrusters

            // These are the little balls, not the thrust lines

            double thrusterLocScale = 1d;

            models.Children.Add(GetThrusterVisual(_thrusterOffset_BottomLeft * thrusterLocScale));
            models.Children.Add(GetThrusterVisual(_thrusterOffset_BottomRight * thrusterLocScale));
            models.Children.Add(GetThrusterVisual(_thrusterOffset_TopLeft * thrusterLocScale));
            models.Children.Add(GetThrusterVisual(_thrusterOffset_TopRight * thrusterLocScale));

            #endregion
            #region Cargo Bay

            //TODO:  Make a visual for this (probably pretty cube like)

            _cargoBay = new CargoBay(_cargoBayMass, _cargoBayVolume);

            _progressBarCargo.Minimum = 0d;
            _progressBarCargo.Maximum = _cargoBay.MaxVolume;
            _progressBarCargo.Value = 0d;

            #endregion
            #region Fuel Tank

            //TODO:  This visual should be a pill

            _fuelTank = new FuelTank();
            _fuelTank.DryMass = _fuelTankMass;
            _fuelTank.QuantityMax = _fuelTankCapacity;
            _fuelTank.QuantityCurrent = _fuelTank.QuantityMax;		// a full tank with the purchace of a new ship!!!
            _fuelTank.FuelDensity = _fuelDensity;

            _progressBarFuel.Minimum = 0d;
            _progressBarFuel.Maximum = _fuelTank.QuantityMax;
            _progressBarFuel.Value = _fuelTank.QuantityCurrent;

            // Link to the thrusters
            foreach (List<ThrustLine> thrustLines in _thrustLines.Values)
            {
                foreach (ThrustLine thrustLine1 in thrustLines)
                {
                    thrustLine1.FuelToThrustRatio = _fuelThrustRatio;
                    thrustLine1.FuelTank = _fuelTank;
                }
            }

            #endregion

            #region Core

            // This just looks stupid.  The idea is that you would see the various components (which would also be point masses).  But until
            // the user can modify their ship, it's just an arbitrary ellipse that is ugly

            //// Material
            //material = new MaterialGroup();
            //material.Children.Add(new DiffuseMaterial(Brushes.DimGray));
            //material.Children.Add(new SpecularMaterial(Brushes.DimGray, 100d));

            //// Geometry Model
            //geometry = new GeometryModel3D();
            //geometry.Material = material;
            //geometry.BackMaterial = material;
            //geometry.Geometry = UtilityWPF.GetSphere(5, .45, .25, .05);
            //geometry.Transform = new TranslateTransform3D(0, this.RadiusY * -.25, 0);

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

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

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

            //_visuals.Add(model);

            #endregion

            // Make a model visual for what I have so far
            model = new ModelVisual3D();        // this is the expensive one, so as few of these should be made as possible
            model.Content = models;

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

            #endregion

            #region WPF Collision 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(50, _hullColor.R, _hullColor.G, _hullColor.B));  // making the skin semitransparent, so you can see the components inside
            Brush skinBrush = new SolidColorBrush(_hullColor);  // decided to make it opaque, since I'm not showing anything 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, this.RadiusX, this.RadiusY, this.RadiusZ);

            // 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(new Vector3D(0, 0, 0)));

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

            _physicsModel = model;    // remember this, so I don't set its transform
            _visuals.Add(model);

            // Add to the viewport (the physics body constructor requires it to be added)
            _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.ShipMaterialID;

            _physicsBody.NewtonBody.UserData = this;

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

            _physicsBody.LinearDamping = .01f;
            //_physicsBody.AngularDamping = new Vector3D(.01f, .01f, .01f);
            //_physicsBody.AngularDamping = new Vector3D(10f, 10f, 10f);
            _physicsBody.AngularDamping = new Vector3D(1f, 1f, 1f);

            _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.  The cockpit looks stupid when you can see
            // it inside the skin

            #region Cockpit

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Teal, Colors.DimGray, .2d))));
            material.Children.Add(new SpecularMaterial(Brushes.White, 100d));

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;
            //geometry.Geometry = UtilityWPF.GetSphere(3, .4, .2, .3);
            geometry.Geometry = UtilityWPF.GetSphere_LatLon(3, .45, .25, .25);
            geometry.Transform = new TranslateTransform3D(0, this.RadiusY * .5, 0);

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

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

            #endregion
            #region Headlight

            SpotLight spotLight = new SpotLight();
            //spotLight.Color = Color.FromArgb(255, 50, 170, 50);
            spotLight.Color = UtilityWPF.AlphaBlend(Colors.White, _hullColor, .25d);
            spotLight.Direction = new Vector3D(0, 1, 0);
            spotLight.OuterConeAngle = 25;
            spotLight.InnerConeAngle = 5;
            //spotLight.LinearAttenuation = .1;
            spotLight.QuadraticAttenuation = .0001;
            spotLight.Range = 1000;

            model = new ModelVisual3D();
            model.Content = spotLight;

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

            #endregion

            #endregion

            // Add to the map
            _map.AddItem(this);
        }
Esempio n. 10
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.listBox = ((System.Windows.Controls.ListBox)(target));

            #line 18 "..\..\..\..\DeviceMigrations\motor.xaml"
                this.listBox.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.listBox_SelectionChanged);

            #line default
            #line hidden
                return;

            case 2:
                this.button5 = ((System.Windows.Controls.Button)(target));

            #line 28 "..\..\..\..\DeviceMigrations\motor.xaml"
                this.button5.Click += new System.Windows.RoutedEventHandler(this.button5_Click);

            #line default
            #line hidden
                return;

            case 3:
                this.label1 = ((System.Windows.Controls.Label)(target));
                return;

            case 4:
                this.textBox1 = ((System.Windows.Controls.TextBox)(target));
                return;

            case 5:
                this.button1 = ((System.Windows.Controls.Button)(target));

            #line 31 "..\..\..\..\DeviceMigrations\motor.xaml"
                this.button1.Click += new System.Windows.RoutedEventHandler(this.button1_Click_1);

            #line default
            #line hidden
                return;

            case 6:
                this.label8 = ((System.Windows.Controls.Label)(target));
                return;

            case 7:
                this.SenceGrid = ((System.Windows.Controls.Grid)(target));
                return;

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

            case 9:
                this.myPerspectiveCamera = ((System.Windows.Media.Media3D.PerspectiveCamera)(target));
                return;

            case 10:
                this.FurnitureContainer = ((System.Windows.Media.Media3D.ContainerUIElement3D)(target));
                return;

            case 11:
                this.viewportLightsModelVisual3D = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 12:
                this.ambientLight = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 13:
                this.directionalLight = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 14:
                this.spotLight = ((System.Windows.Media.Media3D.SpotLight)(target));
                return;

            case 15:
                this.canvas1 = ((System.Windows.Controls.Canvas)(target));
                return;

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

            #line 58 "..\..\..\..\DeviceMigrations\motor.xaml"
                this.label2.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowupclick);

            #line default
            #line hidden
                return;

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

            #line 63 "..\..\..\..\DeviceMigrations\motor.xaml"
                this.label3.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowdownclick);

            #line default
            #line hidden
                return;

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

            #line 68 "..\..\..\..\DeviceMigrations\motor.xaml"
                this.label4.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowleftclick);

            #line default
            #line hidden
                return;

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

            #line 73 "..\..\..\..\DeviceMigrations\motor.xaml"
                this.label5.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowrightclick);

            #line default
            #line hidden
                return;

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

            #line 78 "..\..\..\..\DeviceMigrations\motor.xaml"
                this.label6.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowaddclick);

            #line default
            #line hidden
                return;

            case 21:
                this.label7 = ((System.Windows.Controls.Label)(target));

            #line 83 "..\..\..\..\DeviceMigrations\motor.xaml"
                this.label7.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowdelclick);

            #line default
            #line hidden
                return;

            case 22:
                this.label9 = ((System.Windows.Controls.Label)(target));

            #line 88 "..\..\..\..\DeviceMigrations\motor.xaml"
                this.label9.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.rebackclick);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
Esempio n. 11
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.listBox = ((System.Windows.Controls.ListBox)(target));
     
     #line 18 "..\..\..\..\DeviceMigrations\motor.xaml"
     this.listBox.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.listBox_SelectionChanged);
     
     #line default
     #line hidden
     return;
     case 2:
     this.button5 = ((System.Windows.Controls.Button)(target));
     
     #line 28 "..\..\..\..\DeviceMigrations\motor.xaml"
     this.button5.Click += new System.Windows.RoutedEventHandler(this.button5_Click);
     
     #line default
     #line hidden
     return;
     case 3:
     this.label1 = ((System.Windows.Controls.Label)(target));
     return;
     case 4:
     this.textBox1 = ((System.Windows.Controls.TextBox)(target));
     return;
     case 5:
     this.button1 = ((System.Windows.Controls.Button)(target));
     
     #line 31 "..\..\..\..\DeviceMigrations\motor.xaml"
     this.button1.Click += new System.Windows.RoutedEventHandler(this.button1_Click_1);
     
     #line default
     #line hidden
     return;
     case 6:
     this.label8 = ((System.Windows.Controls.Label)(target));
     return;
     case 7:
     this.SenceGrid = ((System.Windows.Controls.Grid)(target));
     return;
     case 8:
     this.viewport = ((System.Windows.Controls.Viewport3D)(target));
     return;
     case 9:
     this.myPerspectiveCamera = ((System.Windows.Media.Media3D.PerspectiveCamera)(target));
     return;
     case 10:
     this.FurnitureContainer = ((System.Windows.Media.Media3D.ContainerUIElement3D)(target));
     return;
     case 11:
     this.viewportLightsModelVisual3D = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
     return;
     case 12:
     this.ambientLight = ((System.Windows.Media.Media3D.AmbientLight)(target));
     return;
     case 13:
     this.directionalLight = ((System.Windows.Media.Media3D.DirectionalLight)(target));
     return;
     case 14:
     this.spotLight = ((System.Windows.Media.Media3D.SpotLight)(target));
     return;
     case 15:
     this.canvas1 = ((System.Windows.Controls.Canvas)(target));
     return;
     case 16:
     this.label2 = ((System.Windows.Controls.Label)(target));
     
     #line 58 "..\..\..\..\DeviceMigrations\motor.xaml"
     this.label2.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowupclick);
     
     #line default
     #line hidden
     return;
     case 17:
     this.label3 = ((System.Windows.Controls.Label)(target));
     
     #line 63 "..\..\..\..\DeviceMigrations\motor.xaml"
     this.label3.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowdownclick);
     
     #line default
     #line hidden
     return;
     case 18:
     this.label4 = ((System.Windows.Controls.Label)(target));
     
     #line 68 "..\..\..\..\DeviceMigrations\motor.xaml"
     this.label4.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowleftclick);
     
     #line default
     #line hidden
     return;
     case 19:
     this.label5 = ((System.Windows.Controls.Label)(target));
     
     #line 73 "..\..\..\..\DeviceMigrations\motor.xaml"
     this.label5.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowrightclick);
     
     #line default
     #line hidden
     return;
     case 20:
     this.label6 = ((System.Windows.Controls.Label)(target));
     
     #line 78 "..\..\..\..\DeviceMigrations\motor.xaml"
     this.label6.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowaddclick);
     
     #line default
     #line hidden
     return;
     case 21:
     this.label7 = ((System.Windows.Controls.Label)(target));
     
     #line 83 "..\..\..\..\DeviceMigrations\motor.xaml"
     this.label7.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.arrowdelclick);
     
     #line default
     #line hidden
     return;
     case 22:
     this.label9 = ((System.Windows.Controls.Label)(target));
     
     #line 88 "..\..\..\..\DeviceMigrations\motor.xaml"
     this.label9.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.rebackclick);
     
     #line default
     #line hidden
     return;
     }
     this._contentLoaded = true;
 }
Esempio n. 12
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.addusetrol = ((GloryView.RFID.DeviceMigrations.OldEquipment)(target));
                return;

            case 2:
                this.grid = ((System.Windows.Controls.Grid)(target));
                return;

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

            case 4:
                this.grid1 = ((System.Windows.Controls.Grid)(target));
                return;

            case 5:
                this.roomName = ((System.Windows.Controls.Label)(target));
                return;

            case 6:
                this.label3 = ((System.Windows.Controls.Label)(target));
                return;

            case 7:
                this.label1 = ((System.Windows.Controls.Label)(target));
                return;

            case 8:
                this.label2 = ((System.Windows.Controls.Label)(target));
                return;

            case 9:
                this.comboBox1 = ((System.Windows.Controls.ComboBox)(target));

            #line 40 "..\..\..\..\DeviceMigrations\OldEquipment.xaml"
                this.comboBox1.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.comboBox1_SelectionChanged);

            #line default
            #line hidden
                return;

            case 10:
                this.button3 = ((System.Windows.Controls.Button)(target));

            #line 49 "..\..\..\..\DeviceMigrations\OldEquipment.xaml"
                this.button3.Click += new System.Windows.RoutedEventHandler(this.button3_Click);

            #line default
            #line hidden
                return;

            case 11:
                this.button1 = ((System.Windows.Controls.Button)(target));

            #line 50 "..\..\..\..\DeviceMigrations\OldEquipment.xaml"
                this.button1.Click += new System.Windows.RoutedEventHandler(this.button1_Click);

            #line default
            #line hidden
                return;

            case 12:
                this.dataGrid1 = ((System.Windows.Controls.Grid)(target));
                return;

            case 13:
                this.viewport1 = ((System.Windows.Controls.Viewport3D)(target));

            #line 60 "..\..\..\..\DeviceMigrations\OldEquipment.xaml"
                this.viewport1.MouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.rightleftdown);

            #line default
            #line hidden
                return;

            case 14:
                this.myPerspectiveCamera = ((System.Windows.Media.Media3D.PerspectiveCamera)(target));
                return;

            case 15:
                this.FurnitureContainer2 = ((System.Windows.Media.Media3D.ContainerUIElement3D)(target));
                return;

            case 16:
                this.viewportLightsModelVisual3D = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 17:
                this.ambientLight = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

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

            case 19:
                this.spotLight = ((System.Windows.Media.Media3D.SpotLight)(target));
                return;
            }
            this._contentLoaded = true;
        }
Esempio n. 13
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();
              }
        }
Esempio n. 14
0
        /// <summary>
        /// Add a directional spot 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="xDir">The x direction of the light.</param>
        /// <param name="yDir">The y direction of the light.</param>
        /// <param name="zDir">The z direction of the light.</param>
        /// <param name="angle">The cone angle the light in degrees.</param>
        /// <param name="range">The light range.</param>
        /// <returns>The 3DView Light name.</returns>
        public static Primitive AddSpotLight(Primitive shapeName, Primitive colour, Primitive xPos, Primitive yPos, Primitive zPos, Primitive xDir, Primitive yDir, Primitive zDir, Primitive angle, 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;

                                SpotLight spotLight = new SpotLight();
                                spotLight.Color = (Color)ColorConverter.ConvertFromString(colour);
                                spotLight.Position = new Point3D(xPos, yPos, zPos);
                                spotLight.Direction = new Vector3D(xDir, yDir, zDir);
                                spotLight.InnerConeAngle = angle;
                                spotLight.OuterConeAngle = angle + 10;
                                spotLight.Range = range;
                                //spotLight.ConstantAttenuation = 3;

                                string name = getLightingName();
                                Lightings.Add(new Lighting(name, spotLight));
                                model3DGroup.Children.Add(spotLight);
                                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 "";
        }
Esempio n. 15
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.addserver = ((GloryView.RFID.DeviceMigrations.Addserver)(target));
                return;

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

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

            case 4:
                this.FurnitureContainer3 = ((System.Windows.Media.Media3D.ContainerUIElement3D)(target));
                return;

            case 5:
                this.viewportLightsModelVisual3D = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 6:
                this.ambientLight = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 7:
                this.directionalLight = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 8:
                this.spotLight = ((System.Windows.Media.Media3D.SpotLight)(target));
                return;

            case 9:
                this.canvas = ((System.Windows.Controls.Canvas)(target));
                return;

            case 10:
                this.label2 = ((System.Windows.Controls.Label)(target));

            #line 61 "..\..\..\..\DeviceMigrations\Addserver.xaml"
                this.label2.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.upclick);

            #line default
            #line hidden
                return;

            case 11:
                this.label3 = ((System.Windows.Controls.Label)(target));

            #line 66 "..\..\..\..\DeviceMigrations\Addserver.xaml"
                this.label3.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.downclick);

            #line default
            #line hidden
                return;

            case 12:
                this.button1 = ((System.Windows.Controls.Button)(target));

            #line 74 "..\..\..\..\DeviceMigrations\Addserver.xaml"
                this.button1.Click += new System.Windows.RoutedEventHandler(this.button1_Click_1);

            #line default
            #line hidden
                return;

            case 13:
                this.button2 = ((System.Windows.Controls.Button)(target));

            #line 75 "..\..\..\..\DeviceMigrations\Addserver.xaml"
                this.button2.Click += new System.Windows.RoutedEventHandler(this.button2_Click);

            #line default
            #line hidden
                return;

            case 14:
                this.textBox1 = ((System.Windows.Controls.TextBox)(target));
                return;

            case 15:
                this.textBox2 = ((System.Windows.Controls.TextBox)(target));
                return;

            case 16:
                this.textBox3 = ((System.Windows.Controls.TextBox)(target));
                return;
            }
            this._contentLoaded = true;
        }