大家好,这是我在这里的第一个问题。所以请随时给我CC :)
关于该项目。我想在不触及 Z 轴(0,0,0 0,1,0 1,0,0 1,1,0)的情况下从平面多边形平面进行非仿射变换。我需要通过定位它的 4 个角点来做到这一点。我通过使用 Charles Petzold ( http://www.charlespetzold.com/blog/2007/08/250638.html ) 的“2D 非仿射变换”实现了这一点。
到目前为止一切都很好。也没有消失的飞机。
因为我需要画笔/纹理来扩展平面的边缘。我决定添加三角形,直到我有 5x5 的平面网格。(通过选择第一个平面的角点(它是中间的那个),整个几何图形仍然可以变换。)
可悲的是,我还不允许发布图片。
https://i.imgur.com/oG3gKRD.png
浅蓝色的矩形是具有可选角的矩形,紫色是其余的(对于图片我包含另一个平面(与大平面没有连接,只是为了表明没有疯狂的变换效果)只有值相差 1(无论哪个角)
https://i.imgur.com/wSkywVk.png
据我所知,这不是相机的问题。改变很多东西的值,比如相机/近和远平面距离。如果我将网格缩小到 3x3 平面,这种定位总是会导致不可见的几何图形(它不是唯一的位置,其中有一些,但我看不到连接)我有同样的问题,仅在其他职位上。对象仍然存在,只是不可见(我仍然可以选择角点,它会立即再次可见)
有谁知道会导致什么?或者有人知道我如何调试这样的“错误”吗?
也许它是一般增长可变形平面的错误方法?如果有人有想法,请告诉我!
设置两个平面的几何图形(两个自定义类“scalingCanvas”和“CenterOnPoint”,您可以使用具有正常定位的普通画布)
<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 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 3
-2 1, -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>
由于字符的限制,Projektor 课程将作为答案发布。如果您需要任何事情来解决问题,请告诉我!& 这个问题一般来说大吗?我欢迎 cunstructive 批评家!:)