Exemplo n.º 1
0
        void SetupFrustrum()
        {
            //Console.WriteLine("setup frustrum");

            camerapos = Camera.GetInstance().RoamingCameraPos;
            camerarot = Camera.GetInstance().RoamingCameraRot;
            Rot inversecamerarot = camerarot.Inverse();

            viewray = -mvMath.YAxis * inversecamerarot;
            viewray.Normalize();
            right = mvMath.XAxis * inversecamerarot;
            up    = mvMath.ZAxis * inversecamerarot;
            right.Normalize();
            up.Normalize();

            double nearclip = RendererFactory.GetInstance().NearClip;
            double farclip  = RendererFactory.GetInstance().FarClip;

            VNear = 2 * Math.Tan(RendererFactory.GetInstance().FieldOfView / 2 * Math.PI / 180) * nearclip;
            VFar  = VNear * farclip / nearclip;
            HNear = VNear * (double)RendererFactory.GetInstance().WindowWidth / RendererFactory.GetInstance().WindowHeight;
            HFar  = HNear * farclip / nearclip;

            fc  = camerapos + viewray * farclip;
            ftl = fc + (up * VFar / 2) - (right * HFar / 2);
            ftr = fc + (up * VFar / 2) + (right * HFar / 2);
            fbl = fc - (up * VFar / 2) - (right * HFar / 2);
            fbr = fc - (up * VFar / 2) + (right * HFar / 2);

            nc = camerapos + viewray * nearclip;

            ntl = nc + (up * VNear / 2) - (right * HNear / 2);
            ntr = nc + (up * VNear / 2) + (right * HNear / 2);
            nbl = nc - (up * VNear / 2) - (right * HNear / 2);
            nbr = nc - (up * VNear / 2) + (right * HNear / 2);

            // note: all normals point outwards
            planes[0] = new Plane(-viewray, nc);
            planes[1] = new Plane(viewray, fc);

            Vector3 vectoralongplane;
            Vector3 normal;

            vectoralongplane = (ntr - camerapos).Normalize();
            normal           = (up * vectoralongplane).Normalize();
            planes[2]        = new Plane(normal, camerapos);

            vectoralongplane = (nbr - camerapos).Normalize();
            normal           = (right * vectoralongplane).Normalize();
            planes[3]        = new Plane(normal, camerapos);

            vectoralongplane = (nbl - camerapos).Normalize();
            normal           = -(up * vectoralongplane).Normalize();
            planes[4]        = new Plane(normal, camerapos);

            vectoralongplane = (ntl - camerapos).Normalize();
            normal           = -(right * vectoralongplane).Normalize();
            planes[5]        = new Plane(normal, camerapos);
        }
