MVP Matrix
HoloLensアプリ実装の要件の一つが、あるプラグインを使用してホログラムを表示する、というものだった。
Unity Editor上では問題なく表示されたものの、HoloLensにdeployすると逆さまに表示されてしまった。
MVP(Model View Projection)Matrixの算出方法を修正することでこのバグは解消されるようである。
Unity上での座標系(Coordinate System)からくるもので、プラグインなど使用した際にはしばしば起こるもののようだ。
Ref
- http://answers.unity3d.com/questions/20337/flipmirror-camera.html
- http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/
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;
}