Chaotic Motion  1.0
BoundStats.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 
14 public class BoundStats : MonoBehaviour {
15 
16  public float log_interval = 15;
18  public float desired_size = 10;
19  private float[] minP;
20  private float[] maxP;
21 
22  private float last_log;
23 
24  // Use this for initialization
25  void Start () {
26  Reset();
27  last_log = Time.time;
28  }
29 
30  private void Reset () {
31  minP = new float[]{ float.MaxValue, float.MaxValue, float.MaxValue};
32  maxP = new float[]{ float.MinValue, float.MinValue, float.MinValue};
33  last_log = Time.time;
34  }
35 
36  // Update is called once per frame
37  void Update () {
38  Vector3 p = transform.position;
39  minP[0] = Mathf.Min( minP[0], p.x);
40  minP[1] = Mathf.Min( minP[1], p.y);
41  minP[2] = Mathf.Min( minP[2], p.z);
42  maxP[0] = Mathf.Max( maxP[0], p.x);
43  maxP[1] = Mathf.Max( maxP[1], p.y);
44  maxP[2] = Mathf.Max( maxP[2], p.z);
45 
46  if ((Time.time - last_log) > log_interval) {
47  last_log = Time.time;
48  Debug.Log(string.Format(" x=({0:000.0},{1:000.0}) y=({2:000.0},{3:000.0}) z=({4:000.0},{5:000.0})",
49  minP[0], maxP[0],
50  minP[1], maxP[1],
51  minP[2], maxP[2]
52  ));
53  // Determine the offset and global scale for a canonical form
54  float midX = (maxP[0] + minP[0])/2f;
55  float midY = (maxP[1] + minP[1])/2f;
56  float midZ = (maxP[2] + minP[2])/2f;
57  float maxExtent = Mathf.Max((maxP[0] - minP[0]), (maxP[1] - minP[1]));
58  maxExtent = Mathf.Max(maxExtent, (maxP[2] - minP[2]));
59  // desired_Scale = maxEtent * scale, so
60  float scale = desired_size/maxExtent;
61  Debug.Log(string.Format("offset/scale = Vector3({0:00.0}f,{1:00.0}f,{2:00.0}f), {3:0.00}f",
62  -midX, -midY, -midZ, scale
63  ));
64  // this allows early initial position to get discarded.
65  Reset();
66  }
67 
68  }
69 }
Bound stats. Simple method to track min/max in each co-ordinate to determine the extent of an attract...
Definition: BoundStats.cs:14
float desired_size
Size of the bounding box into which system should fit.
Definition: BoundStats.cs:18