Exemple #1
0
        public Vector3 ToEulerAnglesXYZ()
        {
            Real yAngle;
            Real rAngle;
            Real pAngle;

            pAngle = Utility.ASin(m01);
            if (pAngle < Utility.PI / 2)
            {
                if (pAngle > -Utility.PI / 2)
                {
                    yAngle = Utility.ATan2(m21, m11);
                    rAngle = Utility.ATan2(m02, m00);
                }
                else
                {
                    // WARNING. Not a unique solution.
                    Real fRmY = (Real)Utility.ATan2(-m20, m22);
                    rAngle = 0.0f;                     // any angle works
                    yAngle = rAngle - fRmY;
                }
            }
            else
            {
                // WARNING. Not a unique solution.
                Real fRpY = Utility.ATan2(-m20, m22);
                rAngle = 0.0f;                 // any angle works
                yAngle = fRpY - rAngle;
            }

            return(new Vector3(yAngle, rAngle, pAngle));
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        public void Update()
        {
            if (!this.IsCreated)
            {
                return;
            }

            float radius = this.SkyX.Camera.FarClipDistance * 0.95f;
            float size   = radius * this.MoonSize;

            this.MoonBillboard.CommonDirection = (this.SkyX.AtmosphereManager.SunDirection).NormalisedCopy.Perpendicular;

            Vector3 moonRelativePos = this.SkyX.AtmosphereManager.SunDirection *
                                      Utility.Cos(Utility.ASin((size / 2.0f) / radius)) * radius;

            this.MoonSceneNode.Position = this.SkyX.Camera.DerivedPosition + moonRelativePos;

            if (moonRelativePos.y < -size / 2)
            {
                this.MoonSceneNode.SetVisible(false);
            }
            else
            {
                //this.MoonSceneNode.IsVisible = true;
                this.MoonSceneNode.SetVisible(true);

                using (MaterialPtr mat = MaterialManager.Singleton.GetByName("SkyX_Moon")) {
                    //mat.GetTechnique(0).GetPass(0).VertexProgramParameters.SetNamedConstant("uSkydomeCenter", this.SkyX.Camera.DerivedPosition);
                    mat.GetTechnique(0).GetPass(0).GetVertexProgramParameters().SetNamedConstant("uSkydomeCenter", this.SkyX.Camera.DerivedPosition);
                }
            }
        }
Exemple #3
0
        public void ToEulerAngles(out Real pitch, out Real yaw, out Real roll)
        {
            Real halfPi = Utility.PI / 2;
            Real test   = x * y + z * w;

            if (test > 0.499f)
            {
                // singularity at north pole
                yaw   = 2 * Utility.ATan2(x, w);
                roll  = halfPi;
                pitch = 0;
            }
            else if (test < -0.499f)
            {
                // singularity at south pole
                yaw   = -2 * Utility.ATan2(x, w);
                roll  = -halfPi;
                pitch = 0;
            }
            else
            {
                Real sqx = x * x;
                Real sqy = y * y;
                Real sqz = z * z;
                yaw   = Utility.ATan2(2 * y * w - 2 * x * z, 1 - 2 * sqy - 2 * sqz);
                roll  = (Real)Utility.ASin(2 * test);
                pitch = Utility.ATan2(2 * x * w - 2 * y * z, 1 - 2 * sqx - 2 * sqz);
            }

            if (pitch >= -Real.Epsilon && pitch <= Real.Epsilon)
            {
                pitch = 0f;
            }
            else if (pitch == -Utility.PI)
            {
                pitch = Utility.PI;
            }

            if (yaw >= -Real.Epsilon && yaw <= Real.Epsilon)
            {
                yaw = 0f;
            }
            else if (yaw == -Utility.PI)
            {
                yaw = Utility.PI;
            }

            if (roll >= -Real.Epsilon && roll <= Real.Epsilon)
            {
                roll = 0f;
            }
            else if (roll == -Utility.PI)
            {
                roll = Utility.PI;
            }
        }
Exemple #4
0
        public void ToEulerAngles(out Real pitch, out Real yaw, out Real roll)
        {
            var halfPi = Utility.PI / 2;
            var test   = this.x * this.y + this.z * this.w;

            if (test > 0.499f)
            {
                // singularity at north pole
                yaw   = 2 * Utility.ATan2(this.x, this.w);
                roll  = halfPi;
                pitch = 0;
            }
            else if (test < -0.499f)
            {
                // singularity at south pole
                yaw   = -2 * Utility.ATan2(this.x, this.w);
                roll  = -halfPi;
                pitch = 0;
            }
            else
            {
                var sqx = this.x * this.x;
                var sqy = this.y * this.y;
                var sqz = this.z * this.z;
                yaw   = Utility.ATan2(2 * this.y * this.w - 2 * this.x * this.z, 1 - 2 * sqy - 2 * sqz);
                roll  = (Real)Utility.ASin(2 * test);
                pitch = Utility.ATan2(2 * this.x * this.w - 2 * this.y * this.z, 1 - 2 * sqx - 2 * sqz);
            }

            if (pitch <= Real.Epsilon)
            {
                pitch = 0f;
            }
            if (yaw <= Real.Epsilon)
            {
                yaw = 0f;
            }
            if (roll <= Real.Epsilon)
            {
                roll = 0f;
            }
        }
Exemple #5
0
        public void ToEulerAngles(out float pitch, out float yaw, out float roll)
        {
            float halfPi = Utility.PI / 2;
            float test   = x * y + z * w;

            if (test > 0.499f)
            {
                // singularity at north pole
                yaw   = 2 * Utility.ATan2(x, w);
                roll  = halfPi;
                pitch = 0;
            }
            else if (test < -0.499f)
            {
                // singularity at south pole
                yaw   = -2 * Utility.ATan2(x, w);
                roll  = -halfPi;
                pitch = 0;
            }
            else
            {
                float sqx = x * x;
                float sqy = y * y;
                float sqz = z * z;
                yaw   = Utility.ATan2(2 * y * w - 2 * x * z, 1 - 2 * sqy - 2 * sqz);
                roll  = (float)Utility.ASin(2 * test);
                pitch = Utility.ATan2(2 * x * w - 2 * y * z, 1 - 2 * sqx - 2 * sqz);
            }

            if (pitch <= float.Epsilon)
            {
                pitch = 0f;
            }
            if (yaw <= float.Epsilon)
            {
                yaw = 0f;
            }
            if (roll <= float.Epsilon)
            {
                roll = 0f;
            }
        }