[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Draw three interlocked boxes using XAML and C#

interlocked boxes

This example uses techniques similar to those in the example Draw interlocked tetrahedrons using XAML and C# to draw three interlocked boxes. It draws three cubes and scales them so they have different side lengths and so they overlap.

The following code shows how the program defines a single cube centered at the origin and with vertex coordinates (±1, ±1, ±1).

<MeshGeometry3D Positions=" -1,-1,-1 1,-1,-1 1,-1, 1 -1,-1, 1 -1,-1, 1 1,-1, 1 1, 1, 1 -1, 1, 1 1,-1, 1 1,-1,-1 1, 1,-1 1, 1, 1 1, 1, 1 1, 1,-1 -1, 1,-1 -1, 1, 1 -1,-1, 1 -1, 1, 1 -1, 1,-1 -1,-1,-1 -1,-1,-1 -1, 1,-1 1, 1,-1 1,-1,-1 " TriangleIndices=" 0 1 2 2 3 0 4 5 6 6 7 4 8 9 10 10 11 8 12 13 14 14 15 12 16 17 18 18 19 16 20 21 22 22 23 20 " />

The example repeats this code three times and then uses transformations to stretch the cubes into the boxes that it needs. The following code shows how the program scales the red box.

<GeometryModel3D.Transform> <ScaleTransform3D ScaleX="1" ScaleY="2" ScaleZ="3" /> </GeometryModel3D.Transform>

The other cubes are scaled similarly but with different scale factors in the X, Y, and Z directions.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.