Пример #1
0
        /// <summary>
        /// The view matrix from the camera can not be used for the projection
        /// because it is possible to be in a invalid direction where the
        /// projection math does not work.
        /// Instead create a new view matrix that re-aims the view to a
        /// direction that is always valid. I found a simple view looking down
        /// and a bit forward works best.
        /// </summary>
        void AimProjector(Camera cam)
        {
            //Copy camera projection into projector projection
            CopyMatrix(m_projectorP, cam.projectionMatrix);

            CopyVector3(m_pos, cam.transform.position);
            CopyVector3(m_dir, cam.transform.forward);

            //CopyMatrix(m_projectorV, cam.worldToCameraMatrix);
            //return;

            double level = m_ocean.level;

            double range = Math.Max(1.0, m_ocean.FindMaxDisplacement(true));
            //double range = Ocean.MAX_WAVE_HEIGHT;

            double maxHeight = Math.Max(0.0, range + 10.0);

            //The projection must stay above the ocean level.
            if (m_pos[1] < level)
            {
                m_pos[1] = level;
            }

            //Set the projection a bit above the camera
            //and above the max wave height.
            m_pos[1] += maxHeight;

            //Look a bit in front of view.
            m_lookAt[0] = m_pos[0] + m_dir[0] * 50.0;
            m_lookAt[1] = m_ocean.level;
            m_lookAt[2] = m_pos[2] + m_dir[2] * 50.0;

            LookAt(m_pos, m_lookAt, m_up);
        }
Пример #2
0
        /// <summary>
        /// The view matrix from the camera can not be used for the projection
        /// because it is possible to be in a invalid direction where the
        /// projection math does not work.
        /// Instead create a new view matrix that re-aims the view to a
        /// direction that is always valid. I found a simple view looking down
        /// and a bit forward works best.
        /// </summary>
        void AimProjector(Camera cam)
        {
            //Copy camera projection into projector projection
            m_projectorP = cam.projectionMatrix;

            Vector3 pos    = cam.transform.position;
            Vector3 dir    = cam.transform.forward;
            Vector3 lookAt = new Vector3();

            float level = m_ocean.level;

            float range = Mathf.Max(1.0f, m_ocean.FindMaxDisplacement(true));
            //float range = Ocean.MAX_WAVE_HEIGHT;

            float maxHeight = Mathf.Max(0.0f, range + 10.0f);

            //The projection must stay above the ocean level.
            if (pos.y < level)
            {
                pos.y = level;
            }

            //Set the projection a bit above the camera
            //and above the max wave height.
            pos.y += maxHeight;

            //Look a bit in front of view.
            lookAt   = pos + dir * 50.0f;
            lookAt.y = m_ocean.level;

            LookAt(pos, lookAt, Vector3.up);
        }
Пример #3
0
        /// <summary>
        /// The view matrix from the camera can not be used for the projection
        /// because it is possible to be in a invalid direction where the
        /// projection math does not work.
        /// Instead create a new view matrix that re-aims the view to a
        /// direction that is always valid. I found a simple view looking down
        /// and a bit forward works best.
        /// </summary>
        void AimProjector(Camera cam)
        {
            //Copy camera projection into projector projection
            CopyMatrix(m_projectorP, cam.projectionMatrix);

            CopyVector3(m_pos, cam.transform.position);
            CopyVector3(m_dir, cam.transform.forward);

            //CopyMatrix(m_projectorV, cam.worldToCameraMatrix);
            //return;

            double level = m_ocean.level;

            double fit = (TightFit) ? 20.0 : 50.0;

            double range = Math.Max(0.0, m_ocean.FindMaxDisplacement(true)) + fit;

            if (Ocean.DISABLE_PROJECTION_FLIPPING)
            {
                //If flipping disabled keep the projection pos above the surface.
                //Make sure projection position is above the wave range.
                if (m_pos[1] < level)
                {
                    m_pos[1] = level;
                }

                IsFlipped = false;
                m_pos[1]  = Math.Max(m_pos[1], level + range);
            }
            else
            {
                //If the camera is below the sea level then flip the projection.
                //Make sure projection position is above or below the wave range.
                if (m_pos[1] < level)
                {
                    IsFlipped = true;
                    m_pos[1]  = Math.Min(m_pos[1], level - range);
                }
                else
                {
                    IsFlipped = false;
                    m_pos[1]  = Math.Max(m_pos[1], level + range);
                }
            }

            //Look a bit in front of view.
            m_lookAt[0] = m_pos[0] + m_dir[0] * 50.0;
            m_lookAt[1] = m_ocean.level;
            m_lookAt[2] = m_pos[2] + m_dir[2] * 50.0;

            LookAt(m_pos, m_lookAt, m_up);
        }
Пример #4
0
        /// <summary>
        /// The view matrix from the camera can not be used for the projection
        /// because it is possible to be in a invalid direction where the
        /// projection math does not work.
        /// Instead create a new view matrix that re-aims the view to a
        /// direction that is always valid. I found a simple view looking down
        /// and a bit forward works best.
        /// </summary>
        void AimProjector(Camera cam)
        {
            //Copy camera projection into projector projection
            m_projectorP = cam.projectionMatrix;

            Vector3 pos    = cam.transform.position;
            Vector3 dir    = cam.transform.forward;
            Vector3 lookAt = new Vector3();

            float level = m_ocean.level;

            float fit = (TightFit) ? 20.0f : 50.0f;

            float range = Math.Max(0.0f, m_ocean.FindMaxDisplacement(true)) + fit;

            if (Ocean.DISABLE_PROJECTION_FLIPPING)
            {
                //If flipping disabled keep the projection pos above the surface.
                //Make sure projection position is above the wave range.
                if (pos.y < level)
                {
                    pos.y = level;
                }

                IsFlipped = false;
                pos.y     = Math.Max(pos.y, level + range);
            }
            else
            {
                //If the camera is below the sea level then flip the projection.
                //Make sure projection position is above or below the wave range.
                if (pos.y < level)
                {
                    IsFlipped = true;
                    pos.y     = Math.Min(pos.y, level - range);
                }
                else
                {
                    IsFlipped = false;
                    pos.y     = Math.Max(pos.y, level + range);
                }
            }

            //Look a bit in front of view.
            lookAt   = pos + dir * 50.0f;
            lookAt.y = m_ocean.level;

            LookAt(pos, lookAt, Vector3.up);
        }