Exemplo n.º 1
0
        public bool Occupies(Vector Position)
        {
            uint iternum = 0;
            Vector curpos = Position;
            while (iternum < this._IterMax)
            {
                if (curpos.Length() > Math.Sqrt(3))
                {
                    return false;
                }

                // Box fold
                if (curpos.X > 1.0)
                {
                    curpos.X = 2 - curpos.X;
                }
                else if (curpos.X < -1.0)
                {
                    curpos.X = -2 - curpos.X;
                }
                if (curpos.Y > 1.0)
                {
                    curpos.Y = 2 - curpos.Y;
                }
                else if (curpos.Y < -1.0)
                {
                    curpos.Y = -2 - curpos.Y;
                }
                if (curpos.Z > 1.0)
                {
                    curpos.Z = 2 - curpos.Z;
                }
                else if (curpos.Z < -1.0)
                {
                    curpos.Z = -2 - curpos.Z;
                }
                curpos *= this._F;

                // Ball fold
                double mag = curpos.Length();
                if (mag < this._R)
                {
                    curpos *= 1.0 / this._RSQR;
                }
                else if (mag < 1.0)
                {
                    curpos *= 1.0 / (mag * mag * mag);
                }

                // Constants
                curpos *= this._S;
                curpos = curpos - Position;

                iternum++;
            }
            return true;
        }
Exemplo n.º 2
0
 public ISharpShape Subsect(Vector Offset, Vector Scale)
 {
     return new Subsection(this, Offset, Scale);
 }
Exemplo n.º 3
0
 public bool Occupies(Vector Position)
 {
     return Position.Length() < 1.0;
 }
