tags:

views:

171

answers:

1

Hi,

I started to learn some 3D in WPF today and I copied some simple examples (planes) into my XAML, and they all worked. However, when I adjusted the camera's and the plane's coordinates to meet my needs, I always see nothing.

I do not know what I am doing wrong, and I also already sketched the (really simple) 3D scene to verify my data, and it all seems correct to me.

Could anyone please check the following XAML and tell me what I am doing wrong? I only want to create a plane in the x-z-plane, i.e. some sort of "floor" with the camera looking down on it from the top.

<Viewport3D>
    <Viewport3D.Camera>
        <PerspectiveCamera Position="0 1 0"
                           LookDirection="0 -1 0"
                           FieldOfView="60"/>
    </Viewport3D.Camera>
    <Viewport3D.Children>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <AmbientLight Color="White"/>
            </ModelVisual3D.Content>
        </ModelVisual3D>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <GeometryModel3D>
                    <GeometryModel3D.Geometry>
                        <MeshGeometry3D>
                            <MeshGeometry3D.Positions>
                                <Point3D X="-1" Y="0"   Z="1"/>
                                <Point3D X="1"  Y="0"   Z="1"/>
                                <Point3D X="1"  Y="0"   Z="-1"/>
                                <Point3D X="-1" Y="0"   Z="-1"/>
                            </MeshGeometry3D.Positions>
                            <MeshGeometry3D.TriangleIndices>
                                0 1 2  0 2 3
                            </MeshGeometry3D.TriangleIndices>
                            <MeshGeometry3D.Normals>
                                <Vector3D X="0" Y="1" Z="0"/>
                                <Vector3D X="0" Y="1" Z="0"/>
                                <Vector3D X="0" Y="1" Z="0"/>
                                <Vector3D X="0" Y="1" Z="0"/>
                                <Vector3D X="0" Y="1" Z="0"/>
                                <Vector3D X="0" Y="1" Z="0"/>
                            </MeshGeometry3D.Normals>
                        </MeshGeometry3D>
                    </GeometryModel3D.Geometry>
                    <GeometryModel3D.Material>
                        <MaterialGroup>
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <SolidColorBrush Color="Red" Opacity="0.75"/>
                                </DiffuseMaterial.Brush>
                            </DiffuseMaterial>
                        </MaterialGroup>
                    </GeometryModel3D.Material>

                </GeometryModel3D>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D.Children>

</Viewport3D>

EDIT: I just experimented with the camera's Position and LookDirection, and finally saw something when I changed the LookDirection to be not perpendicular to the plane, for example:

<PerspectiveCamera Position="0 2 0"
                   LookDirection="0 -2 1"
                   FieldOfView="60"/>

Is this normal behavior?

Many thanks!

gehho.

+2  A: 

When you are pointing the camera, it is important to watch out for the Up vector as well as the Look direction.

The problem comes from the default value for the Up vector (PerspectiveCamera.UpDirection), which is [0,1,0]. The camera's Look and Up vectors must not be parallel, because in that case it would be impossible to tell which way is up.

Since your model is in the XZ plane, and you want to look down over it, you can simply set UpDirection to [0,0,1] or [1,0,0], so that up points in the direction of either the Z or the X axis, respectively. But if you are planning on allowing the camera to look in all directions, you should be taking care of the Up vector too.

Yanko Yankov
That did the trick! Did not think about adjusting the up-direction. Thanks a lot!
gehho