Page 1 of 1

CompositeTransform3D Behavior

Posted: 06 Jan 2022, 21:59
by stonstad
Out of curiosity, why are elements in the top stack rotated differently compared to the elements in the bottom stack panel? (it is a cut and paste of the same XAML). Even if CompositeTrasnform3D coordinates are global, would the result look like this?

Image
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions">

  <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Top">
    <Grid Width="300" Height="200" Margin="20">
      <noesis:Element.Transform3D>
        <noesis:CompositeTransform3D RotationY="-5" CenterX="150" />
      </noesis:Element.Transform3D>      
      <Rectangle Fill="Gray"/>
      <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">A</TextBlock>
    </Grid>
 
    <Grid Width="300" Height="200" Margin="20">
      <noesis:Element.Transform3D>
        <noesis:CompositeTransform3D RotationY="5" CenterX="150" />
      </noesis:Element.Transform3D>      
      <Rectangle Fill="Gray"/>
      <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">B</TextBlock>
    </Grid>
  </StackPanel>
  
  <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Bottom">
    <Grid Width="300" Height="200" Margin="20">
      <noesis:Element.Transform3D>
        <noesis:CompositeTransform3D RotationY="-5" CenterX="150" />
      </noesis:Element.Transform3D>      
      <Rectangle Fill="Gray"/>
      <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">A</TextBlock>
    </Grid>
 
    <Grid Width="300" Height="200" Margin="20">
      <noesis:Element.Transform3D>
        <noesis:CompositeTransform3D RotationY="5" CenterX="150" />
      </noesis:Element.Transform3D>      
      <Rectangle Fill="Gray"/>
      <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">B</TextBlock>
    </Grid>
  </StackPanel>

</Grid>

Re: CompositeTrasnform3D Behavior

Posted: 06 Jan 2022, 22:31
by stonstad
I was able to achieve the desired behavior through the following:
Matrix3D rotation = Matrix3D.Identity;
Transform3D = new MatrixTransform3D(rotation.RotateY(-5));
This is resolved for me now -- this seemed to be an easier approach. Not sure why the above behaves the way it does, however.

Re: CompositeTrasnform3D Behavior

Posted: 07 Jan 2022, 12:59
by sfernandez
why are elements in the top stack rotated differently compared to the elements in the bottom stack panel?
It is the result of the camera perspective, it is the expected behavior. The CompositeTransform3D matrix is calculated as:
moveToCenter * scale * rotate * translate * moveFromCenter