Beispiel #1
0
        public void             InitializeCamera(float3 _Position, float3 _Target, float3 _Up)
        {
            // Build the camera matrix
            float3 At = _Target - _Position;

            if (At.LengthSquared > 1e-2f)
            {                   // Normal case
                m_CameraTargetDistance = At.Length;
                At /= m_CameraTargetDistance;
            }
            else
            {                   // Special bad case
                m_CameraTargetDistance = 0.01f;
                At = new float3(0.0f, 0.0f, -1.0f);
            }

            float3 Ortho = _Up.Cross(At).Normalized;

            float4x4 CameraMat = float4x4.Identity;

            CameraMat.r3 = new float4(_Position, 1.0f);
            CameraMat.r2 = new float4(At, 0.0f);
            CameraMat.r0 = new float4(Ortho, 0.0f);
            CameraMat.r1 = new float4(At.Cross(Ortho), 0.0f);

            CameraTransform = CameraMat;

            // Setup the normalized target distance
            m_NormalizedTargetDistance = NormalizeTargetDistance(m_CameraTargetDistance);
        }
Beispiel #2
0
        public void             InitializeCamera(float3 _position, float3 _target, float3 _up)
        {
            // Build the camera matrix
            float3 At = _target - _position;

            if (At.LengthSquared > 1e-2f)
            {
                // Normal case
                m_CameraTargetDistance = At.Length;
                At /= m_CameraTargetDistance;
            }
            else
            {
                // Special bad case
                m_CameraTargetDistance = 0.01f;
                At = new float3(0.0f, 0.0f, -1.0f);
            }

            float3 ortho = _up.Cross(At).Normalized;

            float4x4 cameraMat = float4x4.Identity;

            cameraMat[3] = new float4(_position, 1.0f);
            cameraMat[2] = new float4(At, 0.0f);
            cameraMat[0] = new float4(ortho, 0.0f);
            cameraMat[1] = new float4(At.Cross(ortho), 0.0f);

            CameraTransform = cameraMat;

            // Setup the normalized target distance
            m_NormalizedTargetDistance = NormalizeTargetDistance(m_CameraTargetDistance);
        }