Пример #1
0
        public static Quaternion Parse(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("The text parameter cannot be null or zero length.");
            }

            string[] vals = text.Split(new char[] { ' ' },
                                       StringSplitOptions.RemoveEmptyEntries);

            //parse from Angles (special case).
            if (vals.Length == 3)
            {
                return(Angles.Parse(text).ToQuaternion());
            }

            if (vals.Length != 4)
            {
                throw new FormatException(string.Format("Cannot parse the text '{0}' because it does not have 4 parts separated by spaces in the form (x y z w).", text));
            }

            try
            {
                return(new Quaternion(
                           double.Parse(vals[0]),
                           double.Parse(vals[1]),
                           double.Parse(vals[2]),
                           double.Parse(vals[3])));
            }
            catch (Exception)
            {
                throw new FormatException("The parts of the vectors must be decimal numbers.");
            }
        }
Пример #2
0
        public void ToAngles(out Angles result)
        {
            Matrix3 mat;

            ToMatrix3(out mat);
            mat.ToAngles(out result);
        }
Пример #3
0
        //public static Angles operator *( double a, Angles b )
        //{
        //	double inva = 1.0 / a;
        //	return new Angles( b.Roll * inva, b.Pitch * inva, b.Yaw * inva );
        //}

        /// <summary>
        /// Restricts the current instance of <see cref="Angles"/> to be within a specified range.
        /// </summary>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        public void Clamp(Angles min, Angles max)
        {
            if (Roll < min.Roll)
            {
                Roll = min.Roll;
            }
            else if (Roll > max.Roll)
            {
                Roll = max.Roll;
            }
            if (Pitch < min.Pitch)
            {
                Pitch = min.Pitch;
            }
            else if (Pitch > max.Pitch)
            {
                Pitch = max.Pitch;
            }
            if (Yaw < min.Yaw)
            {
                Yaw = min.Yaw;
            }
            else if (Yaw > max.Yaw)
            {
                Yaw = max.Yaw;
            }
        }
Пример #4
0
 public static Angles Generate(Angles minValue, Angles maxValue)
 {
     lock (_static)
         return(new Angles(
                    _static.Next(minValue.Roll, maxValue.Roll),
                    _static.Next(minValue.Pitch, maxValue.Pitch),
                    _static.Next(minValue.Yaw, maxValue.Yaw)));
 }
