Пример #1
0
        public override void UpdateMatrixWorld(bool force = false)
        {
            if (matrixAutoUpdate)
            {
                UpdateMatrix();
            }

            // update matrixWorld
            if (matrixWorldNeedsUpdate || force)
            {
                if (HasParent)
                {
                    matrixWorld.MultiplyMatrices(Parent.matrixWorld, matrix);

                    matrixWorld.Decompose(ref translationWorld, ref quaternionWorld, ref scaleWorld);
                    matrix.Decompose(ref translationObject, ref quaternionObject, ref scaleObject);
                    matrixWorld = Matrix4.Compose(translationWorld, quaternionObject, scaleWorld);
                }
                else
                {
                    matrixWorld = matrix;
                }


                matrixWorldNeedsUpdate = false;
                force = true;
            }

            // update children
            foreach (var c in Children)
            {
                c.UpdateMatrixWorld(force);
            }
        }
        private void InitializeCameras()
        {
            float viewCenter             = m_oculusDevice.HScreenSize * 0.25f;
            float eyeProjectionShift     = viewCenter - m_oculusDevice.LensSeparationDistance * 0.5f;
            float projectionCenterOffset = 4.0f * eyeProjectionShift / m_oculusDevice.HScreenSize;

            // Create projection matrix
            float   aspectRatio        = m_oculusDevice.HorizontalResolution / (2 * (float)m_oculusDevice.VerticalResolution);
            float   halfScreenDistance = (m_oculusDevice.VScreenSize / 2);
            float   yfov       = (float)2.0f * (float)Math.Atan(halfScreenDistance / m_oculusDevice.EyeToScreenDistance);
            Matrix4 projMatrix = m_root.RenderSystem.MakeProjectionMatrix(yfov, aspectRatio, 0.3f, 1000.0f);

            //Matrix4 projMatrixL = Matrix4.Compose(new Vector3(projectionCenterOffset, 0, 0), new Vector3(1.0f, 1.0f, 1.0f), Quaternion.Identity);
            //projMatrixL = Matrix4.Multiply(projCenterMatrix, projMatrixL);

            //Matrix4 projMatrixR = Matrix4.Compose(new Vector3(-projectionCenterOffset, 0, 0), new Vector3(1.0f, 1.0f, 1.0f), Quaternion.Identity) * projCenterMatrix;

            // Create view matrix
            float   halfIPD     = m_oculusDevice.InterpupillaryDistance * 0.5f;
            Matrix4 viewMatrixL = Matrix4.Compose(new Vector3(halfIPD, 0, 0), new Vector3(1.0f, 1.0f, 1.0f), Quaternion.Identity) * viewCenter;
            Matrix4 viewMatrixR = Matrix4.Compose(new Vector3(-halfIPD, 0, 0), new Vector3(1.0f, 1.0f, 1.0f), Quaternion.Identity) * viewCenter;

            // Create cameras array
            m_camera = new Camera[2];

            // Left camera
            m_camera[0] = m_sceneManager.CreateCamera("LeftCamera");
            m_camera[0].Move(new Vector3(0, 0, 1));
            m_camera[0].SetCustomProjectionMatrix(true, projMatrix);
            //m_camera[0].SetCustomViewMatrix(true, viewMatrixL);

            // Right camera
            m_camera[1] = m_sceneManager.CreateCamera("RightCamera");
            m_camera[1].Move(new Vector3(0, 0, 1));
            m_camera[1].SetCustomProjectionMatrix(true, projMatrix);
            //m_camera[1].SetCustomViewMatrix(true, viewMatrixR);
        }
Пример #3
0
 public void UpdateMatrix()
 {
     matrix = Matrix4.Compose(Position, Quaternion, Scale);
     matrixWorldNeedsUpdate = true;
 }