// ****************************************************************************************** // ****************************************************************************************** // ****************************************************************************************** // FIELD SOLVING FUNCTIONS // ****************************************************************************************** private void computeDensityField(CC_Unit cc_u) { Vector2[] cc_u_pos = cc_u.getPositions(); for (int i = 0; i < cc_u_pos.Length; i++) { int xInd = (int)Math.Floor((double)cc_u_pos[i].x); int yInd = (int)Math.Floor((double)cc_u_pos[i].y); float[,] rho = linear1stOrderSplat(cc_u_pos[i].x, cc_u_pos[i].y, CCvals.rho_sc); if (isPointValid(xInd, yInd)) { float rt = readDataFromPoint_rho(xInd, yInd); writeDataToPoint_rho(xInd, yInd, rt + rho [0, 0]); } if (isPointValid(xInd + 1, yInd)) { float rt = readDataFromPoint_rho(xInd + 1, yInd); writeDataToPoint_rho(xInd + 1, yInd, rt + rho [1, 0]); } if (isPointValid(xInd, yInd + 1)) { float rt = readDataFromPoint_rho(xInd, yInd + 1); writeDataToPoint_rho(xInd, yInd + 1, rt + rho [0, 1]); } if (isPointValid(xInd + 1, yInd + 1)) { float rt = readDataFromPoint_rho(xInd + 1, yInd + 1); writeDataToPoint_rho(xInd + 1, yInd + 1, rt + rho [1, 1]); } computeVelocityFieldPoint(xInd, yInd, cc_u.getVelocity()); computeVelocityFieldPoint(xInd + 1, yInd, cc_u.getVelocity()); computeVelocityFieldPoint(xInd, yInd + 1, cc_u.getVelocity()); computeVelocityFieldPoint(xInd + 1, yInd + 1, cc_u.getVelocity()); } }
private void applyPredictiveDiscomfort(float numSec, CC_Unit cc_u) { Vector2 newLoc; float sc; Vector2[] cc_u_pos = cc_u.getPositions(); for (int k = 0; k < cc_u_pos.Length; k++) { Vector2 xprime = cc_u_pos[k] + cc_u.getVelocity() * numSec; float vfMag = Vector2.Distance(cc_u_pos[k], xprime); for (int i = 5; i < vfMag; i++) { newLoc = Vector2.MoveTowards(cc_u_pos[k], xprime, i); sc = (vfMag - i) / vfMag; // inverse scale float[,] gP = linear1stOrderSplat(newLoc, sc * CCvals.gP_weight); int xInd = (int)Math.Floor((double)newLoc.x); int yInd = (int)Math.Floor((double)newLoc.y); if (isPointValid(xInd, yInd)) { float gPt = readDataFromPoint_gP(xInd, yInd); writeDataToPoint_gP(xInd, yInd, gPt + gP [0, 0]); } if (isPointValid(xInd + 1, yInd)) { float gPt = readDataFromPoint_gP(xInd + 1, yInd); writeDataToPoint_gP(xInd + 1, yInd, gPt + gP [1, 0]); } if (isPointValid(xInd, yInd + 1)) { float gPt = readDataFromPoint_gP(xInd, yInd + 1); writeDataToPoint_gP(xInd, yInd + 1, gPt + gP [0, 1]); } if (isPointValid(xInd + 1, yInd + 1)) { float gPt = readDataFromPoint_gP(xInd + 1, yInd + 1); writeDataToPoint_gP(xInd + 1, yInd + 1, gPt + gP [1, 1]); } } } }