public void initialize(int _overSampling, int _vecHeight, int _wallRadius, Texture2D _levelImage) { overSampling = _overSampling; vecHeight = _vecHeight; wallRadius = _wallRadius; levelImage = _levelImage; Debug.Log("Starting to Initialize?"); //first we create the actual vecot field class; myVectorField = new vectorField(_levelImage.width, _levelImage.height, _overSampling, _vecHeight, _wallRadius); //now we need to add the walls vectorFHelper newVFHelper = new vectorFHelper(myVectorField, _wallRadius, _vecHeight, _overSampling, levelImage.width * _overSampling, levelImage.height * _overSampling); for (int x = 0; x < levelImage.width; x++) { for (int z = 0; z < levelImage.height; z++) { if (levelImage.GetPixel(x, z) == Color.black) { myVectorField.addWIC(x, z, newVFHelper); } } } newVFHelper.start(); while (newVFHelper.getInCommingWallCount() > 0) { ; } myVectorField.storeValues(); newVFHelper.stop(); Debug.Log("During runtime wall Count" + myVectorField.wallMem.Count); }
void Start() { //Keyframe[] ks = new Keyframe[2]; //ks[0]= new Keyframe(0,0); //ks[1]= new Keyframe(1.0f,1.0f); //avoidance = new AnimationCurve(ks); //targetDirection = new Vector3 (Random.Range (-1.0f, 1.0f), 0, Random.Range (-1.0f, 1.0f)).normalized; //newTargetDirection = new Vector3 (Random.Range (-1.0f, 1.0f), 0, Random.Range (-1.0f, 1.0f)).normalized; floor = GameObject.Find("Floor").transform.GetComponent <vectorField> (); }
public vectorFHelper(vectorField host_, float wallRadius_, float vecHeight_, int overSampling_, int maxX_, int maxZ_) { maxX = maxX_; maxZ = maxZ_; host = host_; wallRadius = wallRadius_; vecHeight = vecHeight_; overSampling = overSampling_; //Debug.Log("max x is: " + maxX + " max z is: " + maxZ); //recalcThread2 = new Thread(new ThreadStart(calcVectorField)); //arecalcThread2.Start(); }
public void assignData(levelStorage loadedStorage_) { loadedStorage = loadedStorage_; myVectorField = loadedStorage.myVectorField; gates = loadedStorage.gates; myVectorField.loadValues(); int wallCount = myVectorField.wallMem.Count; int minimumX = 0; int minimumZ = 0; int maximumX = 0; int maximumZ = 0; int wallID = 0; int emergencyCounter = 0; Vector2Int[] wallMemory; Vector2Int[] toBeDeleted while (wallCount > 0) { emergencyCounter++; Debug.Log("This wallId should go nothing but up and jump in between" + wallID); if (wallID < myVectorField.wallMem.Count) { minimumX = Mathf.RoundToInt(myVectorField.wallMem[wallID].x); minimumZ = Mathf.RoundToInt(myVectorField.wallMem[wallID].y); maximumX = minimumX; maximumZ = minimumZ; } else { Debug.Log("Breaking since we are moving out of the bounds"); break; } int targetX = minimumX; bool firstRun = true; bool borderFound = false; while (myVectorField.wallMem.Contains(new Vector2(targetX, maximumZ))) { while (myVectorField.wallMem.Contains(new Vector2(targetX, maximumZ))) { //Debug.Log("TargetX" + targetX + "maximumZ" + maximumZ); targetX++; if (!firstRun && targetX >= maximumX) { borderFound = true; break; } } if (firstRun) { firstRun = false; maximumX = targetX - 1; targetX = minimumX; } else if (borderFound) { borderFound = false; targetX = minimumX; maximumZ++; } else { break; } } Debug.Log("Blub new wall..." + maximumX + " z: " + maximumZ); //maximumX--; maximumZ--; Debug.Log("Wall Id retrieved from the last wall" + myVectorField.wallMem.FindIndex(v => maximumX == v.x && maximumZ == v.y)); wallID = myVectorField.wallMem.IndexOf(new Vector2(maximumX, maximumZ)); wallID++; GameObject newWall = GameObject.CreatePrimitive(PrimitiveType.Cube) as GameObject; newWall.transform.localScale = new Vector3(maximumX - minimumX, 2, maximumZ - minimumZ) / myVectorField.overSampling; newWall.transform.position = myVectorField.aSTWS((minimumX + (maximumX / 2)), (minimumZ + (maximumZ / 2)), transform.GetChild(0).gameObject); if (emergencyCounter > myVectorField.wallMem.Count) { Debug.Log("Pulling the emergency break this should not happen"); break; } } }