Exemplo n.º 2
0
        public void ApplyCamera()
        {
            //PlayerMovement playermovement = PlayerMovement.GetInstance();

            GLMatrix4d cameramatrix = GLMatrix4d.identity();

            // rotate and reflect so x points right, y points backwards, z points up
            cameramatrix.applyRotate(-90, 1.0, 0.0, 0.0);
            cameramatrix.applyScale(1, -1, 1);

            // rotate so x points right, y points forward, z points up
            //cameramatrix.applyRotate(-90, 1.0, 0.0, 0.0);

            // rotate so z axis is up, and x axis is forward, y axis is left
            //cameramatrix.applyRotate(90, 0.0, 0.0, 1.0);
            //cameramatrix.applyRotate( 90, 0.0, 1.0, 0.0 );

            if (bRoamingCameraEnabled)
            {
                Rot inversecamerarot = RoamingCameraRot.Inverse();
                mvMath.ApplyRotToGLMatrix4d(ref cameramatrix, inversecamerarot);
                cameramatrix.applyTranslate(-RoamingCameraPos.x, -RoamingCameraPos.y, -RoamingCameraPos.z);
            }
            else if (viewpoint == Viewpoint.MouseLook)
            {
                //cameramatrix.applyRotate( - playermovement.avataryrot, 0f, 1f, 0f );
                //cameramatrix.applyRotate( - playermovement.avatarzrot, 0f, 0f, 1f );
                //cameramatrix.applyTranslate( - playermovement.avatarpos.x, - playermovement.avatarpos.y, - playermovement.avatarpos.z );
            }
            else if (viewpoint == Viewpoint.BehindPlayer)
            {
                /*
                 * cameramatrix.applyRotate( -18f, 0f, 1f, 0f );
                 *
                 * // Vector3 V = new Vector3( 0, playermovement.avataryrot * mvMath.PiOver180, playermovement.avatarzrot * mvMath.PiOver180 );
                 *
                 * cameramatrix.applyTranslate( 3.0f, 0.0f, -1.0f );
                 *
                 * cameramatrix.applyRotate( - (float)playermovement.avataryrot, 0f, 1f, 0f );
                 * cameramatrix.applyRotate( - (float)playermovement.avatarzrot, 0f, 0f, 1f );
                 *
                 * cameramatrix.applyTranslate( -playermovement.avatarpos.x, -playermovement.avatarpos.y, -playermovement.avatarpos.z );
                 */
            }
            else if (viewpoint == Viewpoint.ThirdParty)
            {
                /*
                 * cameramatrix.applyRotate( -18f, 0f, 1f, 0f );
                 * cameramatrix.applyRotate( -90f, 0f, 0f, 1f );
                 *
                 * cameramatrix.applyTranslate( 0.0, - fThirdPartyViewZoom, fThirdPartyViewZoom / 3.0 );
                 * cameramatrix.applyRotate( - fThirdPartyViewRotate, 0f, 0f, 1f );
                 * cameramatrix.applyTranslate( - playermovement.avatarpos.x, - playermovement.avatarpos.y, - playermovement.avatarpos.z );
                 */
            }

            GraphicsHelperFactory.GetInstance().LoadMatrix(cameramatrix.ToArray());
        }
        void SetupFrustrum()
        {
            //Console.WriteLine("setup frustrum");

            camerapos = Camera.GetInstance().RoamingCameraPos;
            camerarot = Camera.GetInstance().RoamingCameraRot;
            Rot inversecamerarot = camerarot.Inverse();
            viewray = -mvMath.YAxis * inversecamerarot;
            viewray.Normalize();
            right = mvMath.XAxis * inversecamerarot;
            up = mvMath.ZAxis * inversecamerarot;
            right.Normalize();
            up.Normalize();

            double nearclip = RendererFactory.GetInstance().NearClip;
            double farclip = RendererFactory.GetInstance().FarClip;
            VNear = 2 * Math.Tan(RendererFactory.GetInstance().FieldOfView / 2 * Math.PI / 180) * nearclip;
            VFar = VNear * farclip / nearclip;
            HNear = VNear * (double)RendererFactory.GetInstance().WindowWidth / RendererFactory.GetInstance().WindowHeight;
            HFar = HNear * farclip / nearclip;

            fc = camerapos + viewray * farclip;
            ftl = fc + (up * VFar / 2) - (right * HFar / 2);
            ftr = fc + (up * VFar / 2) + (right * HFar / 2);
            fbl = fc - (up * VFar / 2) - (right * HFar / 2);
            fbr = fc - (up * VFar / 2) + (right * HFar / 2);

            nc = camerapos + viewray * nearclip;

            ntl = nc + (up * VNear / 2) - (right * HNear / 2);
            ntr = nc + (up * VNear / 2) + (right * HNear / 2);
            nbl = nc - (up * VNear / 2) - (right * HNear / 2);
            nbr = nc - (up * VNear / 2) + (right * HNear / 2);

            // note: all normals point outwards
            planes[0] = new Plane(-viewray, nc);
            planes[1] = new Plane(viewray, fc);

            Vector3 vectoralongplane;
            Vector3 normal;

            vectoralongplane = (ntr - camerapos).Normalize();
            normal = (up * vectoralongplane).Normalize();
            planes[2] = new Plane(normal, camerapos);

            vectoralongplane = (nbr - camerapos).Normalize();
            normal = (right * vectoralongplane).Normalize();
            planes[3] = new Plane(normal, camerapos);

            vectoralongplane = (nbl - camerapos).Normalize();
            normal = -(up * vectoralongplane).Normalize();
            planes[4] = new Plane(normal, camerapos);

            vectoralongplane = (ntl - camerapos).Normalize();
            normal = -(right * vectoralongplane).Normalize();
            planes[5] = new Plane(normal, camerapos);
        }
Exemplo n.º 4
0
        //! Feedback line buffer for OpenGL feedback, used by mvgraphics.cpp

        /*
         * class FeedbackLineBufferItem
         * {
         *  public double type;
         *  public Vector2[] vertices = new Vector2[2];
         * }
         */

        public Vector3 GetMouseVector(Vector3 OurPos, Rot OurRot, int mousex, int mousey)
        {
            IRenderer renderer = RendererFactory.GetInstance();

            Vector3 MouseVectorObserverAxes = new Vector3(-renderer.WindowWidth / 2 + mousex, -renderer.ScreenDistanceScreenCoords, renderer.WindowHeight / 2 - mousey);

            //Console.WriteLine("MouseVectorObserverAxes: " + MouseVectorObserverAxes);
            MouseVectorObserverAxes.Normalize();
            //Console.WriteLine("MouseVectorObserverAxes (normalized): " + MouseVectorObserverAxes);
            Vector3 MouseVectorWorldAxes = MouseVectorObserverAxes * OurRot.Inverse();

            //Console.WriteLine("MouseVectorWorldAxes: " + MouseVectorWorldAxes.ToString());
            MouseVectorWorldAxes.Normalize();
            return(MouseVectorWorldAxes);
        }
        //! Feedback line buffer for OpenGL feedback, used by mvgraphics.cpp
        /*
        class FeedbackLineBufferItem
        {
            public double type;
            public Vector2[] vertices = new Vector2[2];
        }
        */

        public Vector3 GetMouseVector(Vector3 OurPos, Rot OurRot, int mousex, int mousey)
        {
            IRenderer renderer = RendererFactory.GetInstance();

            Vector3 MouseVectorObserverAxes = new Vector3( - renderer.WindowWidth / 2 + mousex, - renderer.ScreenDistanceScreenCoords, renderer.WindowHeight / 2 - mousey);
            //Console.WriteLine("MouseVectorObserverAxes: " + MouseVectorObserverAxes);
            MouseVectorObserverAxes.Normalize();
            //Console.WriteLine("MouseVectorObserverAxes (normalized): " + MouseVectorObserverAxes);
            Vector3 MouseVectorWorldAxes = MouseVectorObserverAxes * OurRot.Inverse();
            //Console.WriteLine("MouseVectorWorldAxes: " + MouseVectorWorldAxes.ToString());
            MouseVectorWorldAxes.Normalize();
            return MouseVectorWorldAxes;
        }