/// <summary> /// Create a matrix given 4 vectors /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> /// <param name="v3"></param> /// <param name="v4"></param> public ASMATRIX4(ASVECTOR4 v1, ASVECTOR4 v2, ASVECTOR4 v3, ASVECTOR4 v4) { Matrix[0] = v1; Matrix[1] = v2; Matrix[2] = v3; Matrix[3] = v4; }
/// <summary> /// Builds an identity matrix and returns it to the caller /// </summary> /// <returns></returns> public void CreateIdentityMatrix() { Matrix[0] = new ASVECTOR4(1, 0, 0, 0); Matrix[1] = new ASVECTOR4(0, 1, 0, 0); Matrix[2] = new ASVECTOR4(0, 0, 1, 0); Matrix[3] = new ASVECTOR4(0, 0, 0, 1); }
/// <summary> /// Empty constructor to initialise the points structure to be all 0 /// </summary> public ASFace() { for (var i = 0; i < 3; i++) { m_points[i] = new ASVECTOR4(); } }
/// <summary> /// Initialise a new vector with a vector /// </summary> /// <param name="vec"></param> public ASVECTOR4(ASVECTOR4 vec) { Points[0] = vec.Points[0]; Points[1] = vec.Points[1]; Points[2] = vec.Points[2]; Points[3] = vec.Points[3]; }
// OPERATOR OVERLOADS /// <summary> /// Minus the components of vector A from vector B to get edge 3 /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> /// <returns></returns> public static ASVECTOR4 operator -(ASVECTOR4 v1, ASVECTOR4 v2) { var newVec = new ASVECTOR4(v1.Points[0] - v2.Points[0], v1.Points[1] - v2.Points[1], v1.Points[2] - v2.Points[2]); return(newVec); }
/// <summary> /// Rescales the point to a valid unit so we can draw it to the screen /// </summary> /// <returns></returns> public ASVECTOR4 Rescale() { var newPoint = new ASVECTOR4(); for (var i = 0; i < 4; i++) { newPoint.Points[i] = Points[i] / Points[3]; } return(newPoint); }
/// <summary> /// Computes the normals for this face, these will be stored as /// U, X, V in the vector, the W parameter will be 1 as we don't /// have a ASVECTOR3 object (no need for it when we can just use VEC4) /// </summary> /// <returns></returns> public ASVECTOR4 ComputeFaceNormals() { // Get the UV edges of our triangle, we can then calculate the face // normals from these values. var vecA = new ASVECTOR4(); vecA.Points[0] = m_points[0].Points[0] - m_points[1].Points[0]; vecA.Points[1] = m_points[0].Points[1] - m_points[1].Points[1]; vecA.Points[2] = m_points[0].Points[2] - m_points[1].Points[2]; var vecB = new ASVECTOR4(); vecB.Points[0] = m_points[1].Points[0] - m_points[2].Points[0]; vecB.Points[1] = m_points[1].Points[1] - m_points[2].Points[1]; vecB.Points[2] = m_points[1].Points[2] - m_points[2].Points[2]; // Get the cross product of the two vectors var norm = (vecA * vecB).Normalise(); // Normalise the vector to get the unit lenght return(norm); }
/// <summary> /// Creates a new ASFace array object to hold each point /// </summary> /// <param name="pointA"></param> /// <param name="pointB"></param> /// <param name="pointC"></param> public ASFace(ASVECTOR4 pointA, ASVECTOR4 pointB, ASVECTOR4 pointC) { m_points[0] = pointA; m_points[1] = pointB; m_points[2] = pointC; }
/// <summary> /// Returns the product of vector A and B /// </summary> /// <param name="v"></param> /// <returns></returns> public double ScalarProduct(ASVECTOR4 v) { return(Points[0] * v.Points[0] + Points[1] * v.Points[1] + Points[2] * v.Points[2]); }
/// <summary> /// Multiplies the x,y,z components of vectors together /// </summary> /// <param name="vecB"></param> public void MultiplyVector(ASVECTOR4 vecB) { Points[0] *= vecB.Points[0]; Points[1] *= vecB.Points[1]; Points[2] *= vecB.Points[2]; }
/// <summary> /// Divides the x,y,z components of two vectors by eachother /// </summary> /// <param name="vecB"></param> public void DivideVector(ASVECTOR4 vecB) { Points[0] /= vecB.Points[0]; Points[1] /= vecB.Points[1]; Points[2] /= vecB.Points[2]; }
/// <summary> /// Substracts the x,y,z components of two vectors from one another /// </summary> /// <param name="vecB"></param> public void MinusFromVector(ASVECTOR4 vecB) { Points[0] -= vecB.Points[0]; Points[1] -= vecB.Points[1]; Points[2] -= vecB.Points[2]; }
/// <summary> /// Adds the x,y,z components of two vectors together /// </summary> /// <param name="vecB"></param> public void AddToVector(ASVECTOR4 vecB) { Points[0] += vecB.Points[0]; Points[1] += vecB.Points[1]; Points[2] += vecB.Points[2]; }