Closed Massimo37 closed 5 years ago
I've added a GitHub sample with the code above and some other code I was testing based on an answer on StackOverflow (which I couldn't get to work):
StackOverflow https://stackoverflow.com/questions/58081943/i-cant-get-my-projection-matrix-to-have-a-proper-perspective-for-a-rotation-ani
I'll loop in @robmikh because his code from #32 helped me get this far. 👍
The issue has to do with the transform you're manipulating on the parent. The StackPanel that gets picked up by element.Parent
has an existing transform for layout purposes (e.g. VerticalAlignment="Center"
), which can cause issues. This is another flavor of XAML-Composition interop friction, which you can read more about the general case here and here.
However this is certainly a strange variant, it had me stumped for a bit! I'm not entirely sure what's going on, but it has to do with manipulating the transform of your StackPanel
. Thankfully, the usual remedies apply here. To get your code working, I modified your MainPage.xaml
:
<StackPanel VerticalAlignment="Center">
<Canvas Width="300" Height="250" Margin="0,0,0,40">
<Border Width="300"
Height="250"
Background="LightSeaGreen"
x:Name="Persp">
<TextBlock Text="Composition"
FontSize="28"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontWeight="Bold"
Foreground="White" />
</Border>
</Canvas>
<Border Width="300"
Height="250"
Background="LightCoral"
x:Name="Proj">
<Border.RenderTransform>
<CompositeTransform />
</Border.RenderTransform>
<Border.Projection>
<PlaneProjection CenterOfRotationX="0.5" CenterOfRotationY="0.5" />
</Border.Projection>
<TextBlock Text="PlaneProjection"
FontSize="28"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontWeight="Bold"
Foreground="White" />
</Border>
</StackPanel>
By manipulating the transform of the Canvas
instead of the StackPanel
, you should be able to avoid interference.
Let me know if that works for you!
That was the fix!! Thank you @robmikh 👍 I can definitely work with that :)
Glad it worked out :)
I
m trying to replicate a plane projection rotation in UWP using the composition api. But I'm having trouble with a projection matrix in my composition code. Here
s what I have:So this code above will rotate along the Y-axis. In the gif below, you'll see that I have it animating on top of another animation which is driven by a PlaneProjection for comparison:
The "perspective" of both is fine, both in the middle. Now lets change this line of code to switch it for a rotation on the X-axis:
Now notice the gif below:
The composition animation seems to rotate with a perspective that`s more towards the right and not perfectly centered. Does my projection matrix need to change?