コード例 #1
0
        public MainViewModel()
        {
            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique         = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager          = new DefaultEffectsManager(RenderTechniquesManager);

            Title    = "Shadow Map Demo";
            SubTitle = "WPF & SharpDX";

            // setup lighting
            this.AmbientLightColor         = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            this.DirectionalLightColor     = Color.White;
            this.DirectionalLightDirection = new Vector3(-0, -1, -1);
            this.LightDirectionTransform   = CreateAnimatedTransform(-DirectionalLightDirection.ToVector3D(), new Vector3D(0, 1, -1), 24);
            this.ShadowMapResolution       = new Vector2(2048, 2048);

            // camera setup
            this.Camera = new PerspectiveCamera {
                Position = (Point3D)(-DirectionalLightDirection.ToVector3D()), LookDirection = DirectionalLightDirection.ToVector3D(), UpDirection = new Vector3D(0, 1, 0)
            };
            Camera1 = new PerspectiveCamera {
                Position = (Point3D)(-DirectionalLightDirection.ToVector3D()), LookDirection = DirectionalLightDirection.ToVector3D(), UpDirection = new Vector3D(0, 1, 0)
            };
            Camera2 = new PerspectiveCamera {
                Position = (Point3D)(-DirectionalLightDirection.ToVector3D()), LookDirection = DirectionalLightDirection.ToVector3D(), UpDirection = new Vector3D(0, 1, 0)
            };
            // floor plane grid
            //Grid = LineBuilder.GenerateGrid();
            //GridColor = SharpDX.Color.Black;
            //GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5);

            // scene model3d
            var b1 = new MeshBuilder();

            b1.AddSphere(new Vector3(0, 0, 0), 0.5);
            b1.AddBox(new Vector3(0, 0, 0), 1, 0.25, 2, BoxFaces.All);
            Model = b1.ToMeshGeometry3D();
            //Instances = new[] { Matrix.Translation(0, 0, -1.5f), Matrix.Translation(0, 0, 1.5f) };

            var b2 = new MeshBuilder();

            b2.AddBox(new Vector3(0, 0, 0), 10, 0, 10, BoxFaces.PositiveY);
            Plane          = b2.ToMeshGeometry3D();
            PlaneTransform = new Media3D.TranslateTransform3D(-0, -2, -0);
            GrayMaterial   = PhongMaterials.LightGray;
            //GrayMaterial.TextureMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute));

            // lines model3d
            Lines = LineBuilder.GenerateBoundingBox(Model);

            // model trafos
            Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0);
            Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0);
            Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0);

            // model materials
            RedMaterial   = PhongMaterials.Glass;
            GreenMaterial = PhongMaterials.Green;
            BlueMaterial  = PhongMaterials.Blue;
        }
コード例 #2
0
 private void OnAnimatedChanged(bool value)
 {
     this.isAnimated = value;
     if (value)
     {
         this.LightDirectionTransform = CreateAnimatedTransform(-DirectionalLightDirection.ToVector3D(), new Vector3D(0, 1, -1), 24);
     }
     else
     {
         this.LightDirectionTransform = Media3D.Transform3D.Identity;
     }
 }
コード例 #3
0
ファイル: Watch3DView.xaml.cs プロジェクト: heldred/Dynamo
        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
#if DEBUG
            if (renderTimer.IsRunning)
            {
                renderTimer.Stop();
                Debug.WriteLine(string.Format("RENDER: {0} ellapsed for setting properties and rendering.", renderTimer.Elapsed));
                renderTimer.Reset();
            }
#endif
            var c = new Vector3((float)camera.LookDirection.X, (float)camera.LookDirection.Y, (float)camera.LookDirection.Z);
            if (!DirectionalLightDirection.Equals(c))
            {
                DirectionalLightDirection = c;
            }
        }
コード例 #4
0
        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
#if DEBUG
            if (renderTimer.IsRunning)
            {
                renderTimer.Stop();
                Debug.WriteLine(string.Format("RENDER: {0} ellapsed for setting properties and rendering.", renderTimer.Elapsed));
                renderTimer.Reset();
            }
