Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MathLibrary
- {
- public class Vector3
- {
- private float _x, _y, _z;
- //Properties
- public float X
- {
- get
- {
- return _x;
- }
- set
- {
- _x = value;
- }
- }
- public float Y
- {
- get
- {
- return _y;
- }
- set
- {
- _y = value;
- }
- }
- public float Z
- {
- get
- {
- return _z;
- }
- set
- {
- _z = value;
- }
- }
- //-------------------------------------------------------------------------
- // Fn: ToString
- //
- // Return: String describing the matrix.
- //
- // Purpose: A way to view the Vector3 object in a string format. Of
- // note is that this is an "override" function. ToString is a function
- // that is standard to all objects in C#. If you are making a custom
- // data type, and it makes sense to be able to print the object to a
- // console.
- // -COMPLETED-
- //-------------------------------------------------------------------------
- public override string ToString()
- {
- return "(" + _x + ", " + _y + ", " + _z + ")";
- }
- //-------------------------------------------------------------------------
- // Fn: Equals
- //
- // Params:
- // object obj - Second object in comparison
- //
- // Return: True if equal, false if not
- //
- // Purpose: Another override function that is standard on all objects in C#
- // and can be used to check equality between objects. If your custom
- // objects are setup in a way that you need to check their equality, you
- // can override this function or create an = operator custom to your
- // object type.
- // -COMPLETED-
- //-------------------------------------------------------------------------
- public override bool Equals(object obj)
- {
- //The 'as' operator allows you to take an object of one type, and attempt
- // to convert it to another type. In the case that this conversion is
- // good, it will return a valid object. If the conversion is bad, it
- // will return 'null', which is basically saying that the object is
- // not valid.
- Vector3 other = obj as Vector3;
- if (other == null)
- return false;
- if (other.X == X && other.Y == Y && other.Z == Z)
- return true;
- return false;
- }
- //-------------------------------------------------------------------------
- // Fn: GetHashCode
- //
- // Return/Purpose: This is often paired with Equals as overrides. This
- // function will return a number value that uniquely describes the
- // object. The main idea is that this function will only ever return
- // the same value as another object if the Equals function above would
- // return true. I don't have it implemented here, but figured it would
- // be worth mentioning.
- //-------------------------------------------------------------------------
- public override int GetHashCode()
- {
- return base.GetHashCode();
- }
- //Required Constructors:
- // Vector3();
- // Vector3(Vector3 vec);
- // Vector3(float x, float y, float z);
- //-------------------------------------------------------------------------
- // Constructors
- //-------------------------------------------------------------------------
- // Constructor: Vector3
- //
- // Purpose: Creates a default vector of (0, 0, 0)
- //-------------------------------------------------------------------------
- public Vector3()
- {
- X = 0;
- Y = 0;
- Z = 0;
- }
- //-------------------------------------------------------------------------
- // Constructor: Vector3
- //
- // Params:
- // Vector3 vec - Vector being copied.
- //
- // Purpose: Copy constructor that takes a vector and creates a new copy of
- // the passed in vector.
- //-------------------------------------------------------------------------
- public Vector3(Vector3 vec)
- {
- X = vec.X;
- Y = vec.Y;
- Z = vec.Z;
- }
- //-------------------------------------------------------------------------
- // Constructor: Vector3
- //
- // Params:
- // float x - X coordinate of the new vector.
- // float y - Y coordiante of the new vector.
- // float z - Z coordinate of the new vector.
- //
- // Purpose: Takes a set of coordinates and creates a new vector using the
- // passed in coordinates.
- //-------------------------------------------------------------------------
- public Vector3(float x, float y, float z)
- {
- X = x;
- Y = y;
- Z = z;
- }
- //-------------------------------------------------------------------------
- // Constructors
- //-------------------------------------------------------------------------
- //-------------------------------------------------------------------------
- // Initializers
- //-------------------------------------------------------------------------
- // Fn: Init
- //
- // Return: this
- //
- // Purpose: Initializes a vector with the position (0, 0, 0)
- //-------------------------------------------------------------------------
- public Vector3 Init()
- {
- _x = 0;
- _y = 0;
- _z = 0;
- return this;
- }
- //-------------------------------------------------------------------------
- // Fn: Init
- //
- // Params:
- // Vector3 vec - Vector being copied.
- //
- // Return: this
- //
- // Purpose: Initializes a vector using the coordinates stored in another
- // vector.
- //-------------------------------------------------------------------------
- public Vector3 Init(Vector3 vec)
- {
- // Maybe correct, maybe not
- _x = vec.X;
- _y = vec.Y;
- _z = vec.Z;
- return Init();
- }
- //-------------------------------------------------------------------------
- // Init
- //
- // Params:
- // float X - X coordinate of the new vector.
- // float Y - Y coordinate of the new vector.
- // float Z - Z coordinate of the new vector.
- //
- // Return: this
- //
- // Purpose: Initializes a new vector using the coordinate (X, Y, Z) as
- // passed into the function.
- //-------------------------------------------------------------------------
- public Vector3 Init(float X, float Y, float Z)
- {
- _x = X;
- _y = Y;
- _z = Z;
- return Init();
- }
- //-------------------------------------------------------------------------
- // Initializers
- //-------------------------------------------------------------------------
- //Required Statics:
- // static Vector3 Add(Vector3 lhs, Vector3 rhs);
- // static Vector3 Subtract(Vector3 lhs, Vector3 rhs);
- // static Vector3 Negate(Vector3 vec);
- // static Vector3 Scale(Vector3 vec, float s);
- // static float Dot(Vector3 lhs, Vector3 rhs);
- // static Vector3 Cross(Vector3 lhs, Vector3 rhs);
- // static Vector3 Normalize(Vector3 vec);
- // static float Distance(Vector3 a, Vector3 b);
- // static float DistanceSquared(Vector3 a, Vector3 b);
- // static Vector3 Project(Vector3 a, Vector3 b);
- // static Vector3 PerpendicularProject(Vector3 a, Vector3 b);
- // static Vector3 Lerp(Vector3 a, Vector3 b, float t);
- //-------------------------------------------------------------------------
- // Arithmetic
- //-------------------------------------------------------------------------
- // Fn: Add
- //
- // Params:
- // Vector3 rhs - Vector on the right of the equation this+rhs
- //
- // Return: this
- //
- // Purpose: Adds vector rhs into 'this'.
- //-------------------------------------------------------------------------
- public Vector3 Add(Vector3 rhs)
- {
- return this;
- }
- //-------------------------------------------------------------------------
- // Fn: Add
- //
- // Params:
- // Vector3 lhs - Vector on left of lhs+rhs
- // Vector3 rhs - Vector on right of lhs+rhs
- //
- // Return: New vector object
- //
- // Purpose: Creates a new vector holding the sum of lhs and rhs.
- //-------------------------------------------------------------------------
- public static Vector3 Add(Vector3 lhs, Vector3 rhs)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Fn: Subtract
- //
- // Params:
- // Vector3 rhs - Vector on the right of the equation this-rhs
- //
- // Return: this
- //
- // Purpose: Subtracts vector rhs from 'this'.
- //-------------------------------------------------------------------------
- public Vector3 Subtract(Vector3 rhs)
- {
- return this;
- }
- //-------------------------------------------------------------------------
- // Fn: Subtract
- //
- // Params:
- // Vector3 lhs - Vector on the left of the equation lhs-rhs
- // Vector3 rhs - Vector on the right of the equation lhs-rhs
- //
- // Return: New vector object
- //
- // Purpose: Subtracts vector rhs from lhs to create a new vector object.
- //-------------------------------------------------------------------------
- public static Vector3 Subtract(Vector3 lhs, Vector3 rhs)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Fn: Negate
- //
- // Return: this
- //
- // Purpose: Negates all components of the vector.
- //-------------------------------------------------------------------------
- public Vector3 Negate()
- {
- return this;
- }
- //-------------------------------------------------------------------------
- // Fn: Negate
- //
- // Params: Vector3 vec - Vector being negated.
- //
- // Return: New vector object
- //
- // Purpose: Negates all components of a copied vector.
- //-------------------------------------------------------------------------
- public static Vector3 Negate(Vector3 vec)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Fn: Scale
- //
- // Params:
- // float s - Scaling value being multiplied in the equation s*this
- //
- // Return: this
- //
- // Purpose: Scales the vector by the scaling value s.
- //-------------------------------------------------------------------------
- public Vector3 Scale(float s)
- {
- return this;
- }
- //-------------------------------------------------------------------------
- // Fn: Scale
- //
- // Params:
- // Vector3 vec - Vector being copied for the scale.
- // float s - Scaling value being multiplied in the equation s*vec
- //
- // Return: New vector object
- //
- // Purpose: Scales the vector by the scaling value s.
- //-------------------------------------------------------------------------
- public static Vector3 Scale(Vector3 vec, float s)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Fn: Normalize
- //
- // Return: this
- //
- // Purpose: Normalizes the vector, resulting in it having a length of 1.
- //-------------------------------------------------------------------------
- public Vector3 Normalize()
- {
- return this;
- }
- //-------------------------------------------------------------------------
- // Fn: Normalize
- //
- // Params:
- // Vector3 vec - Vector being copied before the normalize operation.
- //
- // Return: New vector object
- //
- // Purpose: Normalizes the vector, resulting in it having a length of 1.
- //-------------------------------------------------------------------------
- public static Vector3 Normalize(Vector3 vec)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Arithmetic
- //-------------------------------------------------------------------------
- //-------------------------------------------------------------------------
- //Linear Algebra
- //-------------------------------------------------------------------------
- // Fn: DotWith
- //
- // Params:
- // Vector3 rhs - Second vector in the equation this dot rhs.
- //
- // Return: Result of the dot product.
- //
- // Purpose: Dots a passed in vector with self.
- //-------------------------------------------------------------------------
- public float DotWith(Vector3 rhs)
- {
- return 0.0f;
- }
- //-------------------------------------------------------------------------
- // Fn: Dot
- //
- // Params:
- // Vector3 lhs - Left side of equation lhs dot rhs.
- // Vector3 rhs - Right side of equation lhs dot rhs.
- //
- // Return: Result of the dot product.
- //
- // Purpose: Dots two passed in vectors together.
- //-------------------------------------------------------------------------
- public static float Dot(Vector3 lhs, Vector3 rhs)
- {
- return 0.0f;
- }
- //-------------------------------------------------------------------------
- // Fn: CrossWith
- //
- // Params:
- // Vector3 rhs - Right side of equation this x rhs
- //
- // Return: new vector object
- //
- // Purpose: Crosses two vectors together, returning the third vector that
- // results from the operation.
- //-------------------------------------------------------------------------
- public Vector3 CrossWith(Vector3 rhs)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Fn: Cross
- //
- // Params:
- // Vector3 lhs - Left side of equation lhs x rhs
- // Vector3 rhs - Right side of equation lhs x rhs
- //
- // Return: new vector object
- //
- // Purpose: Crosses two vectors together, returning the third vector that
- // results from the operation.
- //-------------------------------------------------------------------------
- public static Vector3 Cross(Vector3 lhs, Vector3 rhs)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- //Linear Algebra
- //-------------------------------------------------------------------------
- //-------------------------------------------------------------------------
- // Geometry
- //-------------------------------------------------------------------------
- // Fn: Length
- //
- // Return: Length of the vector
- //
- // Purpose: Returns the length of vector this.
- //-------------------------------------------------------------------------
- public float Length()
- {
- return 0.0f;
- }
- //-------------------------------------------------------------------------
- // Fn: LengthSquared
- //
- // Return: Squared length of the vector
- //
- // Purpose: Returns the squared length of vector this.
- //-------------------------------------------------------------------------
- public float LengthSquared()
- {
- return 0.0f;
- }
- //-------------------------------------------------------------------------
- // Fn: DistanceTo
- //
- // Params:
- // Vector3 vec - Second vector in distance calculation.
- //
- // Return: Distance between this and vec
- //
- // Purpose: Calculates the distance between the ends of the two vectors,
- // this and vec, assuming they are anchored at the origin (0, 0).
- //-------------------------------------------------------------------------
- public float DistanceTo(Vector3 vec)
- {
- return 0.0f;
- }
- //-------------------------------------------------------------------------
- // Fn: Distance
- //
- // Params:
- // Vector3 a - First vector in distance calculation.
- // Vector3 b - Second vector in distance calculation.
- //
- // Return: Distance between a and b
- //
- // Purpose: Calculates the distance between the ends of the two vectors,
- // a and b, assuming they are anchored at the origin (0, 0).
- //-------------------------------------------------------------------------
- public static float Distance(Vector3 a, Vector3 b)
- {
- return 0.0f;
- }
- //-------------------------------------------------------------------------
- // Fn: DistanceSquaredTo
- //
- // Params:
- // Vector3 vec - Second vector in distance calculation.
- //
- // Return: Squared distance between this and vec
- //
- // Purpose: Calculates the distance between the ends of the two vectors,
- // this and vec, assuming they are anchored at the origin (0, 0).
- //-------------------------------------------------------------------------
- public float DistanceSquaredTo(Vector3 vec)
- {
- return 0.0f;
- }
- //-------------------------------------------------------------------------
- // Fn: DistanceSquared
- //
- // Params:
- // Vector3 a - First vector in distance calculation.
- // Vector3 b - Second vector in distance calculation.
- //
- // Return: Squared distance between a and b
- //
- // Purpose: Calculates the distance between the ends of the two vectors,
- // a and b, assuming they are anchored at the origin (0, 0).
- //-------------------------------------------------------------------------
- public static float DistanceSquared(Vector3 a, Vector3 b)
- {
- return 0.0f;
- }
- //-------------------------------------------------------------------------
- // Fn: ProjectOnto
- //
- // Params:
- // Vector3 vec - Vector being projected onto
- //
- // Return: New vector object
- //
- // Purpose: Projects vector 'this' onto vector vec. Returns the vector
- // that results from this operation.
- //-------------------------------------------------------------------------
- public Vector3 ProjectOnto(Vector3 vec)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Fn: Project
- //
- // Params:
- // Vector3 a - Vector being projected
- // Vector3 b - Vector being projected onto
- //
- // Return: New vector object
- //
- // Purpose: Projects vector a onto vector b. Returns the vector
- // that results from this operation.
- //-------------------------------------------------------------------------
- public static Vector3 Project(Vector3 a, Vector3 b)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Fn: PerpendicularProjectOnto
- //
- // Params:
- // Vector3 vec - Vector being projected onto
- //
- // Return: New vector object
- //
- // Purpose: Projects vector 'this' onto vector vec. Returns the vector
- // that results from this operation.
- //-------------------------------------------------------------------------
- public Vector3 PerpendicularProjectOnto(Vector3 vec)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Fn: PerpendicularProject
- //
- // Params:
- // Vector3 a - Vector being projected
- // Vector3 b - Vector being projected onto
- //
- // Return: New vector object
- //
- // Purpose: Projects vector a onto vector b. Returns the vector
- // that results from this operation.
- //-------------------------------------------------------------------------
- public static Vector3 PerpendicularProject(Vector3 a, Vector3 b)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Fn: LerpTowards
- //
- // Params:
- // Vector3 vec - Vector being LERPed towards. Result at t = 1
- // float t - Time used for LERP operation.
- //
- // Return: New vector object
- //
- // Purpose: Runs the linear interpolation operation using vector this as a
- // starting point. Lerps towards vec at time t.
- //-------------------------------------------------------------------------
- public Vector3 LerpTowards(Vector3 vec, float t)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Fn: Lerp
- //
- // Params:
- // Vector3 a - Vector being LERPed from. Result at t = 0
- // Vector3 b - Vector being LERPed towards. Result at t = 1
- // float t - Time used for LERP operation.
- //
- // Return: New vector object
- //
- // Purpose: Runs the linear interpolation operation using vector a as a
- // starting point. Lerps towards b at time t.
- //-------------------------------------------------------------------------
- public static Vector3 Lerp(Vector3 a, Vector3 b, float t)
- {
- return new Vector3();
- }
- //-------------------------------------------------------------------------
- // Geometry
- //-------------------------------------------------------------------------
- }
- }
Add Comment
Please, Sign In to add comment