public MainWindow()
{
InitializeComponent();
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(0.001);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
private int i = 0;
void timer_Tick(object sender, EventArgs e)
{
if (myAngleRotation.Angle + 5 == 360)
{
i++;
if (i % 2 == 1)
myAngleRotation.Axis = new Vector3D(3, 3, 0);
else
myAngleRotation.Axis = new Vector3D(0, 3, 3);
}
myAngleRotation.Angle = (myAngleRotation.Angle + 5) % 360;
}
<Grid>
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera FarPlaneDistance="20" FieldOfView="50" NearPlaneDistance="0"
Position="-5,2,3" LookDirection="5,-2,-3" UpDirection="0,1,0"/>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<!--side 5 top-->
<GeometryModel3D >
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="
0.5,0.5,-0.5
-0.5,0.5,-0.5
-0.5,0.5,0.5
-0.5,0.5,0.5
0.5,0.5,0.5
0.5,0.5,-0.5
"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="Blue" />
</GeometryModel3D.Material>
</GeometryModel3D>
<AmbientLight Color="White"></AmbientLight>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="
-0.5,0.5,-0.5
-0.5,-0.5,-0.5
-0.5,-0.5,0.5
-0.5,-0.5,0.5
-0.5,0.5,0.5
-0.5,0.5,-0.5
"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<SolidColorBrush Color="Red" Opacity="1"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="
-0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5
0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,0.5
"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="Yellow" />
</GeometryModel3D.Material>
</GeometryModel3D>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="
-0.5,-0.5,-0.5 -0.5,0.5,-0.5 0.5,0.5,-0.5
0.5,0.5,-0.5 0.5,-0.5,-0.5 -0.5,-0.5,-0.5
"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="Green" />
</GeometryModel3D.Material>
</GeometryModel3D>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="
-0.5,-0.5,-0.5
0.5,-0.5,-0.5
0.5,-0.5,0.5
0.5,-0.5,0.5
-0.5,-0.5,0.5
-0.5,-0.5,-0.5
"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="LightSlateGray" />
</GeometryModel3D.Material>
</GeometryModel3D>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="
0.5,-0.5,-0.5
0.5,0.5,-0.5
0.5,0.5,0.5
0.5,0.5,0.5
0.5,-0.5,0.5
0.5,-0.5,-0.5
"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="DarkOrange" />
</GeometryModel3D.Material>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
<ModelVisual3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D x:Name="myAngleRotation" Axis="0,3,3" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</ModelVisual3D.Transform>
</ModelVisual3D>
</Viewport3D>
</Grid>