Beispiel #1
0
        public static PVector FromAngle(float angle, PVector target)
        {
            if (target == null)
            {
                target = new PVector();
            }
            float x = (float)Math.Cos(angle);
            float y = (float)Math.Sin(angle);

            target.Set(x, y);

            return(target);
        }
Beispiel #2
0
        public float AngleBetween(PVector v)
        {
            if (isAllComponentsZero(this) || isAllComponentsZero(v))
            {
                return(0.0f);
            }

            float dotProduct    = Dot(v);
            float thisMagnitude = Mag();
            float vMagnitude    = v.Mag();
            float cosAngle      = dotProduct / (thisMagnitude * vMagnitude);
            float angle         = (float)Math.Acos(cosAngle);

            return(angle);
        }
Beispiel #3
0
        public static PVector Cross(PVector v1, PVector v2, PVector target)
        {
            PVector crossProduct = v1.Cross(v2);

            if (target == null)
            {
                target = crossProduct;
            }
            else
            {
                target.Set(crossProduct.X, crossProduct.Y, crossProduct.Z);
            }

            return(target);
        }
Beispiel #4
0
        public PVector Cross(PVector v, PVector target)
        {
            float xCrossComponent = Y * v.Z - Z * v.Y;
            float yCrossComponent = Z * v.X - X * v.Z;
            float zCrossComponent = X * v.Y - Y * v.X;

            if (target == null)
            {
                target = new PVector(xCrossComponent, yCrossComponent, zCrossComponent);
            }
            else
            {
                target.Set(xCrossComponent, yCrossComponent, zCrossComponent);
            }

            return(target);
        }
Beispiel #5
0
        public static PVector Div(PVector vectorA, float scalar, PVector target)
        {
            PVector resultVector;

            if (target == null)
            {
                resultVector = vectorA.Copy();
            }
            else
            {
                target.X = vectorA.X;
                target.Y = vectorA.Y;
                target.Z = vectorA.Z;

                resultVector = target;
            }

            return(resultVector.Div(scalar));
        }
Beispiel #6
0
        public static PVector Add(PVector vectorA, PVector vectorB, PVector target)
        {
            PVector resultVector;

            if (target == null)
            {
                resultVector = vectorA.Copy();
            }
            else
            {
                target.X = vectorA.X;
                target.Y = vectorA.Y;
                target.Z = vectorA.Z;

                resultVector = target;
            }

            return(resultVector.Add(vectorB));
        }
Beispiel #7
0
        public static PVector Random2D(PVector target, Random random)
        {
            if (random == null)
            {
                random = new Random();
            }

            float randomAngle = (float)(random.NextDouble() * Math.PI * 2);

            if (target == null)
            {
                target = FromAngle(randomAngle);
            }
            else
            {
                PVector vectorFromAngle = FromAngle(randomAngle);
                target.Set(vectorFromAngle.X, vectorFromAngle.Y);
            }

            return(target);
        }
Beispiel #8
0
        public static PVector Random3D(PVector target, Random random)
        {
            const int maxValue = 1000;

            if (random == null)
            {
                random = new Random();
            }
            float randomX = (float)((random.NextDouble() * 2 - 1) * maxValue);
            float randomY = (float)((random.NextDouble() * 2 - 1) * maxValue);
            float randomZ = (float)((random.NextDouble() * 2 - 1) * maxValue);

            if (target == null)
            {
                target = new PVector(randomX, randomY, randomZ);
            }
            else
            {
                target.Set(randomX, randomY, randomZ);
            }
            target.Normalize();
            return(target);
        }
Beispiel #9
0
        public virtual void Text(string text, float x, float y, float z)
        {
            PVector transformedPosition = transformation.GetTransformedVector(x, y, z);

            drawTextImpl(transformedPosition, text.ToCharArray());
        }
Beispiel #10
0
        public virtual void Vertex(float x, float y)
        {
            PVector position = transformation.GetTransformedVector(x, y);

            addVertexImpl(position);
        }
Beispiel #11
0
        public virtual void Ellipse(float x, float y, float width, float height)
        {
            PVector transformedPosition = transformation.GetTransformedVector(x - width, y - height);

            drawEllipseImpl(transformedPosition, width, height);
        }
Beispiel #12
0
        public virtual void Rect(float x, float y, float width, float heigth)
        {
            PVector transformedPosition = transformation.GetTransformedVector(x, y);

            drawRectImpl(transformedPosition, width, heigth);
        }
Beispiel #13
0
 protected virtual void drawTextImpl(PVector position, char[] chars)
 {
 }
Beispiel #14
0
 protected virtual void drawLineImpl(PVector p1, PVector p2)
 {
 }
Beispiel #15
0
        public static PVector Lerp(PVector v1, PVector v2, float ammount)
        {
            PVector resultVector = v1.Copy();

            return(resultVector.Lerp(v2, ammount));
        }
Beispiel #16
0
 protected virtual void drawEllipseImpl(PVector position, float width, float height)
 {
 }
Beispiel #17
0
 protected virtual void drawPointImpl(PVector position)
 {
 }
Beispiel #18
0
 public static PVector Random3D(PVector target)
 {
     return(Random3D(target, null));
 }
Beispiel #19
0
 protected virtual void addVertexImpl(PVector position)
 {
 }
Beispiel #20
0
 public PVector Set(PVector v)
 {
     return(Set(v.X, v.Y, v.Z));
 }
Beispiel #21
0
        public virtual void Circle(float x, float y, float radius)
        {
            PVector transformedPosition = transformation.GetTransformedVector(x - radius, y - radius);

            drawCircleImpl(transformedPosition, radius);
        }
Beispiel #22
0
 private bool isAllComponentsZero(PVector testVector)
 {
     return(testVector.X == 0 && testVector.Y == 0 && testVector.Z == 0);
 }
Beispiel #23
0
        public virtual void Square(float x, float y, float sideLength)
        {
            PVector transformedPosition = transformation.GetTransformedVector(x, y);

            drawSquareImpl(transformedPosition, sideLength);
        }
 public Transformation()
 {
     origin = new PVector(0, 0, 0);
     Angle  = 0;
 }
Beispiel #25
0
        public virtual void Point(int x, int y)
        {
            PVector transformedPosition = transformation.GetTransformedVector(x, y);

            drawPointImpl(transformedPosition);
        }
Beispiel #26
0
 protected virtual void drawCircleImpl(PVector position, float radius)
 {
 }
Beispiel #27
0
        public virtual void Text(char c, float x, float y, float z)
        {
            PVector transformedPosition = transformation.GetTransformedVector(x, y, z);

            drawTextImpl(transformedPosition, new char[] { c });
        }
Beispiel #28
0
 protected virtual void drawRectImpl(PVector position, float width, float heigth)
 {
 }
Beispiel #29
0
        public virtual void Text(int num, float x, float y, float z)
        {
            PVector transformedPosition = transformation.GetTransformedVector(x, y, z);

            drawTextImpl(transformedPosition, num.ToString().ToCharArray());
        }
Beispiel #30
0
 protected virtual void drawSquareImpl(PVector position, float sideLength)
 {
 }