2D窗口在3D空间中形成控件

时间:2009-12-16 11:36:48

标签: c# windows forms controls 3d

如果这不是发布此问题的正确位置,请原谅我。

我是dotNET的新手,对Direct3D和WPF一无所知。我在那里找到的教程似乎不适合像我这样的初学者。

我想在CSharp中创建一个简单的窗体,其2D控件放置在3D空间中,请以简单的方式指导我。

对不起,我不擅长英语,我不知道上面的问题是否足够清楚,请让我用下面的图片解释一下:

I cannot post images yet, please click this link

上面的图片并不真实,它是用photoshop编辑的,只是为了解释我想要实现的目标。)

为了更清楚,这是我很久以前在Flash工作的示例项目,我想用C#创建类似于Windows应用程序的东西:

aveltium.blogspot.com(这是我的第一篇帖子所以我不能放两个超链接

1 个答案:

答案 0 :(得分:1)

我在WPF中重新创建了你在图片中描述的场景 - 好吧,我已经完成了左右窗格 - 我将为你留下底部窗格。

您只需要在VS2008中创建一个新的WPF应用程序,并将以下XAML粘贴到Window1 XAML上并运行该应用程序......

希望这有帮助。

干杯,

安迪

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="480" Width="751">
    <Window.Resources>
        <Transform3DGroup x:Key="leftTransform" >
            <TranslateTransform3D OffsetX="-3"></TranslateTransform3D>
            <RotateTransform3D  >
                <RotateTransform3D.Rotation>
                    <AxisAngleRotation3D Axis="0,1,0" Angle="50" />
                </RotateTransform3D.Rotation>
            </RotateTransform3D>
        </Transform3DGroup>
        <Transform3DGroup x:Key="rightTransform" >
            <TranslateTransform3D OffsetX="3"></TranslateTransform3D>
            <RotateTransform3D  >
                <RotateTransform3D.Rotation>
                    <AxisAngleRotation3D Axis="0,1,0" Angle="-50" />
                </RotateTransform3D.Rotation>
            </RotateTransform3D>
        </Transform3DGroup>
        <MeshGeometry3D
                        x:Key="squareMeshFront"
                        Positions="-1.5,-1,1  1.5,-1,1  1.5,1,1  -1.5,1,1"
                        TriangleIndices="0 1 2 0 2 3"
                        TextureCoordinates="0,1 1,1 1,0 0,0" />

        <DiffuseMaterial x:Key="visualHostMaterial" Brush="White" Viewport2DVisual3D.IsVisualHostMaterial="True" />
    </Window.Resources>

    <Viewport3D>

        <Viewport3D.Camera>
            <PerspectiveCamera Position="0,0,10" LookDirection="0,0,-1" />
        </Viewport3D.Camera>

        <Viewport2DVisual3D x:Name="vpLeft" Material="{StaticResource visualHostMaterial}" Geometry="{StaticResource squareMeshFront}" Transform="{StaticResource leftTransform}" >

            <Grid Width="300" Height="200" Background="LightGray">
                <Grid.RowDefinitions>
                    <RowDefinition Height="50" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <Label Content="Panel 1" HorizontalAlignment="Left" FontSize="30"></Label>

                <Label Grid.Row="1" HorizontalAlignment="Left" Margin="0,0,10,0">ComboBox</Label>
                <ComboBox HorizontalAlignment="Left" Grid.Row="1" Grid.Column="1" Width="100" Margin="0,0,0,4" />

                <Label Grid.Row="2" HorizontalAlignment="Left" Margin="0,0,10,0">Text Box</Label>
                <TextBox HorizontalAlignment="Left" Grid.Row="2" Grid.Column="1" Width="100" Margin="0,0,0,4"></TextBox>

                <Button Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left" Width="100" Height="25">Button</Button>
            </Grid>

        </Viewport2DVisual3D>

        <Viewport2DVisual3D x:Name="vpRight" Material="{StaticResource visualHostMaterial}" Geometry="{StaticResource squareMeshFront}" Transform="{StaticResource rightTransform}" >

            <Grid Width="300" Height="200" Background="LightGray">
                <Grid.RowDefinitions>
                    <RowDefinition Height="50" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <Label Content="Panel 1" HorizontalAlignment="Left" FontSize="30"></Label>

                <Label Grid.Row="1" HorizontalAlignment="Left" Margin="0,0,10,0">ComboBox</Label>
                <ComboBox HorizontalAlignment="Left" Grid.Row="1" Grid.Column="1" Width="100" Margin="0,0,0,4" />

                <Label Grid.Row="2" HorizontalAlignment="Left" Margin="0,0,10,0">Text Box</Label>
                <TextBox HorizontalAlignment="Left" Grid.Row="2" Grid.Column="1" Width="100" Margin="0,0,0,4"></TextBox>

                <Button Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left" Width="100" Height="25">Button</Button>
            </Grid>

        </Viewport2DVisual3D>

        <ModelVisual3D>
            <ModelVisual3D.Content>
                <AmbientLight Color="White" />
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>

</Window>