Exemplo n.º 1
0
        public static Matrix ProjectionMapping(
            int ref_camera,
            SCN0Node node,
            ModelPanelViewport v,
            float frame)
        {
            Matrix   projMtx = Matrix.Identity;
            Matrix   camMtx  = Matrix.Identity;
            GLCamera cam     = v.Camera;

            if (ref_camera >= 0 && node?.CameraGroup != null && ref_camera < node.CameraGroup.Children.Count)
            {
                // Set so that the image is projected from the specified camera.
                // Transform to the viewing coordinate system of the specified camera
                SCN0CameraNode camNode = (SCN0CameraNode)node.CameraGroup.Children[ref_camera];
                camNode.GetModelViewMatrix(frame, out Matrix cm, out Matrix cmInv);
                camMtx  = cm * cam._matrix;
                projMtx = (Matrix)ProjectionTexMtx(camNode, frame);
            }
            else
            {
                camMtx  = cam._matrix;
                projMtx = (Matrix)ProjectionTexMtx(cam);
            }

            return(projMtx * camMtx);
        }
Exemplo n.º 2
0
        public static Matrix EnvCamMap(int refCam, SCN0Node node, ModelPanelViewport v, float frame)
        {
            GLCamera cam = v.Camera;

            if (refCam >= 0 && node?.CameraGroup != null && refCam < node.CameraGroup.Children.Count)
            {
                SCN0CameraNode camNode = (SCN0CameraNode)node.CameraGroup.Children[refCam];
                camNode.GetModelViewMatrix(frame, out Matrix cm, out Matrix cmInv);
                return((Matrix)EnvironmentTexMtx() * cm.GetRotationMatrix());
            }

            return((Matrix)EnvironmentTexMtx() * v.Camera._matrix.GetRotationMatrix());
        }
Exemplo n.º 3
0
        /// <summary>
        /// This function returns a texture matrix
        /// that will aim the texture to the midpoint between the active camera
        /// and the given reference camera or light.
        /// </summary>
        public static Matrix EnvSpecMap(
            int refCam,
            int refLight,
            SCN0Node node,
            ModelPanelViewport v,
            float frame)
        {
            // Normal environmental map when neither the light nor the camera is specified.
            Matrix34 finalMtx = EnvironmentTexMtx();

            GLCamera cam = v.Camera;
            Vector3  vLook, camUp, camLook;
            Matrix   camMtx    = cam._matrixInverse;
            Matrix   invCamMtx = cam._matrix;

            Matrix34 m34 = (Matrix34)camMtx;

            camLook._x = -m34[8];
            camLook._y = -m34[9];
            camLook._z = -m34[10];

            if (refLight >= 0)
            {
                bool    specEnabled;
                Vector3 lgtLook = GetLightLook(node, refLight, invCamMtx, v, frame, out specEnabled);

                // Specular light is already set as a vector taking the center position.
                if (!specEnabled)
                {
                    vLook = GetHalfAngle(camLook, lgtLook);
                }
                else
                {
                    vLook = -lgtLook;
                }

                if ((Math.Abs(vLook._x) < 0.000001f) &&
                    (Math.Abs(vLook._z) < 0.000001f))
                {
                    camUp._x = camUp._y = 0.0f;
                    if (vLook._y <= 0.0f)
                    {
                        // Look straight down
                        camUp._z = -1.0f;
                    }
                    else
                    {
                        // Look straight up
                        camUp._z = 1.0f;
                    }
                }
                else
                {
                    camUp._x = camUp._z = 0.0f;
                    camUp._y = 1.0f;
                }
            }
            else if (refCam >= 0)
            {
                SCN0CameraNode camNode = null;

                if (node != null && node.CameraGroup != null && refCam < node.CameraGroup.Children.Count)
                {
                    camNode = (SCN0CameraNode)node.CameraGroup.Children[refCam];
                }
                else
                {
                }

                Matrix cM, cMInv;
                camNode.GetModelViewMatrix(frame, out cM, out cMInv);

                // Map from the midpoint of the view camera and the specified camera.
                Matrix34 lgtCam = (Matrix34)cM;
                camUp._x = lgtCam[4];
                camUp._y = lgtCam[5];
                camUp._z = lgtCam[6];
                Vector3 lgtLook = new Vector3(-lgtCam[8], -lgtCam[9], -lgtCam[10]);

                vLook = GetHalfAngle(camLook, lgtLook);
            }
            else
            {
                return((Matrix)finalMtx);
            }

            vLook.Normalize();
            Vector3 vRight, vUp;

            vUp = (vRight = vLook.Cross(camUp).Normalize()).Cross(vLook);
            m34 = new Matrix34(
                vRight._x, vRight._y, vRight._z, 0.0f,
                vUp._x, vUp._y, vUp._z, 0.0f,
                vLook._x, vLook._y, vLook._z, 0.0f);

            m34     = (Matrix34)(((Matrix)m34) * invCamMtx);
            m34[3]  = 0.0f;
            m34[7]  = 0.0f;
            m34[11] = 0.0f;

            return((Matrix)(finalMtx * m34));
        }