Reputation: 2403
I am working on a flooring visualizer (for a tile floor in perspective) and am going bonkers over the camera. Basically, I have a 2D rectangle (on the X & Y axis) and I want to look at the square as if it were a floor (which I'll "tile" later - similar to a checkerboard). The problem is, after spending hours fiddling with the LookDirection and Position (in the perspective camera), I can't seem to get it to look straight at the square (as if looking into the room). Nothing I change allows me to look at the scene "head on" (with either the X or Y axis in the "back") and it's always stuck at an angle. I don't want to rotate the model, only the camera. How do I do this?
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="-40,60,50" LookDirection="0.8,-.7,-0.8" UpDirection="0,0,1" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<DirectionalLight Color="White" Direction="-1,-1,-3" />
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="0,0,0 25,0,0 25,25,0 0,25,0 " TriangleIndices="0 1 3 1 2 3 "/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="Red"/>
</GeometryModel3D.Material>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
Upvotes: 0
Views: 2216
Reputation: 1389
I believe you're stuck at an angle because of your LookDirection
. This is a direction vector, so having X
, Y
, and Z
set is going to give you that offset look. You're pointing off into space at an angle rather than straight ahead. To look straight ahead, set X
to 0 in your LookDirection
and instead move the camera's Position X
to the center of your scene, which is 12.5 (because your square goes from 0 to 25).
<PerspectiveCamera Position="12.5,60,50" LookDirection="0,-.7,-0.8" UpDirection="0,0,1" />
That will produce a "head on" view. Based on what you said, it seemed like you wanted to be closer to the "floor", so I moved the Position
closer to the "floor" and reduced the angle on the LookDirection
vector, like so.
<PerspectiveCamera Position="12.5,50,20" LookDirection="0,-.7,-0.35" UpDirection="0,0,1" />
This produced the following.
Upvotes: 2