Good day everyone, this is my first question here. So feel free to give me CC :)
About the project. I want to non-affine transfrom a flat polygonal plane without touchiung it´s Z-axis (0,0,0 0,1,0 1,0,0 1,1,0). I need to do that by positioning the 4 corner points of it. I achieved that by using the "Non-Affine Transforms in 2D by Charles Petzold (http://www.charlespetzold.com/blog/2007/08/250638.html).
Everything fine so far. And no dissapearing plane.
Because I need brushes/texture to expand over the edges of the plane. I decided to add triangles until I had 5x5 mesh of planes. (the whole geometry is still transformable by selecting the corner points of the first plane (it is the one in the middle.)
Sadly I am not allowed to post pictures yet.
https://i.imgur.com/oG3gKRD.png
The lightblue rectangle is the one with the selectable corners & the purple is the rest of it (for the pictures I inculded another plane (which is not connected to the big one, just to show that there is no crazy transformation effect) There is only a difference of 1 in the value (no matter what corner)
https://i.imgur.com/wSkywVk.png
It is not a problem with the camera as far as I could tell. Changing values on a lot of stuff like camera/near & farplanedistance. This positioning always results in invisible geometry (& it is not the only position leading to it, there are a few of them, but i am not able to see a connection) if I reduce the mesh to a 3x3 plane I have the same problem, only on other postions. The object is still there it is just not visible (I can still select the corner points and it will instantly visible again)
Does anyone know what can lead to that? Or does someone know how I can debug "errors" like that?
maybe is it the wrong approach for growing the transfomrable plane in general? If anyone has an idea let me know!
Setup for the geometry with both planes (two custom classes "scalingCanvas" and "CenterOnPoint" you can use a normal canvas with normal positoning)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:HtMatrix">
<Style TargetType="local:HtProjektor">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:HtProjektor">
<Grid Background="DarkOrange">
<Viewport3D Name="viewport3d" Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" >
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D x:Name="mesh"
Positions="0 0 0, 0 1 0, 1 0 0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-2 2, -1 1, -1 2,
2 1, 2 2, 3 1, 3 2,
-2 0, -2 1, -1 0, -1 1,
2 0, 2 1, 3 0, 3 1,
-2 -1, -2 0, -1 -1, -1 0,
2 -1, 2 0, 3 -1, 3 0
-2 -2, -2 -1, -1 -2, -1 -1,
-1 -2, -1 -1, 0 -2, 0 -1,
0 -2, 0 -1, 1 -2, 1 -1,
1 -2, 1 -1, 2 -2, 2 -1,
2 -2, 2 -1, 3 -2, 3 -1
"
TriangleIndices="0 2 1, 1 2 3,
4 6 5, 5 6 7,
8 10 9, 9 10 11,
12 14 13, 13 14 15,
16 18 17, 17 18 19,
20 22 21, 21 22 23,
24 26 25, 25 26 27,
28 30 29, 29 30 31,
32 34 33, 33 34 35,
36 38 37, 37 38 39,
40 42 41, 41 42 43,
44 46 45, 45 46 47,
48 50 49, 49 50 51,
52 54 53, 53 54 55
56 58 57, 57 58 59,
60 62 61, 61 62 63,
64 66 65, 65 66 67,
68 70 69, 69 70 71,
72 74 73, 73 74 75,
76 78 77, 77 78 79,
80 82 81, 81 82 83,
84 86 85, 85 86 87,
88 90 89, 89 90 91,
92 94 93, 93 94 95,
96 98 97, 97 98 99
" />
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<VisualBrush>
<VisualBrush.Visual>
<local:ScalingCanvas Background="Gray" Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}">
<Grid Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" ClipToBounds="True">
<local:ScalingCanvas Width="{Binding RelativeSource={RelativeSource TemplatedParent}}" Height="{Binding RelativeSource={RelativeSource TemplatedParent}}" Background="PaleVioletRed" Opacity="0.5">
<local:ScalingCanvas.RenderTransform>
<ScaleTransform ScaleX="{Binding ScaleX, RelativeSource={RelativeSource TemplatedParent}}" ScaleY="{Binding ScaleY, RelativeSource={RelativeSource TemplatedParent}}"/>
</local:ScalingCanvas.RenderTransform>
<Rectangle Height="768" Width="1024"/>
<Rectangle local:ScalingCanvas.Top="200" local:ScalingCanvas.Left="200" Fill="Aqua" Width="100" Height="100" />
<Rectangle local:CenterOnPoint.CenterPoint="100,100" Fill="Blue" Width="100" Height="100" Opacity="0.7"/>
<Rectangle local:CenterOnPoint.CenterPoint="0,0" Fill="Yellow" Width="100" Height="100" Opacity="0.7"/>
<Rectangle local:CenterOnPoint.CenterPoint="1024,0" Fill="Yellow" Width="100" Height="100" Opacity="0.7"/>
<Rectangle local:CenterOnPoint.CenterPoint="0,768" Fill="Yellow" Width="100" Height="100" Opacity="0.7"/>
<Rectangle local:CenterOnPoint.CenterPoint="1024,768" Fill="Yellow" Width="100" Height="100" Opacity="0.7"/>
<Rectangle local:CenterOnPoint.CenterPoint="500, 0" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="600, 768" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="500, 868" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="500, -100" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="0,350" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="1000,384" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="512,384" Fill="YellowGreen" Height="153.6" Width="204.8" Opacity="0.5"/>
<Image local:CenterOnPoint.CenterPoint="512,384" Source="IMG_4831.JPG" Width="100" Height="150" Stretch="Fill" />
</local:ScalingCanvas>
</Grid>
</local:ScalingCanvas>
</VisualBrush.Visual>
</VisualBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
<GeometryModel3D.Transform >
<Transform3DGroup>
<MatrixTransform3D x:Name="xform" />
</Transform3DGroup>
</GeometryModel3D.Transform>
</GeometryModel3D>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D x:Name="mesh1"
Positions="0 0 0, 0 1 0, 1 0 0, 1 1 0"
TextureCoordinates="0 0, 0 1, 1 0, 1 1"
TriangleIndices="0 2 1, 2 3 1" />
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<VisualBrush>
<VisualBrush.Visual>
<local:ScalingCanvas Background="Gray" Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}">
<Grid Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" ClipToBounds="True">
<local:ScalingCanvas Width="{Binding RelativeSource={RelativeSource TemplatedParent}}" Height="{Binding RelativeSource={RelativeSource TemplatedParent}}" Background="AliceBlue" Opacity="0.5">
<local:ScalingCanvas.RenderTransform>
<ScaleTransform ScaleX="{Binding ScaleX, RelativeSource={RelativeSource TemplatedParent}}" ScaleY="{Binding ScaleY, RelativeSource={RelativeSource TemplatedParent}}"/>
</local:ScalingCanvas.RenderTransform>
<Rectangle Height="768" Width="1024"/>
<Rectangle local:ScalingCanvas.Top="200" local:ScalingCanvas.Left="200" Fill="Aqua" Width="100" Height="100" />
<Rectangle local:CenterOnPoint.CenterPoint="100,100" Fill="Blue" Width="100" Height="100" Opacity="0.7"/>
<Rectangle local:CenterOnPoint.CenterPoint="0,0" Fill="Yellow" Width="100" Height="100" Opacity="0.7"/>
<Rectangle local:CenterOnPoint.CenterPoint="1024,0" Fill="Yellow" Width="100" Height="100" Opacity="0.7"/>
<Rectangle local:CenterOnPoint.CenterPoint="0,768" Fill="Yellow" Width="100" Height="100" Opacity="0.7"/>
<Rectangle local:CenterOnPoint.CenterPoint="1024,768" Fill="Yellow" Width="100" Height="100" Opacity="0.7"/>
<Rectangle local:CenterOnPoint.CenterPoint="500, 0" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="600, 768" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="500, 868" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="500, -100" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="0,350" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="1000,384" Fill="Black" Height="100" Width="100"/>
<Rectangle local:CenterOnPoint.CenterPoint="512,384" Fill="YellowGreen" Height="153.6" Width="204.8" Opacity="0.5"/>
<Image local:CenterOnPoint.CenterPoint="512,384" Source="IMG_4831.JPG" Width="100" Height="150" Stretch="Fill" />
</local:ScalingCanvas>
</Grid>
</local:ScalingCanvas>
</VisualBrush.Visual>
</VisualBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
<GeometryModel3D.Transform >
<Transform3DGroup>
<MatrixTransform3D x:Name="xform2" />
</Transform3DGroup>
</GeometryModel3D.Transform>
</GeometryModel3D>
<!--Light source.-->
<AmbientLight Color="White" />
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
<!-- Camera. -->
<Viewport3D.Camera>
<OrthographicCamera Position="0.5 0.5 1"
LookDirection="0 0 -1"
UpDirection="0 1 0"
Width="1"
/>
</Viewport3D.Camera>
</Viewport3D>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
The Projektor class will be posted as an answer because the limitation of character. If you need anything to clear things up just let me know! & is this question to big in general? I welcome cunstructive critic! :)