LoginSignup
2
1

More than 5 years have passed since last update.

Unity | 逆さま(Upside down)に表示されるオブジェクトのMVPを変更(Matrix4x4)

Posted at

MVP Matrix

HoloLensアプリ実装の要件の一つが、あるプラグインを使用してホログラムを表示する、というものだった。
Unity Editor上では問題なく表示されたものの、HoloLensにdeployすると逆さまに表示されてしまった。
MVP(Model View Projection)Matrixの算出方法を修正することでこのバグは解消されるようである。

Unity上での座標系(Coordinate System)からくるもので、プラグインなど使用した際にはしばしば起こるもののようだ。

Ref

private Matrix4x4 q1; // identity

    public void Update(Camera cam, Matrix4x4 m)
    {
        /*
        some code...
        */

        // matrix stuff
        Matrix4x4 v = cam.worldToCameraMatrix;
        // added matrix multiplication
        v *= Matrix4x4.Scale(new Vector3(-1.0f, 1.0f, 1.0f));

        Matrix4x4 mat = Camera.main.projectionMatrix;
        // added matrix multiplication
        mat *= Matrix4x4.Scale(new Vector3(1.0f, -1.0f, 1.0f));

        Matrix4x4 p = GL.GetGPUProjectionMatrix(mat, false);

        MVP = q1 * p * v * m;

    }
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1