hakan aydogan

hakan aydogan

  • NA
  • 2
  • 32.9k

3D rotation problem on WPF

Jan 16 2011 5:24 PM
Hi everyone,
I have been trying to animate a 3D rotation for a  viewport3d object On one of its edges. My animation rotates the object around its centre axis but not around the desired edge. I need to do this on either sides of the object, it will rotate on a specific edge. Below is my animation. Thanks for the help.

  1. <Window x:Class="Sepis.MainWindow"  
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  4. Title="MainWindow" Height="768" MinWidth="800" Width="1000" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">  
  5. <Window.Resources>  
  6. </Window.Resources>  
  7. Name="rectangle1" Width="100" Height="100" Fill="Red">  
  8. </Rectangle>  
  9.   
  10.         <Viewport3D Name="BAckgroundWindow" ClipToBound  
  11.     <Grid Height="Auto" Width="1400" MinWidth="1280" Name="MainGrid" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Stretch" Opacity="1">  
  12. <Grid.ColumnDefinitions>  
  13. <ColumnDefinition Width="0*" />  
  14. <ColumnDefinition Width="1210*" />  
  15. </Grid.ColumnDefinitions>  
  16. <Button Name="btnOper">  
  17. </Button>  
  18. <Rectangle  
  19.  s="True" Margin="353,0,747,180" Grid.Column="1" Width="300" Height="300" HorizontalAlignment="Center" VerticalAlignment="Bottom">  
  20. <!-- Defines the camera used to view the 3D object. -->  
  21. <Viewport3D.Camera>  
  22. <PerspectiveCamera UpDirection="0,1,0" Position="0,0,2" LookDirection="0,0,-1" FieldOfView="33" />  
  23. </Viewport3D.Camera>  
  24. <!-- The ModelVisual3D children contain the 3D models -->  
  25. <Viewport3D.Children>  
  26. <!-- This ModelVisual3D defines the light cast in the scene. Without light, the 3D   
  27. object cannot be seen. Also, the direction of the lights affect shadowing. If desired,  
  28. you can create multiple lights with different colors that shine from different directions. -->  
  29. <ModelVisual3D>  
  30. <ModelVisual3D.Content>  
  31. <AmbientLight Color="#FFFFFF"/>  
  32. </ModelVisual3D.Content>  
  33. </ModelVisual3D>  
  34. <ModelVisual3D>  
  35. <ModelVisual3D.Content>  
  36. <GeometryModel3D x:Name="geometryMode3">  
  37. <!-- The geometry specifes the shape of the 3D plane. In this sample, a flat sheet is created. -->  
  38. <GeometryModel3D.Geometry>  
  39. <MeshGeometry3D TriangleIndices="0,1,2 2,3,0 2,1,0 0,3,2" Normals="0,0,1 0,1,1 0,0,1 0,0,1" TextureCoordinates="0,1 1,1 1,0 0,0" Positions="-0.5,-0.5,0 0.5,-0.5,0 0.5,0.5,0 -0.5,0.5,0" />  
  40. </GeometryModel3D.Geometry>  
  41. <!-- The material specifies the material applied to the 3D object. In this sample a linear gradient   
  42. covers the surface of the 3D object.-->  
  43. <GeometryModel3D.Material>  
  44. <MaterialGroup>  
  45. <DiffuseMaterial>  
  46. <DiffuseMaterial.Brush>  
  47. <SolidColorBrush Color="Red" />  
  48. </DiffuseMaterial.Brush>  
  49. </DiffuseMaterial>  
  50. </MaterialGroup>  
  51. </GeometryModel3D.Material>  
  52. <!-- Apply a transform to the object. In this sample, a rotation transform is applied, rendering the   
  53. 3D object rotated. -->  
  54. <GeometryModel3D.Transform>  
  55. <Transform3DGroup>  
  56. <RotateTransform3D>  
  57. <RotateTransform3D.Rotation>  
  58. <AxisAngleRotation3D Axis="1,0,0" Angle="-85" x:Name="rotation3"/>  
  59. </RotateTransform3D.Rotation>  
  60. </RotateTransform3D>  
  61. <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="3" x:Name="scale3"/>  
  62. </Transform3DGroup>  
  63. </GeometryModel3D.Transform>  
  64. </GeometryModel3D>  
  65. </ModelVisual3D.Content>  
  66. </ModelVisual3D>  
  67. </Viewport3D.Children>  
  68. </Viewport3D>  
  69. <Button Content="Button" Grid.Column="1" Height="48" HorizontalAlignment="Left" Margin="80,97,0,0" Name="button1" VerticalAlignment="Top" Width="101" />  
  70. </Grid>  
  71. <Window.Triggers>  
  72. <EventTrigger RoutedEvent="Button.Click" SourceName="button1">  
  73. <BeginStoryboard>  
  74. <Storyboard>  
  75. <!--Fourth Rotate the SecondaryComponents Viewport 3D>-->  
  76. <DoubleAnimation RepeatBehavior="0:0:0.5" Storyboard.TargetName="rotation3" Storyboard.TargetProperty="(AxisAngleRotation3D.Angle)" From="-85" To="0" Duration="0:0:0.5"/>  
  77. </Storyboard>  
  78. </BeginStoryboard>  
  79. </EventTrigger>  
  80. </Window.Triggers>  
  81. </Window>