Question

I'm displaying a scene with some cubes in it. The camera uses persective. Everything works great, but I'd like the vertical lines to be parallel (two point perspective: http://en.wikipedia.org/wiki/Perspective_(graphical)#Two-point_perspective).

When viewing a cube from the front:

What I want:

+-----+
|     |
|     |
+-----+

What I'm getting (exaggerated):

+--------+
 \      /
  \    /
   +--+

I've tried fiddling with the camera's FOV, but to no avail.

My attempt so far:

Camera = SceneManager.CreateCamera(CameraName);
float q = 45;
float d = 5000f;
Matrix4 m = new Matrix4(
    1, 0, 0, (float)(Math.Sin(q)/d),
    0, 1, 0, 0,
    0, 0, 1, (float)(Math.Cos(q)/d),
    0, 0, 0, 0
    );
Camera.SetCustomProjectionMatrix(true, m);
Was it helpful?

Solution

The University of Berkeley has a page on the different perspective transformations and the matrices you need to use. The two-point perspective transformation is:

  _                    _
 |  1   0   0 sin(q)/d  |
 |  0   1   0     0     |
 |  0   0   1 cos(q)/d  |
 |_ 0   0   0     0    _|

Where q is the angle used to rotate the points (rather than the axes) and d is unexplained(!) but I think it's the distance of the camera from the focal plane.

enter image description here

Source

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top