ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

WPF 透视相机的UpDirection(向上方向)

2020-03-08 10:56:35  阅读:306  来源: 互联网

标签:CultureInfo object UpDirection 相机 culture values WPF Type public


透视相机的updirection,是具有三个参数的的属性(X,Y,Z),不过Z属性是没有作用的。

也就是说这一个立体中的平面坐标系。

那么X,Y是什么呢?

我们知道在X,Y坐标轴系内单位圆上的点,都是可以用的cosX,sinY来表示。

网上找的图

 

 

假设,XY坐标系内画一个直径为1的圆(圆心[0,0])

确定好圆上的点连接圆心之后和Y轴之间的夹角之后再用反三角函数求出角度即可

比如说我用sin函数

当确定X,Y值后,点连接圆心,长度为1,圆心角的对边长度为X坐标,斜边长度为1(不知道为什么直接写1不好使,必须用勾股定理求一下斜边),之后再arcsin函数转角度就好了。

转换器

 class MC : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var v = Activator.CreateInstance(targetType,values);
            return v;
       //     throw new NotImplementedException();
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    class Deg : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            double a = double.Parse(values[0].ToString());
            double b = double.Parse(values[1].ToString());
            var d = Math.Sqrt(a * a + b * b);
            Debug.WriteLine(d);
            var c = (Math.Asin(a/d )/Math.PI) * 180.0;
            return c.ToString();
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

 

 

<Window.Resources>
        <local:MC x:Key="mc"/>
        <local:Deg x:Key="dc"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Viewport3D>
            <Viewport3D.Camera>
                <PerspectiveCamera Position="0,0,10"   LookDirection="0,0,-10">
                    <PerspectiveCamera.UpDirection>
                        <MultiBinding  Converter="{StaticResource mc}">
                            <Binding ElementName="s1" Path="Value"/>
                            <Binding ElementName="s2" Path="Value"/>
                            <Binding ElementName="s3" Path="Value"/>
                        </MultiBinding>
                    </PerspectiveCamera.UpDirection>
                </PerspectiveCamera>
            </Viewport3D.Camera>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <DirectionalLight Color="White" Direction="-1,-1,-1"/>
                </ModelVisual3D.Content>
            </ModelVisual3D>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                   
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D Positions="-1,0,0  0,1,0  1,0,0" TriangleIndices="0,2,1"/>
                        </GeometryModel3D.Geometry>
                        <GeometryModel3D.Material>
                            <DiffuseMaterial Brush="Red"   />
                        </GeometryModel3D.Material>
                    </GeometryModel3D>
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </Viewport3D>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <StackPanel >
                <Slider LargeChange="0.1" Maximum="1" Minimum="-1" Value="{Binding ElementName=c1, Path=Text,UpdateSourceTrigger=PropertyChanged}" x:Name="s1"/>
                <Slider  LargeChange="0.1" Maximum="1" Minimum="-1" Value="{Binding ElementName=c2, Path=Text,UpdateSourceTrigger=PropertyChanged}" x:Name="s2"/>
                <Slider Maximum="10" Minimum="-10" Value="0" x:Name="s3"/>
              
            </StackPanel>
            <StackPanel Grid.Column="1">
                <TextBlock Text="{Binding ElementName=s1,Path=Value}"/>
                <TextBlock  Text="{Binding ElementName=s2,Path=Value}"/>
                <TextBlock Text="{Binding ElementName=s3,Path=Value}"/>
                <TextBlock >
                    <TextBlock.Text>
                        <MultiBinding Converter="{StaticResource dc}">
                            <Binding ElementName="s1" Path="Value"/>
                            <Binding ElementName="s2" Path="Value"/>
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>
                <TextBox x:Name="c1"/>
                <TextBox  x:Name="c2"/>
            </StackPanel>
        </Grid>
    </Grid>

 

值得注意的是 这个是旋转的是摄像机旋转,物体是不动的,也就是左右方向是反的。

最后上传

其他软件的对照角度和XY坐标,可以自己验证一下

 

标签:CultureInfo,object,UpDirection,相机,culture,values,WPF,Type,public
来源: https://www.cnblogs.com/T-ARF/p/12441316.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有