Beispiel #1
0
    //https://blog.nobel-joergensen.com/2010/10/22/spherical-coordinates-in-unity/
    public static void SphericalToCartesian(Spherical3 sphereCoords, out Vector3 outCart)
    {
        float a = sphereCoords.r * Mathf.Cos(sphereCoords.e);

        outCart.x = a * Mathf.Cos(sphereCoords.p);
        outCart.y = sphereCoords.r * Mathf.Sin(sphereCoords.e);
        outCart.z = a * Mathf.Sin(sphereCoords.p);
    }
Beispiel #2
0
 public void StartRecord()
 {
     mytrail.Clear();
     startPos = transform.position;
     startSph = new Spherical3();
     SphereUtility.CartesianToSpherical(startPos - origin.transform.position, out startSph);
     mytrail.Push(startSph);
     StartCoroutine("Recording");
 }
Beispiel #3
0
    public static Spherical3 Rotate(Spherical3 inS, float deltaRad)
    {
        Spherical3 m = new Spherical3();

        m.r = inS.r;
        m.p = inS.p + deltaRad;
        m.e = inS.e;
        return(m);
    }
Beispiel #4
0
    public static Spherical3 Mirror(Spherical3 inS)
    {
        Spherical3 m = new Spherical3();

        m.r = inS.r;
        m.p = -inS.p;
        m.e = inS.e;
        return(m);
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        Spherical3 sc = new Spherical3();

        Vector3 where = toTrack.transform.position - origin.transform.position;
        SphereUtility.CartesianToSpherical(where, out sc);

        // reflecting
        sc.p *= -1;

        Vector3 nwhere = new Vector3();

        SphereUtility.SphericalToCartesian(sc, out nwhere);

        transform.position = startPos + nwhere;
    }
Beispiel #6
0
 public static void CartesianToSpherical(Vector3 cartCoords, out Spherical3 sphereCoords)
 {
     if (cartCoords.x == 0)
     {
         cartCoords.x = Mathf.Epsilon;
     }
     sphereCoords.r = Mathf.Sqrt((cartCoords.x * cartCoords.x)
                                 + (cartCoords.y * cartCoords.y)
                                 + (cartCoords.z * cartCoords.z));
     sphereCoords.p = Mathf.Atan(cartCoords.z / cartCoords.x);
     if (cartCoords.x < 0)
     {
         sphereCoords.p += Mathf.PI;
     }
     sphereCoords.e = Mathf.Asin(cartCoords.y / sphereCoords.r);
 }
Beispiel #7
0
 // Use this for initialization
 void Start()
 {
     mytrail = new Stack <Spherical3>();
     sc      = new Spherical3();
 }