Title: Draw three interlocked boxes using XAML and C#
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.
|