private void TestToStringWithCulture(CultureInfo culture)
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = culture;
            try
            {
                string listSeparator    = culture.TextInfo.ListSeparator;
                string decimalSeparator = culture.NumberFormat.NumberDecimalSeparator;
                var    o = new AngleAxisF(1.1f, new Vec3F(2.2f, 3.3f, 4.4f));

                string s = o.ToString(null, null);
                TestToStringResults(o, s, listSeparator, decimalSeparator);

                string s2 = o.ToString();
                Assert.AreEqual(s, s2);

                s = o.ToString("G", culture);
                TestToStringResults(o, s, listSeparator, decimalSeparator);

                s = o.ToString("R", culture);
                TestToStringResults(o, s, listSeparator, decimalSeparator);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
Esempio n. 2
0
        private void TestToStringWithCulture(CultureInfo culture)
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = culture;
            try
            {
                string listSeparator = culture.TextInfo.ListSeparator;
                string decimalSeparator = culture.NumberFormat.NumberDecimalSeparator;
                var o = new AngleAxisF(1.1f, new Vec3F(2.2f, 3.3f, 4.4f));

                string s = o.ToString(null, null);
                TestToStringResults(o, s, listSeparator, decimalSeparator);

                string s2 = o.ToString();
                Assert.AreEqual(s, s2);

                s = o.ToString("G", culture);
                TestToStringResults(o, s, listSeparator, decimalSeparator);

                s = o.ToString("R", culture);
                TestToStringResults(o, s, listSeparator, decimalSeparator);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
Esempio n. 3
0
 private void TestToStringResults(AngleAxisF o, string s, string listSeparator, string decimalSeparator)
 {
     string[] results = s.Split(new[] { listSeparator }, StringSplitOptions.RemoveEmptyEntries);
     Assert.AreEqual(results.Length, 4);
     foreach (string oneFloatString in results)
         Assert.True(oneFloatString.Contains(decimalSeparator));
     Assert.AreEqual(float.Parse(results[0]), o.Angle);
     Assert.AreEqual(float.Parse(results[1]), o.Axis.X, 0.00001f); //the axis is normalized, and so only "R"
     Assert.AreEqual(float.Parse(results[2]), o.Axis.Y, 0.00001f); //  can work perfectly.
     Assert.AreEqual(float.Parse(results[3]), o.Axis.Z, 0.00001f);
 }
 private void TestToStringResults(AngleAxisF o, string s, string listSeparator, string decimalSeparator)
 {
     string[] results = s.Split(new[] { listSeparator }, StringSplitOptions.RemoveEmptyEntries);
     Assert.AreEqual(results.Length, 4);
     foreach (string oneFloatString in results)
     {
         Assert.True(oneFloatString.Contains(decimalSeparator));
     }
     Assert.AreEqual(float.Parse(results[0]), o.Angle);
     Assert.AreEqual(float.Parse(results[1]), o.Axis.X, 0.00001f); //the axis is normalized, and so only "R"
     Assert.AreEqual(float.Parse(results[2]), o.Axis.Y, 0.00001f); //  can work perfectly.
     Assert.AreEqual(float.Parse(results[3]), o.Axis.Z, 0.00001f);
 }
Esempio n. 5
0
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None || m_activeOp == null || m_activeOp.NodeList.Count == 0)
                return;
            Camera cam = vc.Camera;

            Matrix4F view = cam.ViewMatrix;
            Matrix4F proj = cam.ProjectionMatrix;

            Matrix4F axisMtrx = HitMatrix * view;
            Ray3F hitRay = HitRayV;
            Ray3F dragRay = vc.GetRay(scrPt, proj);
            
            Vec3F xAxis = axisMtrx.XAxis;
            Vec3F yAxis = axisMtrx.YAxis;
            Vec3F zAxis = axisMtrx.ZAxis;
            Vec3F origin = axisMtrx.Translation;
            
            Vec3F rotAxis = new Vec3F();            
            float theta = 0;

            float snapAngle = ((ISnapSettings)DesignView).SnapAngle;
            switch (m_hitRegion)
            {                
                case HitRegion.XAxis:
                    {
                        Plane3F xplane = new Plane3F(xAxis, origin);
                        theta = CalcAngle(origin, xplane, hitRay, dragRay, snapAngle);
                        rotAxis = HitMatrix.XAxis;                        
                    }
                    break;
                case HitRegion.YAxis:
                    {
                        Plane3F yplane = new Plane3F(yAxis, origin);
                        theta = CalcAngle(origin, yplane, hitRay, dragRay, snapAngle);
                        rotAxis = HitMatrix.YAxis;                        
                    }
                    break;
                case HitRegion.ZAxis:
                    {
                        Plane3F zplane = new Plane3F(zAxis, origin);
                        theta = CalcAngle(origin, zplane, hitRay, dragRay, snapAngle);
                        rotAxis = HitMatrix.ZAxis;
                    }
                    break;
                case HitRegion.LookAxis:
                    {                        
                        // for billboard objects the look vector is object's negative position in viewspace.
                        Vec3F lookAxis = Vec3F.Normalize(-origin);
                        Plane3F plane = new Plane3F(lookAxis, origin);
                        theta = CalcAngle(origin, plane, hitRay, dragRay, snapAngle);                        
                        rotAxis = m_lookAxisHitMtrx.ZAxis;
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            AngleAxisF axf = new AngleAxisF(-theta, rotAxis);
            Matrix4F deltaMtrx = new Matrix4F(axf);                                   
            Matrix4F rotMtrx = new Matrix4F();

            for (int i = 0; i < m_activeOp.NodeList.Count; i++)
            {
                ITransformable node = m_activeOp.NodeList[i];                              
                rotMtrx.Mul(m_rotations[i], deltaMtrx);                
                float ax, ay, az;
                rotMtrx.GetEulerAngles(out ax, out ay, out az);                                
                node.Rotation = new Vec3F(ax, ay, az);      
            }
        }
Esempio n. 6
0
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None || NodeList.Count == 0)
                return;
            Camera cam = vc.Camera;

            Matrix4F view = cam.ViewMatrix;
            Matrix4F mtrx = cam.ProjectionMatrix;

            Matrix4F axisMtrx = HitMatrix * view;
            Ray3F hitRay = HitRayV;
            Ray3F dragRay = vc.GetRay(scrPt, mtrx);
            
            Vec3F xAxis = axisMtrx.XAxis;
            Vec3F yAxis = axisMtrx.YAxis;
            Vec3F zAxis = axisMtrx.ZAxis;
            Vec3F origin = axisMtrx.Translation;
            
            Vec3F rotAxis = new Vec3F();
            float theta = 0;
            
            switch (m_hitRegion)
            {                
                case HitRegion.XAxis:
                    {
                        Plane3F xplane = new Plane3F(xAxis, origin);
                        theta = CalcAngle(origin, xplane, hitRay, dragRay);
                        rotAxis = HitMatrix.XAxis;                     
                    }
                    break;
                case HitRegion.YAxis:
                    {
                        Plane3F yplane = new Plane3F(yAxis, origin);
                        theta = CalcAngle(origin, yplane, hitRay, dragRay);
                        rotAxis = HitMatrix.YAxis;

                    }
                    break;
                case HitRegion.ZAxis:
                    {
                        Plane3F zplane = new Plane3F(zAxis, origin);
                        theta = CalcAngle(origin, zplane, hitRay, dragRay);
                        rotAxis = HitMatrix.ZAxis;
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            AngleAxisF axf = new AngleAxisF(-theta, rotAxis);
            Matrix4F deltaMtrx = new Matrix4F(axf);                                   
            Matrix4F rotMtrx = new Matrix4F();            
            for (int i = 0; i < NodeList.Count; i++)
            {                                
                ITransformable node = NodeList[i];                
                rotMtrx.Set(m_rotations[i]);
                rotMtrx.Mul(rotMtrx, deltaMtrx);                
                float ax, ay, az;
                rotMtrx.GetEulerAngles(out ax, out ay, out az);                
                node.Rotation = new Vec3F(ax,ay,az);
            }

        }
Esempio n. 7
0
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None || NodeList.Count == 0)
            {
                return;
            }
            Camera cam = vc.Camera;

            Matrix4F view = cam.ViewMatrix;
            Matrix4F mtrx = cam.ProjectionMatrix;

            Matrix4F axisMtrx = HitMatrix * view;
            Ray3F    hitRay   = HitRayV;
            Ray3F    dragRay  = vc.GetRay(scrPt, mtrx);

            Vec3F xAxis  = axisMtrx.XAxis;
            Vec3F yAxis  = axisMtrx.YAxis;
            Vec3F zAxis  = axisMtrx.ZAxis;
            Vec3F origin = axisMtrx.Translation;

            Vec3F rotAxis = new Vec3F();
            float theta   = 0;

            float snapAngle = ((ISnapSettings)DesignView).SnapAngle;

            switch (m_hitRegion)
            {
            case HitRegion.XAxis:
            {
                Plane3F xplane = new Plane3F(xAxis, origin);
                theta   = CalcAngle(origin, xplane, hitRay, dragRay, snapAngle);
                rotAxis = HitMatrix.XAxis;
            }
            break;

            case HitRegion.YAxis:
            {
                Plane3F yplane = new Plane3F(yAxis, origin);
                theta   = CalcAngle(origin, yplane, hitRay, dragRay, snapAngle);
                rotAxis = HitMatrix.YAxis;
            }
            break;

            case HitRegion.ZAxis:
            {
                Plane3F zplane = new Plane3F(zAxis, origin);
                theta   = CalcAngle(origin, zplane, hitRay, dragRay, snapAngle);
                rotAxis = HitMatrix.ZAxis;
            }
            break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            AngleAxisF axf       = new AngleAxisF(-theta, rotAxis);
            Matrix4F   deltaMtrx = new Matrix4F(axf);
            Matrix4F   rotMtrx   = new Matrix4F();

            for (int i = 0; i < NodeList.Count; i++)
            {
                ITransformable node = NodeList[i];
                rotMtrx.Mul(m_rotations[i], deltaMtrx);
                float ax, ay, az;
                rotMtrx.GetEulerAngles(out ax, out ay, out az);
                node.Rotation = new Vec3F(ax, ay, az);
            }
        }