Ejemplo n.º 1
0
 protected void InitializeMatrices()
 {
     scaleMatrix    = Matrix.Scaling(new Vector3(scale, 0f));
     positionMatrix = Matrix.Translation(new Vector3(position, 0));
     originMatrix   = Matrix.Translation(new Vector3(-origin, 0));
     rotationMatrix = Matrix.RotationZ(MathUtil.DegreesToRadians(degrees));
 }
Ejemplo n.º 2
0
        internal override List <PolygonPoint> GetPoints(float thickness = 0)
        {
            List <PolygonPoint> points = new List <PolygonPoint>();

            int   arcSides      = (int)Math.Round((arcDegrees / 360f) * sides, MidpointRounding.AwayFromZero);
            int   halfArcSides  = arcSides / 2;
            float offsetDegrees = MathUtil.RadiansToDegrees((float)Math.Tan(thickness / radius));
            float degreeStep    = (arcDegrees - offsetDegrees) / arcSides;
            float r             = radius - thickness * 0.5f;
            float t             = thickness - (thickness * (arcDegrees / 180)) / 2;

            points.Add(GetPoint(0, t));

            for (int i = -halfArcSides; i <= halfArcSides; i++)
            {
                points.Add(GetPoint(degreeStep * i, r));
            }

            if (!Filled)
            {
                points.Add(points[0]);
            }

            return(points);
        }
Ejemplo n.º 3
0
        private PolygonPoint GetPoint(float degrees, float radius)
        {
            float  radAngle = MathUtil.DegreesToRadians(degrees) - MathUtil.PiOverTwo;
            double x        = Math.Cos(radAngle) * radius;
            double y        = Math.Sin(radAngle) * radius;

            return(new PolygonPoint(x, y));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns the degrees of angle A in a triangle using the law of cosines.
        /// </summary>
        /// <param name="A">Position of A.</param>
        /// <param name="B">Position of B.</param>
        /// <param name="C">Position of C.</param>
        public static float Angle(Vector2 A, Vector2 B, Vector2 C)
        {
            float lenA        = Vector2.Distance(B, C);
            float lenB        = Vector2.Distance(A, C);
            float lenC        = Vector2.Distance(A, B);
            float tmpAngle    = ((lenB * lenB + lenC * lenC - lenA * lenA) / (2 * lenB * lenC));
            float radianAngle = (float)Math.Acos(tmpAngle);

            return(MathUtil.RadiansToDegrees(radianAngle));
        }
Ejemplo n.º 5
0
        private Vector4 GetWeights(float altitude)
        {
            Vector4 weights = new Vector4(1);

            weights.X = MathUtil.Clamp((-altitude + 40) / 20, 0, 1);
            weights.Y = MathUtil.Clamp(Math.Abs(altitude - 75) / 40, 0, 1);
            weights.Z = MathUtil.Clamp(Math.Abs(altitude - 175) / 80, 0, 1);
            weights.W = MathUtil.Clamp((altitude - 350) / 50, 0, 1);
            weights.Normalize();
            return(weights);
        }
Ejemplo n.º 6
0
 public PTriangle(Vector2 a, float lengthAB, float angleB, uint thickness) : base(thickness)
 {
     if (angleB >= 180)
     {
         throw new ArgumentException("Angle cannot be greater than or equal to 180.");
     }
     this.position = a;
     this.a        = a;
     this.b        = new Vector2(a.X + lengthAB, a.Y);
     this.c        = b + RadianToVector(MathUtil.DegreesToRadians(angleB) - MathUtil.PiOverTwo) * lengthAB;
 }
Ejemplo n.º 7
0
        public override bool Intersects(float x, float y)
        {
            float distX         = x - TransformedPosition.X;
            float distY         = y - TransformedPosition.Y;
            float radius        = this.radius * TransformedScale.X;
            float distSquared   = (distX * distX) + (distY * distY);
            float radiusSquared = radius * radius;

            if (thickness > 1)
            {
                float t = thickness * TransformedScale.X;
                float innerRadiusSquared = (radius - t) * (radius - t);

                if (distSquared <= radiusSquared && distSquared > innerRadiusSquared)
                {
                    return(true);
                }
            }
            else if (distSquared <= radiusSquared)
            {
                float radians = (float)Math.Atan2(distY, distX) + MathUtil.Pi;
                float angle   = MathUtil.RadiansToDegrees(radians) - TransformedDegrees;
                if (angle < 0)
                {
                    angle += 360;
                }

                // TODO: Pre-compute left and right angles
                float leftAngle  = arcDegrees * 0.5f;
                float rightAngle = leftAngle + arcDegrees;

                //Console.WriteLine("TransformedDegrees: " + TransformedDegrees);
                //Console.WriteLine("Angle between: " + angle);
                //Console.WriteLine("left: " + leftAngle + ", right: " + rightAngle);

                if (angle < leftAngle || angle > rightAngle)
                {
                    return(false);
                }
                //Console.WriteLine("intersects");
                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        internal override List <PolygonPoint> GetPoints(float thickness = 0)
        {
            List <PolygonPoint> points = new List <PolygonPoint>();

            float degreeStep = 360f / sides;
            float r          = radius - thickness;

            for (int i = 0; i < sides; i++)
            {
                float  radAngle = MathUtil.DegreesToRadians(degreeStep * i);
                double x        = Math.Cos(radAngle) * r;
                double y        = Math.Sin(radAngle) * r;

                points.Add(new PolygonPoint(x, y));
            }

            if (!Filled)
            {
                points.Add(points[0]);
            }

            return(points);
        }