private void DrawGeometry() { // screen space DrawPolyline(new[] { new Point3D(3, 20, 0), new Point3D(140, 20, 0) }, Space.Screen, Pens.Gray); // view space DrawPolyline(new[] { new Point3D(-0.9, -0.9, 0), new Point3D(0.9, -0.9, 0) }, Space.View, Pens.Gray); // world space bigger cube var angle = GetDeltaTime(new TimeSpan(0, 0, 0, 5)) * Math.PI * 2; var matrixModel = MatrixEx.Scale(0.5) * MatrixEx.Rotate(new UnitVector3D(1, 0, 0), angle) * MatrixEx.Translate(1, 0, 0); foreach (var cubePolyline in CubePolylines) { DrawPolyline(matrixModel.Transform(cubePolyline), Space.World, Pens.White); } // world space smaller cube angle = GetDeltaTime(new TimeSpan(0, 0, 0, 1)) * Math.PI * 2; matrixModel = MatrixEx.Scale(0.5) * MatrixEx.Rotate(new UnitVector3D(0, 1, 0), angle) * MatrixEx.Translate(0, 1, 0) * matrixModel; foreach (var cubePolyline in CubePolylines) { DrawPolyline(matrixModel.Transform(cubePolyline), Space.World, Pens.Yellow); } }
private void DrawGeometry() { // bigger cube var angle = GetDeltaTime(new TimeSpan(0, 0, 0, 5)) * Math.PI * 2; var matrixModel = MatrixEx.Scale(0.5) * MatrixEx.Rotate(new UnitVector3D(1, 0, 0), angle) * MatrixEx.Translate(1, 0, 0); foreach (var cubePolyline in CubePolylines) { DrawPolyline(matrixModel.Transform(cubePolyline), Space.World, Pens.White); } // smaller cube angle = GetDeltaTime(new TimeSpan(0, 0, 0, 1)) * Math.PI * 2; matrixModel = MatrixEx.Scale(0.5) * MatrixEx.Rotate(new UnitVector3D(0, 1, 0), angle) * MatrixEx.Translate(0, 1, 0) * matrixModel; foreach (var cubePolyline in CubePolylines) { DrawPolyline(matrixModel.Transform(cubePolyline), Space.World, Pens.Yellow); } }
/// <summary> /// Get some primitives to demonstrate hierarchical matrix multiplication. /// </summary> private static IEnumerable <IPrimitive> GetPrimitivesCubes() { var duration = new TimeSpan(DateTime.UtcNow.Ticks); // world space bigger cube var angle = GetTimeSpanPeriodRatio(duration, new TimeSpan(0, 0, 0, 5)) * Math.PI * 2; var matrixModel = MatrixEx.Scale(0.5) * MatrixEx.Rotate(new UnitVector3D(1, 0, 0), angle) * MatrixEx.Translate(1, 0, 0); foreach (var cubePolyline in CubePolylines) { yield return(new Materials.Position.Primitive ( new PrimitiveBehaviour(Space.World), PrimitiveTopology.LineStrip, matrixModel.Transform(cubePolyline).Select(position => new Materials.Position.Vertex(position)).ToArray(), Color.White )); } // world space smaller cube angle = GetTimeSpanPeriodRatio(duration, new TimeSpan(0, 0, 0, 1)) * Math.PI * 2; matrixModel = MatrixEx.Scale(0.5) * MatrixEx.Rotate(new UnitVector3D(0, 1, 0), angle) * MatrixEx.Translate(0, 1, 0) * matrixModel; foreach (var cubePolyline in CubePolylines) { yield return(new Materials.Position.Primitive ( new PrimitiveBehaviour(Space.World), PrimitiveTopology.LineStrip, matrixModel.Transform(cubePolyline).Select(position => new Materials.Position.Vertex(position)).ToArray(), Color.Yellow )); } }