#endif

            var cf    = new Vector3((float)camera.LookDirection.X, (float)camera.LookDirection.Y, (float)camera.LookDirection.Z).Normalized();
            var cu    = new Vector3((float)camera.UpDirection.X, (float)camera.UpDirection.Y, (float)camera.UpDirection.Z).Normalized();
            var right = Vector3.Cross(cf, cu);

            var qel = SharpDX.Quaternion.RotationAxis(right, (float)((-LightElevationDegrees * Math.PI) / 180));
            var qaz = SharpDX.Quaternion.RotationAxis(cu, (float)((LightAzimuthDegrees * Math.PI) / 180));
            var v   = Vector3.Transform(cf, qaz * qel);

            if (!DirectionalLightDirection.Equals(v))
            {
                DirectionalLightDirection = v;
            }
        }
コード例 #5
0
        public MainViewModel()
        {
            // Lines Setup
            this.LineThickness          = 1d;
            this.TriangulationThickness = .5;
            this.ShowTriangleLines      = true;

            // Count Setup
            this.PointCount = 1000;

            // Lighting Setup
            this.AmbientLightColor         = new Color4(1f, 1f, 1f, 1.0f);
            this.DirectionalLightColor     = Color.White;
            this.DirectionalLightDirection = new Vector3(0, -1, 0);

            // Model Transformations
            this.ModelTransform     = new TranslateTransform3D(0, 0, 0);
            this.ModelLineTransform = new TranslateTransform3D(0, 0.001, 0);

            // Model Materials and Colors
            this.Material           = PhongMaterials.PolishedBronze;
            this.TriangulationColor = SharpDX.Color.Black;

            // Grid Setup
            this.Grid          = LineBuilder.GenerateGrid(Vector3.UnitY, -5, 5, 0, 10);
            this.GridColor     = SharpDX.Color.DarkGray;
            this.GridTransform = new TranslateTransform3D(0, -0.01, 0);


            //this.GroundGeometry = new Element3DCollection();
            //this.PlayersGeometry = new Element3DCollection();


            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique         = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager          = new DefaultEffectsManager(RenderTechniquesManager);



            // setup lighting

            this.LightDirectionTransform = CreateAnimatedTransform(-DirectionalLightDirection.ToVector3D(), new Vector3D(0, 1, -1), 24);
            this.ShadowMapResolution     = new Vector2(2048, 2048);

            // camera setup
            this.Camera = new PerspectiveCamera {
                Position = (Point3D)(-DirectionalLightDirection.ToVector3D()), LookDirection = DirectionalLightDirection.ToVector3D(), UpDirection = new Vector3D(0, 1, 0)
            };

            // floor plane grid
            //Grid = LineBuilder.GenerateGrid();
            //GridColor = SharpDX.Color.Black;
            //GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5);

            // scene model3d
            //var b1 = new MeshBuilder();
            //b1.AddSphere(new Vector3(0, 0, 0), 0.5);
            //b1.AddBox(new Vector3(0, 0, 0), 1, 0.25, 2, BoxFaces.All);
            //Model = b1.ToMeshGeometry3D();
            ////Instances = new[] { Matrix.Translation(0, 0, -1.5f), Matrix.Translation(0, 0, 1.5f) };

            //var b2 = new MeshBuilder();
            //b2.AddBox(new Vector3(0, 0, 0), 10, 0, 10, BoxFaces.PositiveY);
            //Plane = b2.ToMeshGeometry3D();
            //PlaneTransform = new Media3D.TranslateTransform3D(-0, -2, -0);
            //GrayMaterial = PhongMaterials.LightGray;
            ////GrayMaterial.TextureMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute));

            //// lines model3d
            //Lines = LineBuilder.GenerateBoundingBox(Model);

            //// model trafos
            //Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0);
            //Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0);
            //Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0);

            // model materials
            RedMaterial   = PhongMaterials.Glass;
            GreenMaterial = PhongMaterials.Green;
            BlueMaterial  = PhongMaterials.Blue;
        }