/// <summary> /// Creates the vector field arrows and move them to the right position depending on the resolution. /// </summary> private void createVectorFieldArrows() { float arrow_scale; if (resolution > 20) { arrow_scale = 1 - (resolution - 20) * 0.05f; } else { arrow_scale = 1 + (20 - resolution) * 0.05f; } for (int i = 0; i < resolution; i++) { for (int j = 0; j < resolution; j++) { float x = -width / 2 + (width / resolution) * (0.5f + i); float y = -height / 2 + (height / resolution) * (0.5f + j); GameObject arrow = Instantiate(arrowPrefab) as GameObject; arrow.GetComponent <ArrowController>().fieldStrengthFactor = this.fieldStrengthFactor; arrow.transform.localScale = Vector3.Scale(new Vector3(arrow_scale, arrow_scale, arrow_scale), transform.localScale) / 3; arrow.transform.parent = transform; //set vectorField as parent arrow.transform.localPosition = new Vector3(x, 0, y); simController.AddNewResetObject(arrow.GetComponent <IResetObject>()); vectorFieldArrows.Add(arrow); } } }
/// <summary> /// Stops the simulations and generate the field image by drawing random irons. /// </summary> public void generateFieldImage() { if (field == null) { return; } simController.StopSimulation(); simController.AddNewResetObject(this); Debug.Log("Start IronFiling"); for (int i = 0; i < iterations * 2; i++) { Vector3 origin = new Vector3(Random.Range(-1f, 1f) * width / 2, 0, Random.Range(-1f, 1f) * height / 2); drawIron(origin, linerenderers[i]); } Debug.Log("End IronFiling"); gameObject.SetActive(true); }