public bool updatePhysics(float elapsed) { // get the object position mPos.x = transform.position.x; mPos.y = transform.position.y; //------------------------------------------- //Stores the displacement in a vector HVector2D displacement = mVel * elapsed; //Creates a new Matrix HMatrix2D transMatrix = new HMatrix2D(); //Set the translation matrix with displacement values transMatrix.setTranslationMat(displacement.x, displacement.y); //Updates original vector pos with translation matrix mPos = transMatrix * mPos; //Adds friction physics to the Velocity, so the ball slows down. mVel = mVel * GlobalVariable.PHYSICS_FRICTION; //----------------------------------------------- tempPos.x = mPos.x; tempPos.y = mPos.y; transform.position = tempPos; //transform.position = new Vector2(transform.position.x + mVel.x, transform.position.y + mVel.y); return(true); }
public HMatrix2D transpose() { //Flips the Matrix HMatrix2D transpose = new HMatrix2D(entries[0, 0], entries[1, 0], entries[2, 0], entries[0, 1], entries[1, 1], entries[2, 1], entries[0, 2], entries[1, 2], entries[2, 2]); return(transpose); }
public static HMatrix2D operator *(HMatrix2D a, float b) { HMatrix2D result = new HMatrix2D(); for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { result.entries[row, col] = a.entries[row, col] * b; } } return(result); }
public HMatrix2D transpose() { HMatrix2D result = new HMatrix2D(); for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { result.entries[row, col] = result.entries[col, row]; } } return(result); }
public static HMatrix2D operator +(HMatrix2D a, HMatrix2D b) { HMatrix2D result = new HMatrix2D(); for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { //Adds the numbers on the corresponding positions on matrix a and b, then pushes it onto result result.entries[row, col] = a.entries[row, col] + b.entries[row, col]; } } return(result); }
public static HMatrix2D operator *(HMatrix2D a, float b) { HMatrix2D result = new HMatrix2D(); for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { //Multiplies matrix a with scalar b //and pushes the result onto the corresponding position on result result.entries[row, col] = a.entries[row, col] * b; } } return(result); }
public static HMatrix2D operator *(HMatrix2D a, HMatrix2D right) { HMatrix2D result = new HMatrix2D(); for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { result.entries[row, col] = 0; for (int i = 0; i < 3; i++) { result.entries[row, col] = result.entries[row, col] + a.entries[row, i] * right.entries[i, col]; } } } return(result); }
// Update is called once per frame void Update() { HVector2D vA = new HVector2D(); vA.x = 1; vA.y = 2; HVector2D vB = new HVector2D(5, 7); HVector2D vSum = vA + vB; float dp = vA.dotProduct(vB); HVector2D mPos = new HVector2D(10, 10); HVector2D displacement = new HVector2D(3, 4); HMatrix2D translationMatrix = new HMatrix2D(); translationMatrix.setTranslationMat(displacement.x, displacement.y); mPos = translationMatrix * mPos; }
public static HMatrix2D operator *(HMatrix2D a, HMatrix2D right) { HMatrix2D result = new HMatrix2D(); //Cycles thru the row of Matrix a for (int a_row = 0; a_row < 3; a_row++) { //cycles thru the row of Matrix right for (int right_col = 0; right_col < 3; right_col++) { float val = 0; //Cycles thru col of matrix a and thru row of matrix right for (int i = 0; i < 3; i++) { val += a.entries[a_row, i] * right.entries[i, right_col]; } result.entries[a_row, right_col] = val; } } return(result); }