Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Camera LookDirection look front face

Tags:

c#

wpf

camera

3d

How to look at the front of 3D Model in WPF?

I am confused to set X Y Z for LookDirection.

I don't know what happens when I set xyz and I don't know where camera is looking at. I don't know the same thing for UpDirection.

Below is my camera properties:

camera.Position = new Point3D(100, 100, 150);
camera.LookDirection = new Vector3D(-100, -100, -100);
camera.UpDirection = new Vector3D(0, 0, 1);

The problem is that camera is looking from behind. Model is shown like cube below.

enter image description here

How to make it look front face?

Also please explain how to set xyz. i know what properties do but i cant imagine them.

I think X is from right to left.Y is depth. Z is up to down .

like image 519
M.kazem Akhgary Avatar asked Dec 05 '22 21:12

M.kazem Akhgary


1 Answers

Imagine, instead of a camera, you're moving your head around in 3D space. then Camera.Position is specifying where your head is located, Camera.LookDirection determines the direction you're looking at and Camera.UpDirection shows the orientation of your head. the following pictures clear things up for you.

In the first Image, Camera is centered on the +Z axis looking down to -Z axis and to your shape:

enter image description here

When you set camera.Position to for example (x=1, y=0, z=10) then camera position changes like this:

enter image description here

as a result, camera moves a little to the right and therefore you will see your shape at the left side of the view.

Now if camera.LookDirection gets changed to say (x=0, y=1, z=-1), then camera simply looks at the point (0,1,-1) like this:

enter image description here


Important Edit:

Based on DaveInCaz's comment, LookDirection is different from LookAtPoint (former property of PrespectiveCamera which was a Point3D rather than Vector3D).

LookDirection is actually equals to "the point to look at" minus "camera position".

This means that in the above diagram, if we want the camera which is located in (1,0,10) to look at point (0,1,-1) then the LookDirection should be:

(0,1,-1) - (1,0,10) = (-1,1,-11).


And finally, camera.UpDirection determines where the top of your camera points at. In the following picture, setting camera.UpDirection to (-0.5,1,0) results in rotation of the camera counter clockwise:

enter image description here

I hope these pictures clear things up for you.

like image 103
Bahman_Aries Avatar answered Dec 08 '22 09:12

Bahman_Aries