zbw911
zbw911

Reputation: 98

how to convert MatrixCamera's setting to ProjectionCamera

how to convert MatrixCamera's setting to ProjectionCamera

My code looks like:

            var vm = new Matrix3D(matrixarray[0], matrixarray[1], matrixarray[2], matrixarray[3], matrixarray[4],
                              matrixarray[5], matrixarray[6], matrixarray[7], matrixarray[8], matrixarray[9],
                              matrixarray[10], matrixarray[11], matrixarray[12], matrixarray[13],
                              matrixarray[14], matrixarray[15]);




        var pm = this.CreateFrustumMatrix(frustumArray[0], frustumArray[1], frustumArray[2], frustumArray[3],
                                          frustumArray[4], frustumArray[5]);
        var mc = new MatrixCamera(vm, pm);

But I Want Use a ProjectionCamera ,so , I Want Convert it to ProjectionCamera

Upvotes: 0

Views: 168

Answers (1)

Andon M. Coleman
Andon M. Coleman

Reputation: 43369

ProjectionCamera is an abstract class that PerspectiveCamera and OrthographicCamera share.

If you want perspective (objects farther away appear smaller), then construct a PerspectiveCamera, otherwise construct an OrthographicCamera.

You'll need the look vector, up vector, eye point and field of view in order to construct either of these cameras. You can get these vectors directly from rows in the view matrix (look, up and eye) and projection matrix (fov).

Using your view matrix:

Look: <m13, m23, m33>
Up:   <m12, m22, m32>
Eye:  <m41, m42, m43>

NOTE: m13 means matrix [0][2]... since the matrix is laid out as a linear block of memory, you'd access it like this: matrix [x*4+y].

Using your projection matrix:

FOV: 2.0 * tan^-1 (1.0 / m11)

NOTE: tan^-1 is known as Math.Atan (...) in C#

Upvotes: 1

Related Questions