Пример #5
0
 /// <summary>
 /// Determines whether the specified Euler angles are equal to the current instance of <see cref="Angles"/>
 /// with a given precision.
 /// </summary>
 /// <param name="a">The Euler angles to compare.</param>
 /// <param name="epsilon">The precision value.</param>
 /// <returns>True if the specified Euler angles are equal to the current instance of <see cref="Angles"/>; False otherwise.</returns>
 public bool Equals(Angles a, double epsilon)
 {
     if (Math.Abs(Roll - a.Roll) > epsilon)
     {
         return(false);
     }
     if (Math.Abs(Pitch - a.Pitch) > epsilon)
     {
         return(false);
     }
     if (Math.Abs(Yaw - a.Yaw) > epsilon)
     {
         return(false);
     }
     return(true);
 }
        public override void Render(ViewportRenderingContext context, out int verticesRendered)
        {
            verticesRendered = 0;

            var context2 = context.objectInSpaceRenderingContext;

            //var scene = ParentScene;
            //bool show = ( scene.GetDisplayDevelopmentDataInThisApplication() && scene.DisplayPhysicalObjects ) ||
            //	context2.selectedObjects.Contains( this ) || context2.canSelectObjects.Contains( this ) || context2.dragDropCreateObject == this;
            if (/*show && */ rigidBody != null && context.Owner.Simple3DRenderer != null)
            {
                var viewport = context.Owner;
                var renderer = viewport.Simple3DRenderer;

                //if( context2.displayPhysicalObjectsCounter < context2.displayPhysicalObjectsMax )
                //{
                //	context2.displayPhysicalObjectsCounter++;

                //draw body
                {
                    ColorValue color;
                    if (MotionType.Value == MotionTypeEnum.Static)
                    {
                        color = ProjectSettings.Get.SceneShowPhysicsStaticColor;
                    }
                    else if (rigidBody.Awake)
                    {
                        color = ProjectSettings.Get.SceneShowPhysicsDynamicActiveColor;
                    }
                    else
                    {
                        color = ProjectSettings.Get.SceneShowPhysicsDynamicInactiveColor;
                    }
                    viewport.Simple3DRenderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);

                    Transform tr;
                    {
                        tr = Transform.Value;
                        var newRotation = new Angles(0, 0, tr.Rotation.ToAngles().Yaw).ToQuaternion();
                        tr = tr.UpdateRotation(newRotation);
                    }

                    foreach (var shape in GetComponents <Component_CollisionShape2D>(false, true, true))
                    {
                        shape.Render(viewport, tr, false, ref verticesRendered);
                    }

                    ////center of mass
                    //if( MotionType.Value == MotionTypeEnum.Dynamic )
                    //{
                    //	var center = rigidBody.LocalCenter;//CenterOfMassPosition;
                    //	double radius = SpaceBounds.CalculatedBoundingSphere.Radius / 16;

                    //	var item = GetCenterOfMassGeometry( (float)radius );
                    //	var transform = Matrix4.FromTranslate( Physics2DUtility.Convert( center ) );
                    //	context.Owner.Simple3DRenderer.AddTriangles( item.positions, item.indices, ref transform, false, true );
                    //	//context.viewport.Simple3DRenderer.AddSphere( BulletPhysicsUtility.Convert( center ), radius, 16, true );

                    //	//Vector3 center = Vector3.Zero;
                    //	//double radius = 1.0;
                    //	//rigidBody.CollisionShape.GetBoundingSphere( out center, out radius );
                    //	//center = rigidBody.CenterOfMassPosition;
                    //	//radius /= 16.0;
                    //	//context.viewport.DebugGeometry.AddSphere( BulletUtils.Convert( center ), radius );

                    //	verticesRendered += item.positions.Length;
                    //}
                }

                //draw selection
                if (context2.selectedObjects.Contains(this) || context2.canSelectObjects.Contains(this))
                {
                    ColorValue color;
                    if (context2.selectedObjects.Contains(this))
                    {
                        color = ProjectSettings.Get.SelectedColor;
                    }
                    else if (context2.canSelectObjects.Contains(this))
                    {
                        color = ProjectSettings.Get.CanSelectColor;
                    }
                    else
                    {
                        color = ProjectSettings.Get.SceneShowPhysicsDynamicActiveColor;
                    }

                    color.Alpha *= .5f;
                    viewport.Simple3DRenderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);

                    foreach (var shape in GetComponents <Component_CollisionShape2D>(false, true, true))
                    {
                        shape.Render(viewport, Transform, true, ref verticesRendered);
                    }

                    //context.viewport.DebugGeometry.AddBounds( SpaceBounds.CalculatedBoundingBox );
                }

                //display collision contacts
                if (ContactsDisplay && rigidBody.ContactList != null)
                {
                    var size3 = SpaceBounds.CalculatedBoundingBox.GetSize();
                    var scale = (float)Math.Min(size3.X, size3.Y) / 30;
                    //var scale = (float)Math.Max( size3.X, Math.Max( size3.Y, size3.Z ) ) / 40;

                    var edge = rigidBody.ContactList;
                    while (edge != null)
                    {
                        var contact = edge.Contact;

                        int pointCount = contact.Manifold.PointCount;
                        if (pointCount > 0)
                        {
                            if (pointCount > 2)
                            {
                                pointCount = 2;
                            }

                            renderer.SetColor(new ColorValue(1, 0, 0));

                            contact.GetWorldManifold(out _, out var points);

                            for (int n = 0; n < pointCount; n++)
                            {
                                var point = Physics2DUtility.Convert(points[n]);

                                var pos    = new Vector3(point, TransformV.Position.Z);
                                var bounds = new Bounds(
                                    pos - new Vector3(scale, scale, scale),
                                    pos + new Vector3(scale, scale, scale));

                                renderer.AddBounds(bounds, true);
                            }
                        }

                        edge = edge.Next;
                    }
                }

                //}
            }
        }