Exemplo n.º 4
0
 public static Vector operator /(Vector A, double Scalar)
 {
     Vector c = new Vector(A);
     c.Divide(Scalar);
     return c;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a matrix that translates to the specified position and rotates to align the x axis
 /// with the specified target.
 /// </summary>
 public static Matrix Lookat(Vector Up, Vector Pos, Vector Target)
 {
     return Transform(Align(Up, Target - Pos), Translate(Pos));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a matrix that translates by the specified amount.
 /// </summary>
 public static Matrix Translate(Vector Amount)
 {
     return new Matrix(
         1.0, 0.0, 0.0, Amount.X,
         0.0, 1.0, 0.0, Amount.Y,
         0.0, 0.0, 1.0, Amount.Z,
         0.0, 0.0, 0.0, 1.0);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Subtracts another vector from this vector.
 /// </summary>
 public void Subtract(Vector Other)
 {
     this.X -= Other.X;
     this.Y -= Other.Y;
     this.Z -= Other.Z;
 }
Exemplo n.º 8
0
 public ISharpShape Subsect(Vector Offset, Vector Scale)
 {
     Offset.Scale(this._Scale);
     Scale.Scale(this._Scale);
     Offset.Add(this._Offset);
     return this._Source.Subsect(Offset, Scale);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Adds another vector to this vector.
 /// </summary>
 public void Add(Vector Other)
 {
     this.X += Other.X;
     this.Y += Other.Y;
     this.Z += Other.Z;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Scales the vector the specified amount.
 /// </summary>
 public void Scale(Vector Scale)
 {
     this.X *= Scale.X;
     this.Y *= Scale.Y;
     this.Z *= Scale.Z;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Computes the dot product between two vectors.
 /// </summary>
 public static double Dot(Vector A, Vector B)
 {
     return (A.X * B.X) + (A.Y * B.Y) + (A.Z * B.Z);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Computes the cross product between two vectors, with the resulting
 /// vector being the normal.
 /// </summary>
 public static Vector Cross(Vector A, Vector B)
 {
     return new Vector(
         (A.Y * B.Z) - (A.Z * B.Y),
         (A.Z * B.X) - (A.X * B.Z),
         (A.X * B.Y) - (A.Y * B.X));
 }
Exemplo n.º 13
0
        private void _DrawOctoTree(Vector Offset, Vector Scale, OctoTree Tree)
        {
            if (Tree == OctoTree.Full)
            {
                GL.Color3(Color.FromArgb(192, (int)(Offset.X * 126 + 127), (int)(Offset.Y * 126 + 127), (int)(Offset.Z * 126 + 127)));
                GL.Vertex3(Offset);
            }
            else if (Tree == OctoTree.Empty)
            {

            }
            else
            {
                OctoTree[] children = Tree.Children;
                for (int t = 0; t < 8; t++)
                {
                    Vector offset = OctoTree.Offset(t);
                    offset.Scale(Scale);
                    _DrawOctoTree(Offset + offset, Scale * 0.5, children[t]);
                }
            }
        }
Exemplo n.º 14
0
 public Subsection(ISharpShape Source, Vector Offset, Vector Scale)
 {
     this._Source = Source;
     this._Scale = Scale;
     this._Offset = Offset;
 }
Exemplo n.º 15
0
 public Vector(Vector Source)
 {
     this.X = Source.X;
     this.Y = Source.Y;
     this.Z = Source.Z;
 }
Exemplo n.º 16
0
 public bool Occupies(Vector Position)
 {
     Position.Scale(this._Scale);
     Position.Add(this._Offset);
     return this._Source.Occupies(Position);
 }
Exemplo n.º 17
0
 public static Vector operator *(Vector A, double Scalar)
 {
     Vector c = new Vector(A);
     c.Multiply(Scalar);
     return c;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Creates a rotation matrix that will bring the new x vector to the specified foward vector
 /// and the z vector as close to the up vector as possible.
 /// </summary>
 public static Matrix Align(Vector Up, Vector Foward)
 {
     Vector x = Foward;
     x.Normalize();
     Vector y = Vector.Cross(Up, x);
     y.Normalize();
     Vector z = Vector.Cross(x, y);
     z.Normalize();
     return Remap(x, y, z, new Vector(0.0, 0.0, 0.0));
 }
Exemplo n.º 19
0
 public static Vector operator +(Vector A, Vector B)
 {
     Vector c = new Vector(A);
     c.Add(B);
     return c;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Creates a matrix that remaps all the unit vector to the specified vector and adds the specified
 /// translation.
 /// </summary>
 public static Matrix Remap(Vector X, Vector Y, Vector Z, Vector T)
 {
     return new Matrix(
         X.X, Y.X, Z.X, T.X,
         X.Y, Y.Y, Z.Y, T.Y,
         X.Z, Y.Z, Z.Z, T.Z,
         0.0, 0.0, 0.0, 1.0);
 }
Exemplo n.º 21
0
 public static Vector operator -(Vector A, Vector B)
 {
     Vector c = new Vector(A);
     c.Subtract(B);
     return c;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Linear transforms a vector and returns the result. Such a transform will not apply translation
 /// and is useful for converting direction vectors.
 /// </summary>
 public Vector LinearTransform(Vector Vector)
 {
     return new Vector(
         (this.M11 * Vector.X) + (this.M12 * Vector.Y) + (this.M13 * Vector.Z),
         (this.M21 * Vector.X) + (this.M22 * Vector.Y) + (this.M23 * Vector.Z),
         (this.M31 * Vector.X) + (this.M32 * Vector.Y) + (this.M33 * Vector.Z));
 }
Exemplo n.º 23
0
 public bool Occupies(Vector Position)
 {
     switch (this.Content)
     {
         case BlockyShapeContent.Full:
             return true;
         case BlockyShapeContent.Empty:
             return false;
         case BlockyShapeContent.Partial:
             int index = 0;
             if (Position.Z < 0.0) { index += 1; Position.Z += 1.0; }
             if (Position.Y < 0.0) { index += 2; Position.Y += 1.0; }
             if (Position.X < 0.0) { index += 4; Position.X += 1.0; }
             return this[index].Occupies(Position * 2 - new Vector(1.0, 1.0, 1.0));
     }
     return false;
 }