Ejemplo n.º 1
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            var width = this.ActualWidth;
            var height = this.ActualHeight;

            Func<Vector3, Point?> toPoint = position =>
                Math.Abs(position.Z) > 1
                    ? default(Point?)
                    : new Point(
                        (-position.X + 1.0) / 2.0 * width,
                        (position.Y + 1.0) / 2.0 * height);

            var view = Matrix44.GetPerspective(Math.PI / 4, width / height, 0.1, 100.0);
            var viewTransform = new Transform3D(view)
                .Translate(new Vector3(this.Offset?.X ?? 0.0, this.Offset?.Y ?? 0.0, this.Offset?.Z ?? 0.0))
                ;

            //var offset = new Vector3(this.Offset?.X ?? 0.0, this.Offset?.Y ?? 0.0, this.Offset?.Z ?? 0.0);

            foreach (var mesh in this.Meshes)
            {
                foreach (var face in mesh.Faces)
                {
                    var prev = viewTransform.Apply(face.Vertices.Last() /*+ offset*/);
                    foreach (var vertex in face.Vertices)
                    {
                        var position = viewTransform.Apply(vertex /*+ offset*/);

                        var pp = toPoint(prev);
                        var pc = toPoint(position);

                        if(pp.HasValue && pc.HasValue)
                        {
                            drawingContext.DrawLine(new Pen(Brushes.Red, 1), pp.Value, pc.Value);
                        }
                        
                        prev = position;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void TransformChaining()
        {
            var expected = new Vector3(1, 0, 2);
            var transform = new Transform3D()
                .Translate(new Vector3(1, 0, 0))
                .RotateY(-Math.PI / 2)
                .Translate(new Vector3(2, 0, 0));
            var vector = new Vector3(0, 0, 0);
            var actual = transform.Apply(vector);

            Assert.AreEqual(expected, actual);
        }