tags:

views:

187

answers:

1

I'm attempting to position my perspective camera 30 units above the origin and pointing straight down.

If I set the LookDirection of the camera to "0,0,-1", however, everything disappears. I have to make it "0.01,0.01,-1" for it to work. Why?

<Window
    x:Class="ThreeDeeTester.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1"
    Height="300"
    Width="300">
    <Grid>
        <Viewport3D>
            <Viewport3D.Camera>
                <PerspectiveCamera
                    Position="0,0,30"
                    LookDirection="0.01,0.01,-1" 
                    UpDirection="0,0,1" />
                    <!-- LookDirection="0,0,-1" doesn't work...why? -->
            </Viewport3D.Camera>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <Model3DGroup>
                        <DirectionalLight
                            Color="White"
                            Direction="1,-1,-1" />
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
                                    Positions="0,0,10 -5,-5,0 -5,5,0 5,5,0 5,-5,0"
                                    TriangleIndices="2 1 0  2 0 3  4 3 0  1 4 0" />
                            </GeometryModel3D.Geometry>
                            <GeometryModel3D.Material>
                                <DiffuseMaterial Brush="Red" />
                            </GeometryModel3D.Material>
                        </GeometryModel3D>
                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </Viewport3D>
    </Grid>
</Window>
+1  A: 

It's probably trying to recreate the full camera matrix, starting with a cross product between the LookDirection and UpDirection. The result of a cross product between parallel vectors is zero, so you end up basically creating a completely invalid view matrix.

Since you're also setting the UpDirection, why not set it to the direction that the top of the screen faces? That's what you should be doing, anyway. Picture yourself looking down at your shoes, what direction is your head pointing?

LookDirection and UpDirection should be as close to right angles from one another as possible. Presumably the software will "fix" things if they aren't exact, but if you're looking "pretty much straight down," it's probably a good idea to indicate where you want the top of the camera facing. Certainly this is only a real problem when you're looking straight down, though, since any angle between those vectors can be used to figure out what the correct right angle vector from the LookDirection is. Only when they are actually parallel does it become impossible to know what the camera's orientation should be.

Edit: Short answer: make your UpDirection 0,1,0

dash-tom-bang
Perfect answer, thank you :)
DanM
You should play around with the UpDirection, it might give you a better feel for what it does. Good luck!
dash-tom-bang