Guest User

Untitled

a guest
Feb 19th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 21.40 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MathLibrary
  4. {
  5.   public class Vector3
  6.   {
  7.     private float _x, _y, _z;
  8.  
  9.     //Properties
  10.     public float X
  11.     {
  12.       get
  13.       {
  14.         return _x;
  15.       }
  16.       set
  17.       {
  18.         _x = value;
  19.       }
  20.     }
  21.  
  22.     public float Y
  23.     {
  24.       get
  25.       {
  26.         return _y;
  27.       }
  28.       set
  29.       {
  30.         _y = value;
  31.       }
  32.     }
  33.  
  34.     public float Z
  35.     {
  36.       get
  37.       {
  38.         return _z;
  39.       }
  40.       set
  41.       {
  42.         _z = value;
  43.       }
  44.     }
  45.  
  46.     //-------------------------------------------------------------------------
  47.     //  Fn: ToString
  48.     //
  49.     //  Return: String describing the matrix.
  50.     //
  51.     //  Purpose: A way to view the Vector3 object in a string format.  Of
  52.     //    note is that this is an "override" function.  ToString is a function
  53.     //    that is standard to all objects in C#.  If you are making a custom
  54.     //    data type, and it makes sense to be able to print the object to a
  55.     //    console.
  56.     //    -COMPLETED-
  57.     //-------------------------------------------------------------------------
  58.     public override string ToString()
  59.     {
  60.       return "(" + _x + ", " + _y + ", " + _z + ")";
  61.     }
  62.  
  63.     //-------------------------------------------------------------------------
  64.     // Fn: Equals
  65.     //
  66.     // Params:
  67.     //    object obj - Second object in comparison
  68.     //
  69.     // Return: True if equal, false if not
  70.     //
  71.     // Purpose: Another override function that is standard on all objects in C#
  72.     //    and can be used to check equality between objects.  If your custom
  73.     //    objects are setup in a way that you need to check their equality, you
  74.     //    can override this function or create an = operator custom to your
  75.     //    object type.
  76.     //    -COMPLETED-
  77.     //-------------------------------------------------------------------------
  78.     public override bool Equals(object obj)
  79.     {
  80.       //The 'as' operator allows you to take an object of one type, and attempt
  81.       //  to convert it to another type.  In the case that this conversion is
  82.       //  good, it will return a valid object.  If the conversion is bad, it
  83.       //  will return 'null', which is basically saying that the object is
  84.       //  not valid.
  85.       Vector3 other = obj as Vector3;
  86.       if (other == null)
  87.         return false;
  88.  
  89.       if (other.X == X && other.Y == Y && other.Z == Z)
  90.         return true;
  91.  
  92.       return false;
  93.     }
  94.  
  95.     //-------------------------------------------------------------------------
  96.     // Fn: GetHashCode
  97.     //
  98.     // Return/Purpose: This is often paired with Equals as overrides.  This
  99.     //    function will return a number value that uniquely describes the
  100.     //    object.  The main idea is that this function will only ever return
  101.     //    the same value as another object if the Equals function above would
  102.     //    return true.  I don't have it implemented here, but figured it would
  103.     //    be worth mentioning.
  104.     //-------------------------------------------------------------------------
  105.     public override int GetHashCode()
  106.     {
  107.       return base.GetHashCode();
  108.     }
  109.  
  110.     //Required Constructors:
  111.     //  Vector3();
  112.     //  Vector3(Vector3 vec);
  113.     //  Vector3(float x, float y, float z);
  114.  
  115.     //-------------------------------------------------------------------------
  116.     // Constructors
  117.     //-------------------------------------------------------------------------
  118.     // Constructor: Vector3
  119.     //
  120.     // Purpose: Creates a default vector of (0, 0, 0)
  121.     //-------------------------------------------------------------------------
  122.     public Vector3()
  123.     {
  124.         X = 0;
  125.         Y = 0;
  126.         Z = 0;
  127.     }
  128.  
  129.     //-------------------------------------------------------------------------
  130.     // Constructor: Vector3
  131.     //
  132.     // Params:
  133.     //    Vector3 vec - Vector being copied.
  134.     //
  135.     // Purpose: Copy constructor that takes a vector and creates a new copy of
  136.     //    the passed in vector.
  137.     //-------------------------------------------------------------------------
  138.     public Vector3(Vector3 vec)
  139.     {
  140.         X = vec.X;
  141.         Y = vec.Y;
  142.         Z = vec.Z;
  143.     }
  144.  
  145.     //-------------------------------------------------------------------------
  146.     // Constructor: Vector3
  147.     //
  148.     // Params:
  149.     //    float x - X coordinate of the new vector.
  150.     //    float y - Y coordiante of the new vector.
  151.     //    float z - Z coordinate of the new vector.
  152.     //
  153.     // Purpose: Takes a set of coordinates and creates a new vector using the
  154.     //    passed in coordinates.
  155.     //-------------------------------------------------------------------------
  156.     public Vector3(float x, float y, float z)
  157.     {
  158.         X = x;
  159.         Y = y;
  160.         Z = z;
  161.     }
  162.     //-------------------------------------------------------------------------
  163.     // Constructors
  164.     //-------------------------------------------------------------------------
  165.  
  166.     //-------------------------------------------------------------------------
  167.     // Initializers
  168.     //-------------------------------------------------------------------------
  169.     // Fn: Init
  170.     //
  171.     // Return: this
  172.     //
  173.     // Purpose: Initializes a vector with the position (0, 0, 0)
  174.     //-------------------------------------------------------------------------
  175.     public Vector3 Init()
  176.     {
  177.       _x = 0;
  178.       _y = 0;
  179.       _z = 0;
  180.  
  181.       return this;
  182.     }
  183.  
  184.     //-------------------------------------------------------------------------
  185.     // Fn: Init
  186.     //
  187.     // Params:
  188.     //    Vector3 vec - Vector being copied.
  189.     //
  190.     // Return: this
  191.     //
  192.     // Purpose: Initializes a vector using the coordinates stored in another
  193.     //    vector.
  194.     //-------------------------------------------------------------------------
  195.     public Vector3 Init(Vector3 vec)
  196.     {
  197.         // Maybe correct, maybe not
  198.         _x = vec.X;
  199.         _y = vec.Y;
  200.         _z = vec.Z;
  201.       return Init();
  202.     }
  203.  
  204.     //-------------------------------------------------------------------------
  205.     // Init
  206.     //
  207.     // Params:
  208.     //    float X - X coordinate of the new vector.
  209.     //    float Y - Y coordinate of the new vector.
  210.     //    float Z - Z coordinate of the new vector.
  211.     //
  212.     // Return: this
  213.     //
  214.     // Purpose: Initializes a new vector using the coordinate (X, Y, Z) as
  215.     //    passed into the function.
  216.     //-------------------------------------------------------------------------
  217.     public Vector3 Init(float X, float Y, float Z)
  218.     {
  219.         _x = X;
  220.         _y = Y;
  221.         _z = Z;
  222.       return Init();
  223.     }
  224.     //-------------------------------------------------------------------------
  225.     // Initializers
  226.     //-------------------------------------------------------------------------
  227.  
  228.     //Required Statics:
  229.     //  static Vector3 Add(Vector3 lhs, Vector3 rhs);
  230.     //  static Vector3 Subtract(Vector3 lhs, Vector3 rhs);
  231.     //  static Vector3 Negate(Vector3 vec);
  232.     //  static Vector3 Scale(Vector3 vec, float s);
  233.     //  static float   Dot(Vector3 lhs, Vector3 rhs);
  234.     //  static Vector3 Cross(Vector3 lhs, Vector3 rhs);
  235.     //  static Vector3 Normalize(Vector3 vec);
  236.     //  static float   Distance(Vector3 a, Vector3 b);
  237.     //  static float   DistanceSquared(Vector3 a, Vector3 b);
  238.     //  static Vector3 Project(Vector3 a, Vector3 b);
  239.     //  static Vector3 PerpendicularProject(Vector3 a, Vector3 b);
  240.     //  static Vector3 Lerp(Vector3 a, Vector3 b, float t);
  241.  
  242.     //-------------------------------------------------------------------------
  243.     // Arithmetic
  244.     //-------------------------------------------------------------------------
  245.     // Fn: Add
  246.     //
  247.     // Params:
  248.     //    Vector3 rhs - Vector on the right of the equation this+rhs
  249.     //
  250.     // Return: this
  251.     //
  252.     // Purpose: Adds vector rhs into 'this'.
  253.     //-------------------------------------------------------------------------
  254.     public Vector3 Add(Vector3 rhs)
  255.     {
  256.       return this;
  257.     }
  258.     //-------------------------------------------------------------------------
  259.     // Fn: Add
  260.     //
  261.     // Params:
  262.     //    Vector3 lhs - Vector on left of lhs+rhs
  263.     //    Vector3 rhs - Vector on right of lhs+rhs
  264.     //
  265.     // Return: New vector object
  266.     //
  267.     // Purpose: Creates a new vector holding the sum of lhs and rhs.
  268.     //-------------------------------------------------------------------------
  269.     public static Vector3 Add(Vector3 lhs, Vector3 rhs)
  270.     {
  271.       return new Vector3();
  272.     }
  273.  
  274.     //-------------------------------------------------------------------------
  275.     // Fn: Subtract
  276.     //
  277.     // Params:
  278.     //    Vector3 rhs - Vector on the right of the equation this-rhs
  279.     //
  280.     // Return: this
  281.     //
  282.     // Purpose: Subtracts vector rhs from 'this'.
  283.     //-------------------------------------------------------------------------
  284.     public Vector3 Subtract(Vector3 rhs)
  285.     {
  286.       return this;
  287.     }
  288.     //-------------------------------------------------------------------------
  289.     // Fn: Subtract
  290.     //
  291.     // Params:
  292.     //    Vector3 lhs - Vector on the left of the equation lhs-rhs
  293.     //    Vector3 rhs - Vector on the right of the equation lhs-rhs
  294.     //
  295.     // Return: New vector object
  296.     //
  297.     // Purpose: Subtracts vector rhs from lhs to create a new vector object.
  298.     //-------------------------------------------------------------------------
  299.     public static Vector3 Subtract(Vector3 lhs, Vector3 rhs)
  300.     {
  301.       return new Vector3();
  302.     }
  303.  
  304.     //-------------------------------------------------------------------------
  305.     // Fn: Negate
  306.     //
  307.     // Return: this
  308.     //
  309.     // Purpose: Negates all components of the vector.
  310.     //-------------------------------------------------------------------------
  311.     public Vector3 Negate()
  312.     {
  313.       return this;
  314.     }
  315.     //-------------------------------------------------------------------------
  316.     // Fn: Negate
  317.     //
  318.     // Params: Vector3 vec - Vector being negated.
  319.     //
  320.     // Return: New vector object
  321.     //
  322.     // Purpose: Negates all components of a copied vector.
  323.     //-------------------------------------------------------------------------
  324.     public static Vector3 Negate(Vector3 vec)
  325.     {
  326.       return new Vector3();
  327.     }
  328.  
  329.     //-------------------------------------------------------------------------
  330.     // Fn: Scale
  331.     //
  332.     // Params:
  333.     //    float s - Scaling value being multiplied in the equation s*this
  334.     //
  335.     // Return: this
  336.     //
  337.     // Purpose: Scales the vector by the scaling value s.
  338.     //-------------------------------------------------------------------------
  339.     public Vector3 Scale(float s)
  340.     {
  341.       return this;
  342.     }
  343.     //-------------------------------------------------------------------------
  344.     // Fn: Scale
  345.     //
  346.     // Params:
  347.     //    Vector3 vec - Vector being copied for the scale.
  348.     //    float s - Scaling value being multiplied in the equation s*vec
  349.     //
  350.     // Return: New vector object
  351.     //
  352.     // Purpose: Scales the vector by the scaling value s.
  353.     //-------------------------------------------------------------------------
  354.     public static Vector3 Scale(Vector3 vec, float s)
  355.     {
  356.       return new Vector3();
  357.     }
  358.  
  359.     //-------------------------------------------------------------------------
  360.     // Fn: Normalize
  361.     //
  362.     // Return: this
  363.     //
  364.     // Purpose: Normalizes the vector, resulting in it having a length of 1.
  365.     //-------------------------------------------------------------------------
  366.     public Vector3 Normalize()
  367.     {
  368.       return this;
  369.     }
  370.     //-------------------------------------------------------------------------
  371.     // Fn: Normalize
  372.     //
  373.     // Params:
  374.     //    Vector3 vec - Vector being copied before the normalize operation.
  375.     //
  376.     // Return: New vector object
  377.     //
  378.     // Purpose: Normalizes the vector, resulting in it having a length of 1.
  379.     //-------------------------------------------------------------------------
  380.     public static Vector3 Normalize(Vector3 vec)
  381.     {
  382.       return new Vector3();
  383.     }
  384.     //-------------------------------------------------------------------------
  385.     // Arithmetic
  386.     //-------------------------------------------------------------------------
  387.  
  388.     //-------------------------------------------------------------------------
  389.     //Linear Algebra
  390.     //-------------------------------------------------------------------------
  391.     // Fn: DotWith
  392.     //
  393.     // Params:
  394.     //    Vector3 rhs - Second vector in the equation this dot rhs.
  395.     //
  396.     // Return: Result of the dot product.
  397.     //
  398.     // Purpose: Dots a passed in vector with self.
  399.     //-------------------------------------------------------------------------
  400.     public float DotWith(Vector3 rhs)
  401.     {
  402.       return 0.0f;
  403.     }
  404.     //-------------------------------------------------------------------------
  405.     // Fn: Dot
  406.     //
  407.     // Params:
  408.     //    Vector3 lhs - Left side of equation lhs dot rhs.
  409.     //    Vector3 rhs - Right side of equation lhs dot rhs.
  410.     //
  411.     // Return: Result of the dot product.
  412.     //
  413.     // Purpose: Dots two passed in vectors together.
  414.     //-------------------------------------------------------------------------
  415.     public static float Dot(Vector3 lhs, Vector3 rhs)
  416.     {
  417.       return 0.0f;
  418.     }
  419.  
  420.     //-------------------------------------------------------------------------
  421.     // Fn: CrossWith
  422.     //
  423.     // Params:
  424.     //    Vector3 rhs - Right side of equation this x rhs
  425.     //
  426.     // Return: new vector object
  427.     //
  428.     // Purpose: Crosses two vectors together, returning the third vector that
  429.     //    results from the operation.
  430.     //-------------------------------------------------------------------------
  431.     public Vector3 CrossWith(Vector3 rhs)
  432.     {
  433.       return new Vector3();
  434.     }
  435.     //-------------------------------------------------------------------------
  436.     // Fn: Cross
  437.     //
  438.     // Params:
  439.     //    Vector3 lhs - Left side of equation lhs x rhs
  440.     //    Vector3 rhs - Right side of equation lhs x rhs
  441.     //
  442.     // Return: new vector object
  443.     //
  444.     // Purpose: Crosses two vectors together, returning the third vector that
  445.     //    results from the operation.
  446.     //-------------------------------------------------------------------------
  447.     public static Vector3 Cross(Vector3 lhs, Vector3 rhs)
  448.     {
  449.       return new Vector3();
  450.     }
  451.     //-------------------------------------------------------------------------
  452.     //Linear Algebra
  453.     //-------------------------------------------------------------------------
  454.  
  455.     //-------------------------------------------------------------------------
  456.     // Geometry
  457.     //-------------------------------------------------------------------------
  458.     // Fn: Length
  459.     //
  460.     // Return: Length of the vector
  461.     //
  462.     // Purpose: Returns the length of vector this.
  463.     //-------------------------------------------------------------------------
  464.     public float Length()
  465.     {
  466.       return 0.0f;
  467.     }
  468.  
  469.     //-------------------------------------------------------------------------
  470.     // Fn: LengthSquared
  471.     //
  472.     // Return: Squared length of the vector
  473.     //
  474.     // Purpose: Returns the squared length of vector this.
  475.     //-------------------------------------------------------------------------
  476.     public float LengthSquared()
  477.     {
  478.       return 0.0f;
  479.     }
  480.  
  481.     //-------------------------------------------------------------------------
  482.     // Fn: DistanceTo
  483.     //
  484.     // Params:
  485.     //    Vector3 vec - Second vector in distance calculation.
  486.     //
  487.     // Return: Distance between this and vec
  488.     //
  489.     // Purpose: Calculates the distance between the ends of the two vectors,
  490.     //    this and vec, assuming they are anchored at the origin (0, 0).
  491.     //-------------------------------------------------------------------------
  492.     public float DistanceTo(Vector3 vec)
  493.     {
  494.       return 0.0f;
  495.     }
  496.     //-------------------------------------------------------------------------
  497.     // Fn: Distance
  498.     //
  499.     // Params:
  500.     //    Vector3 a - First vector in distance calculation.
  501.     //    Vector3 b - Second vector in distance calculation.
  502.     //
  503.     // Return: Distance between a and b
  504.     //
  505.     // Purpose: Calculates the distance between the ends of the two vectors,
  506.     //    a and b, assuming they are anchored at the origin (0, 0).
  507.     //-------------------------------------------------------------------------
  508.     public static float Distance(Vector3 a, Vector3 b)
  509.     {
  510.       return 0.0f;
  511.     }
  512.  
  513.     //-------------------------------------------------------------------------
  514.     // Fn: DistanceSquaredTo
  515.     //
  516.     // Params:
  517.     //    Vector3 vec - Second vector in distance calculation.
  518.     //
  519.     // Return: Squared distance between this and vec
  520.     //
  521.     // Purpose: Calculates the distance between the ends of the two vectors,
  522.     //    this and vec, assuming they are anchored at the origin (0, 0).
  523.     //-------------------------------------------------------------------------
  524.     public float DistanceSquaredTo(Vector3 vec)
  525.     {
  526.       return 0.0f;
  527.     }
  528.     //-------------------------------------------------------------------------
  529.     // Fn: DistanceSquared
  530.     //
  531.     // Params:
  532.     //    Vector3 a - First vector in distance calculation.
  533.     //    Vector3 b - Second vector in distance calculation.
  534.     //
  535.     // Return: Squared distance between a and b
  536.     //
  537.     // Purpose: Calculates the distance between the ends of the two vectors,
  538.     //    a and b, assuming they are anchored at the origin (0, 0).
  539.     //-------------------------------------------------------------------------
  540.     public static float DistanceSquared(Vector3 a, Vector3 b)
  541.     {
  542.       return 0.0f;
  543.     }
  544.  
  545.     //-------------------------------------------------------------------------
  546.     // Fn: ProjectOnto
  547.     //
  548.     // Params:
  549.     //    Vector3 vec - Vector being projected onto
  550.     //
  551.     // Return: New vector object
  552.     //
  553.     // Purpose: Projects vector 'this' onto vector vec.  Returns the vector
  554.     //    that results from this operation.
  555.     //-------------------------------------------------------------------------
  556.     public Vector3 ProjectOnto(Vector3 vec)
  557.     {
  558.       return new Vector3();
  559.     }
  560.     //-------------------------------------------------------------------------
  561.     // Fn: Project
  562.     //
  563.     // Params:
  564.     //    Vector3 a - Vector being projected
  565.     //    Vector3 b - Vector being projected onto
  566.     //
  567.     // Return: New vector object
  568.     //
  569.     // Purpose: Projects vector a onto vector b.  Returns the vector
  570.     //    that results from this operation.
  571.     //-------------------------------------------------------------------------
  572.     public static Vector3 Project(Vector3 a, Vector3 b)
  573.     {
  574.       return new Vector3();
  575.     }
  576.  
  577.     //-------------------------------------------------------------------------
  578.     // Fn: PerpendicularProjectOnto
  579.     //
  580.     // Params:
  581.     //    Vector3 vec - Vector being projected onto
  582.     //
  583.     // Return: New vector object
  584.     //
  585.     // Purpose: Projects vector 'this' onto vector vec.  Returns the vector
  586.     //    that results from this operation.
  587.     //-------------------------------------------------------------------------
  588.     public Vector3 PerpendicularProjectOnto(Vector3 vec)
  589.     {
  590.       return new Vector3();
  591.     }
  592.     //-------------------------------------------------------------------------
  593.     // Fn: PerpendicularProject
  594.     //
  595.     // Params:
  596.     //    Vector3 a - Vector being projected
  597.     //    Vector3 b - Vector being projected onto
  598.     //
  599.     // Return: New vector object
  600.     //
  601.     // Purpose: Projects vector a onto vector b.  Returns the vector
  602.     //    that results from this operation.
  603.     //-------------------------------------------------------------------------
  604.     public static Vector3 PerpendicularProject(Vector3 a, Vector3 b)
  605.     {
  606.       return new Vector3();
  607.     }
  608.  
  609.     //-------------------------------------------------------------------------
  610.     // Fn: LerpTowards
  611.     //
  612.     // Params:
  613.     //    Vector3 vec - Vector being LERPed towards.  Result at t = 1
  614.     //    float t - Time used for LERP operation.
  615.     //
  616.     // Return: New vector object
  617.     //
  618.     // Purpose: Runs the linear interpolation operation using vector this as a
  619.     //    starting point.  Lerps towards vec at time t.
  620.     //-------------------------------------------------------------------------
  621.     public Vector3 LerpTowards(Vector3 vec, float t)
  622.     {
  623.       return new Vector3();
  624.     }
  625.     //-------------------------------------------------------------------------
  626.     // Fn: Lerp
  627.     //
  628.     // Params:
  629.     //    Vector3 a - Vector being LERPed from.  Result at t = 0
  630.     //    Vector3 b - Vector being LERPed towards.  Result at t = 1
  631.     //    float t - Time used for LERP operation.
  632.     //
  633.     // Return: New vector object
  634.     //
  635.     // Purpose: Runs the linear interpolation operation using vector a as a
  636.     //    starting point.  Lerps towards b at time t.
  637.     //-------------------------------------------------------------------------
  638.     public static Vector3 Lerp(Vector3 a, Vector3 b, float t)
  639.     {
  640.       return new Vector3();
  641.     }
  642.     //-------------------------------------------------------------------------
  643.     // Geometry
  644.     //-------------------------------------------------------------------------
  645.   }
  646. }
Add Comment
Please, Sign In to add comment