possible 3D LookDirection bug

the scene has a cube at the origin. the camera is looking down on it from LookDirection="0,.0001,-1" ... and that works. but if i change it to LookDirection="0,0,-1" ... then the cube cannot be seen. i'm assuming a DivideByZero bug happens somewhere during processing?

Just copy/paste the XAML below into a file and open in IE.

Thanks, casey

<CanvasClipToBounds="true"Width="400"Height="300"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"xmlns:c="http://schemas.openxmlformats.org/markup-compatibility/2006"c:Ignorable="d">

<Viewport3DClipToBounds="true"Width="400"Height="400">

<Viewport3D.Camera>

<!--WORKS can see the cube, if LookDirection is not quite zero-->

<PerspectiveCameraFarPlaneDistance="20"LookDirection="0,.0001,-1"UpDirection="0,0,1"NearPlaneDistance="1"Position="0,0,10"FieldOfView="45" />

<!--FAILS cannot see the cube-->

<!--PerspectiveCamera FarPlaneDistance="20" LookDirection="0,0,-1" UpDirection="0,0,1" NearPlaneDistance="1" Position="0,0,10" FieldOfView="45" /-->

</Viewport3D.Camera>

<ModelVisual3D>

<ModelVisual3D.Content>

<Model3DGroupx:Name="Scene">

<Model3DGroup.Transform>

<Transform3DGroup>

<TranslateTransform3DOffsetX="0"OffsetY="0"OffsetZ="0"/>

<ScaleTransform3DScaleX="1"ScaleY="1"ScaleZ="1"/>

<RotateTransform3D>

<RotateTransform3D.Rotation>

<AxisAngleRotation3DAngle="0"Axis="0 1 0"/>

</RotateTransform3D.Rotation>

</RotateTransform3D>

<RotateTransform3D>

<RotateTransform3D.Rotation>

<AxisAngleRotation3DAngle="0"Axis="1 0 0"/>

</RotateTransform3D.Rotation>

</RotateTransform3D>

<TranslateTransform3DOffsetX="0"OffsetY="0"OffsetZ="0"/>

</Transform3DGroup>

</Model3DGroup.Transform>

<AmbientLightColor="#646464" />

<Model3DGroupxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

<Model3DGroup.Children>

<GeometryModel3D>

<!--left handed world-->

<GeometryModel3D.BackMaterial>

<DiffuseMaterial>

<DiffuseMaterial.Brush>

<SolidColorBrushColor="Red"Opacity="1.0" />

</DiffuseMaterial.Brush>

</DiffuseMaterial>

</GeometryModel3D.BackMaterial>

<GeometryModel3D.Geometry>

<MeshGeometry3Dx:Key="myCube"TriangleIndices="0 2 1 0 3 2 1 5 4 1 2 5 0 6 7 0 7 3 6 4 5 6 7 5 3 5 2 3 7 5 0 1 4 0 4 6"

TextureCoordinates="1,0 0,0 0,1 1,1 0,0 0,1 1,0 1,1"

Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1"

Positions="1,1,0 0,1,0 0,0,0 1,0,0 0,1,-1 0,0,-1 1,1,-1 1,0,-1" />

</GeometryModel3D.Geometry>

</GeometryModel3D>

</Model3DGroup.Children>

</Model3DGroup>

</Model3DGroup>

</ModelVisual3D.Content>

</ModelVisual3D>

</Viewport3D>

</Canvas>

[7720 byte] By [kcchesnut] at [2007-12-24]
# 1

First, you need to drop the Key off the MeshGeometry3D...XAMLPad doesn't like it for some reason.

Second, I cut and pasted your Model3DGroup into the Viewport3D sample that is in the ProjectionCamera documentation and it works fine. The problem appears to be that you're setting the UpDirection to be the same as your LookDirection. If you switch it from UpDirection="0,0,-1" to UpDirection="0,-1,0" you fix your problem.

ivolved_Mike_Brown at 2007-10-8 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

as you said, that would mean UpDirection is overriding LookDirection. but this only happens for 0,0,-1 ... but not for 0,.0001,-1? possibly only when they are inverse.

and here's a little backstory. although the scene above is static, our app has a dynamic camera. initially we set the UpDirection to 0,0,1, and then never change it. all we change is the camera's position and look direction. so the camera can be moved to where it's UpDirection is still 0,0,1 but its LookDirection is 0,0,-1 ... at which point the models can no longer be seen. then you move the camera a little bit and the models come back.

Thanks, casey

kcchesnut at 2007-10-8 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3
To further discuss this issue, it looks like when Up and Look direction share two coordinates in their vector, UpDirection overrides LookDirection. It would help if someone from the WPF team provides input on what drives the view logic for a camera.
ivolved_Mike_Brown at 2007-10-8 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4

When building the view transform, we need the vector perpendicular to Look and Up and this is accomplished with the cross product. However, cross(u, u) or cross(u, -u) is the zero vector which messes up the transform. If you keep rotating Look more, your scene will flip which isn't desirable either.

I can think of two ways to avoid the issue:
1) Move Up as well
2) Leave Look and Up alone and use Camera.Transform to rotate/translate instead

#2 is the better solution I think.

(You can find all of the math behind viewing in any decent 3D graphics book)

JordanParker-MSFT at 2007-10-8 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 5
Ahhhh...a transform...I should have known!
ivolved_Mike_Brown at 2007-10-8 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified