//determine which echo to call public echoDistData getEchoDistData(Vector3 playerPos, Vector3 playerFront, Vector3 playerLeft) { float threshhold = 0.01f; int player_y_idx = 0, player_x_idx = 0; //get which index of gridPos() player is in for (int i = 1; i <= rows; i++) { for (int j = 1; j <= columns; ++j) { if ((gridPositions [i * (columns + 2) + j] - playerPos).magnitude <= threshhold) { player_y_idx = i; player_x_idx = j; //UnityEngine.Debug.Log ("idx is"); //UnityEngine.Debug.Log (new Vector2 (j, i)); break; } } } //setup the return value echoDistData result = new echoDistData(); Vector2 gridIdx = new Vector2(player_x_idx, player_y_idx); Vector2 gridTemp; gridTemp = _getDist(gridIdx, playerFront); result.front = (int)(gridTemp - gridIdx).magnitude; result.fType = getJunctionType(gridTemp - new Vector2(playerFront.x, playerFront.y), gridIdx); gridTemp = _getDist(gridIdx, -playerFront); result.back = (int)(gridTemp - gridIdx).magnitude; result.bType = getJunctionType(gridTemp + new Vector2(playerFront.x, playerFront.y), gridIdx); //_debug_print_wallidx (); //print ("LEFT!"); gridTemp = _getDist(gridIdx, playerLeft); result.left = (int)(gridTemp - gridIdx).magnitude; result.lType = getJunctionType(gridTemp - new Vector2(playerLeft.x, playerLeft.y), gridIdx); gridTemp = _getDist(gridIdx, -playerLeft); result.right = (int)(gridTemp - gridIdx).magnitude; result.rType = getJunctionType(gridTemp + new Vector2(playerLeft.x, playerLeft.y), gridIdx); return(result); }
//determine which echo to call public echoDistData getEchoDistData(Vector3 playerPos, Vector3 playerFront, Vector3 playerLeft) { //setup the return value echoDistData result = new echoDistData(); Vector2 gridIdx = get_idx_from_pos(playerPos); Vector2 gridTemp; Vector2 exitIdx = get_idx_from_pos(exitPos); bool check_exit = true; result.exitpos = 0; gridTemp = _getDist(gridIdx, playerFront); result.front = (int)(gridTemp - gridIdx).magnitude; result.fType = getJunctionType(gridTemp - new Vector2(playerFront.x, playerFront.y), gridIdx); //0: no exit, 1:left, 2:right, 3:front, 4:back if (check_exit) { Vector2 searchIdx = gridIdx; while ((searchIdx.x > 0) && (searchIdx.x < columns + 1) && (searchIdx.y > 0) && (searchIdx.y < rows + 1)) { if ((_idx_is_equal(searchIdx, exitIdx)) && ((int)(searchIdx - gridIdx).magnitude) <= result.front) { result.exitpos = 3; check_exit = false; break; } else { searchIdx += new Vector2(playerFront.x, playerFront.y); } } } gridTemp = _getDist(gridIdx, -playerFront); result.back = (int)(gridTemp - gridIdx).magnitude; result.bType = getJunctionType(gridTemp + new Vector2(playerFront.x, playerFront.y), gridIdx); if (check_exit) { Vector2 searchIdx = gridIdx; while ((searchIdx.x > 0) && (searchIdx.x < columns + 1) && (searchIdx.y > 0) && (searchIdx.y < rows + 1)) { if ((_idx_is_equal(searchIdx, exitIdx)) && ((int)(searchIdx - gridIdx).magnitude) <= result.back) { result.exitpos = 4; check_exit = false; break; } else { searchIdx -= new Vector2(playerFront.x, playerFront.y); } } } //_debug_print_wallidx (); //print ("LEFT!"); gridTemp = _getDist(gridIdx, playerLeft); result.left = (int)(gridTemp - gridIdx).magnitude; result.lType = getJunctionType(gridTemp - new Vector2(playerLeft.x, playerLeft.y), gridIdx); if (check_exit) { Vector2 searchIdx = gridIdx; while ((searchIdx.x > 0) && (searchIdx.x < columns + 1) && (searchIdx.y > 0) && (searchIdx.y < rows + 1)) { if ((_idx_is_equal(searchIdx, exitIdx)) && ((int)(searchIdx - gridIdx).magnitude) <= result.left) { result.exitpos = 1; check_exit = false; break; } else { searchIdx += new Vector2(playerLeft.x, playerLeft.y); } } } gridTemp = _getDist(gridIdx, -playerLeft); result.right = (int)(gridTemp - gridIdx).magnitude; result.rType = getJunctionType(gridTemp + new Vector2(playerLeft.x, playerLeft.y), gridIdx); if (check_exit) { Vector2 searchIdx = gridIdx; while ((searchIdx.x > 0) && (searchIdx.x < columns + 1) && (searchIdx.y > 0) && (searchIdx.y < rows + 1)) { if ((_idx_is_equal(searchIdx, exitIdx)) && ((int)(searchIdx - gridIdx).magnitude) <= result.right) { result.exitpos = 2; check_exit = false; break; } else { searchIdx -= new Vector2(playerLeft.x, playerLeft.y); } } } result.updateDistances(); return(result); }