Пример #7
0
        //

        static SimpleTypes()
        {
            //string
            RegisterType(typeof(string), delegate(string value)
            {
                if (value == null)
                {
                    return("");
                    //throw new Exception( "GetSimpleTypeValue: string type, value = null" );
                }
                return(value);
            }, "");

            //bool
            RegisterType(typeof(bool), delegate(string value)
            {
                string lower = value.ToLower();
                if (value == "1" || lower == "yes" || lower == "true")
                {
                    return(true);
                }
                else if (value == "0" || lower == "no" || lower == "false")
                {
                    return(false);
                }
                else
                {
                    return(bool.Parse(value));
                }
            }, false);

            //sbyte
            RegisterType(typeof(sbyte), delegate(string value) { return(sbyte.Parse(value)); }, 0);

            //byte
            RegisterType(typeof(byte), delegate(string value) { return(byte.Parse(value)); }, 0);

            //char
            RegisterType(typeof(char), delegate(string value) { return(char.Parse(value)); }, 0);

            //short
            RegisterType(typeof(short), delegate(string value) { return(short.Parse(value)); }, 0);

            //ushort
            RegisterType(typeof(ushort), delegate(string value) { return(ushort.Parse(value)); }, 0);

            //int
            RegisterType(typeof(int), delegate(string value) { return(int.Parse(value)); }, 0);

            //uint
            RegisterType(typeof(uint), delegate(string value) { return(uint.Parse(value)); }, (uint)0);

            //long
            RegisterType(typeof(long), delegate(string value) { return(long.Parse(value)); }, (long)0);

            //ulong
            RegisterType(typeof(ulong), delegate(string value) { return(ulong.Parse(value)); }, (ulong)0);

            //float
            RegisterType(typeof(float), delegate(string value) { return(float.Parse(value)); }, 0.0f);

            //double
            RegisterType(typeof(double), delegate(string value) { return(double.Parse(value)); }, 0.0);

            //decimal
            RegisterType(typeof(decimal), delegate(string value) { return(decimal.Parse(value)); }, (decimal)0.0);

            //Vec2
            RegisterType(typeof(Vector2F), delegate(string value) { return(Vector2F.Parse(value)); }, Vector2F.Zero);

            //Range
            RegisterType(typeof(RangeF), delegate(string value) { return(RangeF.Parse(value)); }, RangeF.Zero);

            //Vec3
            RegisterType(typeof(Vector3F), delegate(string value) { return(Vector3F.Parse(value)); }, Vector3F.Zero);

            //Vec4
            RegisterType(typeof(Vector4F), delegate(string value) { return(Vector4F.Parse(value)); }, Vector4F.Zero);

            //Bounds
            RegisterType(typeof(BoundsF), delegate(string value) { return(BoundsF.Parse(value)); }, BoundsF.Zero);

            //Quat
            RegisterType(typeof(QuaternionF), delegate(string value) { return(QuaternionF.Parse(value)); }, QuaternionF.Identity);

            //ColorValue
            RegisterType(typeof(ColorValue), delegate(string value) { return(ColorValue.Parse(value)); }, ColorValue.Zero);

            //ColorValuePowered
            RegisterType(typeof(ColorValuePowered), delegate(string value) { return(ColorValuePowered.Parse(value)); }, ColorValuePowered.Zero);

            //ColorPacked
            RegisterType(typeof(ColorByte), delegate(string value) { return(ColorByte.Parse(value)); }, ColorByte.Zero);

            //SphereDir
            RegisterType(typeof(SphericalDirectionF), delegate(string value) { return(SphericalDirectionF.Parse(value)); }, SphericalDirectionF.Zero);

            //Vec2I
            RegisterType(typeof(Vector2I), delegate(string value) { return(Vector2I.Parse(value)); }, Vector2I.Zero);

            //Vec3I
            RegisterType(typeof(Vector3I), delegate(string value) { return(Vector3I.Parse(value)); }, Vector3I.Zero);

            //Vec4I
            RegisterType(typeof(Vector4I), delegate(string value) { return(Vector4I.Parse(value)); }, Vector4I.Zero);

            //Rect
            RegisterType(typeof(RectangleF), delegate(string value) { return(RectangleF.Parse(value)); }, RectangleF.Zero);

            //RectI
            RegisterType(typeof(RectangleI), delegate(string value) { return(RectangleI.Parse(value)); }, RectangleI.Zero);

            //Degree
            RegisterType(typeof(DegreeF), delegate(string value) { return(DegreeF.Parse(value)); }, DegreeF.Zero);

            //Radian
            RegisterType(typeof(RadianF), delegate(string value) { return(RadianF.Parse(value)); }, RadianF.Zero);

            //Vec2D
            RegisterType(typeof(Vector2), delegate(string value) { return(Vector2.Parse(value)); }, Vector2.Zero);

            //RangeD
            RegisterType(typeof(Range), delegate(string value) { return(Range.Parse(value)); }, Range.Zero);

            //RangeI
            RegisterType(typeof(RangeI), delegate(string value) { return(RangeI.Parse(value)); }, RangeI.Zero);

            //Vec3D
            RegisterType(typeof(Vector3), delegate(string value) { return(Vector3.Parse(value)); }, Vector3.Zero);

            //Vec4D
            RegisterType(typeof(Vector4), delegate(string value) { return(Vector4.Parse(value)); }, Vector4.Zero);

            //BoundsD
            RegisterType(typeof(Bounds), delegate(string value) { return(Bounds.Parse(value)); }, Bounds.Zero);

            //QuatD
            RegisterType(typeof(Quaternion), delegate(string value) { return(Quaternion.Parse(value)); }, Quaternion.Identity);

            //SphereDirD
            RegisterType(typeof(SphericalDirection), delegate(string value) { return(SphericalDirection.Parse(value)); }, SphericalDirection.Zero);

            //RectD
            RegisterType(typeof(Rectangle), delegate(string value) { return(Rectangle.Parse(value)); }, Rectangle.Zero);

            //DegreeD
            RegisterType(typeof(Degree), delegate(string value) { return(Degree.Parse(value)); }, Degree.Zero);

            //RadianD
            RegisterType(typeof(Radian), delegate(string value) { return(Radian.Parse(value)); }, Radian.Zero);

            //Angles
            RegisterType(typeof(AnglesF), delegate(string value) { return(AnglesF.Parse(value)); }, AnglesF.Zero);

            //AnglesD
            RegisterType(typeof(Angles), delegate(string value) { return(Angles.Parse(value)); }, Angles.Zero);

            //Mat2F
            RegisterType(typeof(Matrix2F), delegate(string value) { return(Matrix2F.Parse(value)); }, Matrix2F.Zero);

            //Mat2D
            RegisterType(typeof(Matrix2), delegate(string value) { return(Matrix2.Parse(value)); }, Matrix2.Zero);

            //Mat3F
            RegisterType(typeof(Matrix3F), delegate(string value) { return(Matrix3F.Parse(value)); }, Matrix3F.Zero);

            //Mat3D
            RegisterType(typeof(Matrix3), delegate(string value) { return(Matrix3.Parse(value)); }, Matrix3.Zero);

            //Mat4F
            RegisterType(typeof(Matrix4F), delegate(string value) { return(Matrix4F.Parse(value)); }, Matrix4F.Zero);

            //Mat4D
            RegisterType(typeof(Matrix4), delegate(string value) { return(Matrix4.Parse(value)); }, Matrix4.Zero);

            //PlaneF
            RegisterType(typeof(PlaneF), delegate(string value) { return(PlaneF.Parse(value)); }, PlaneF.Zero);

            //PlaneD
            RegisterType(typeof(Plane), delegate(string value) { return(Plane.Parse(value)); }, Plane.Zero);

            //Transform
            RegisterType(typeof(Transform), delegate(string value) { return(Transform.Parse(value)); }, Transform.Identity);

            //UIMeasureValueDouble
            RegisterType(typeof(UIMeasureValueDouble), delegate(string value) { return(UIMeasureValueDouble.Parse(value)); }, new UIMeasureValueDouble());

            //UIMeasureValueVec2
            RegisterType(typeof(UIMeasureValueVector2), delegate(string value) { return(UIMeasureValueVector2.Parse(value)); }, new UIMeasureValueVector2());

            //UIMeasureValueRect
            RegisterType(typeof(UIMeasureValueRectangle), delegate(string value) { return(UIMeasureValueRectangle.Parse(value)); }, new UIMeasureValueRectangle());

            RegisterType(typeof(RangeVector3F), delegate(string value) { return(RangeVector3F.Parse(value)); }, RangeVector3F.Zero);
            RegisterType(typeof(RangeColorValue), delegate(string value) { return(RangeColorValue.Parse(value)); }, RangeColorValue.Zero);

            //no Parse methods. This is complex structures. This is not simple types? or just can't parse?
            //Box
            //Capsule
            //Cone
            //Line3
            //Line2
            //Ray
            //Frustum?

            RegisterConvertDoubleToFloatTypes();
        }
Пример #8
0
 public Transform(Vector3 position, Angles rotation)
 {
     this.position = position;
     this.rotation = rotation.ToQuaternion();
     this.scale    = Vector3.One;
 }
Пример #9
0
 /// <summary>
 /// Constructs Euler angles with another specified <see cref="Angles"/> object.
 /// </summary>
 /// <param name="source">Euler angles of <see cref="Angles"/> format.</param>
 public Angles(Angles source)
 {
     this.Roll  = source.Roll;
     this.Pitch = source.Pitch;
     this.Yaw   = source.Yaw;
 }