开发者

Constraining dimension of a PlaneProjection

How can I constrain a plane projection to a particular dimension? For example, I have the following:

    <Canvas  Width="720" Height="540" x:Name="Root" Background="Red"  >
        <Line Width="200" Height="5" X1="0" X2="200" 
            Y1="0" Y2="0" Stroke="LimeGreen" StrokeThickness="10"
            Canvas.Left="260" Canvas.Top="70" />
        <Rectangle Width="200" Height="400" Stroke="Blue" StrokeThickness="6" 
            Fill="LightBlue"  Opacity="0.5" Canvas.Left="260" Canvas.Top="70">
            <Rectangle.Projection>
                <PlaneProjection x:Name="box" />
            </Rectangle.Projection>
        </Rectangle>
        <Line Width="200" Height="10" X1="0" X2="200" 
            Y1="0" Y2="0" Stroke="LimeGreen" StrokeThickness="10"
            Canvas.Left="260" Canvas.Top="464" />
    </Canvas>

I want to rotate this around its Y axis by 360 degrees, but never want the projection to exceed the bounds of the height of the rectangle - in this case, 400 points.

The storyboard, just for simplicities' sake in testing, is in a trigger.

<UserControl.Triggers>
    <EventTrigger>
        <BeginStoryboard>
            <Storyboard>
 开发者_JAVA百科               <DoubleAnimation Storyboard.TargetName="box"
                                 Storyboard.TargetProperty="RotationY"
                                 By="360" Duration="0:0:15"
                                 RepeatBehavior="Forever" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</UserControl.Triggers>


This is not perfect, as it is linear interpolation and the actual relationship of the height to angle of rotation is a slight sinusoidal curve, but is close to what you want.

It basically scales Y to 0.88 in one quarter of the total time (and is AutoReversed).

You can simplify the element naming as you did with "box" if you prefer (I used Blend to author/test the storyboard and it always creates the long element names):

            <Storyboard>
                <DoubleAnimation Storyboard.TargetName="box"
                             Storyboard.TargetProperty="RotationY"
                             By="360" Duration="0:0:15"
                             RepeatBehavior="Forever" />
                <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" 
                    Storyboard.TargetName="rectangle"
                    Duration="0:0:3.75" To="0.88"
                    RepeatBehavior="Forever" 
                    AutoReverse="True" >
                </DoubleAnimation>

            </Storyboard>


            <Rectangle x:Name="rectangle" 
                       Stroke="Blue" 
                       StrokeThickness="6" 
                       Fill="LightBlue" 
                       Opacity="0.5" 
                       RenderTransformOrigin="0.5,0.5">
                <Rectangle.RenderTransform>
                    <CompositeTransform/>
                </Rectangle.RenderTransform>
                <Rectangle.Projection>
                    <PlaneProjection x:Name="box" />
                </Rectangle.Projection>
            </Rectangle>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