Ejemplo n.º 1
0
    /*
     * public class GraphPointInteraction : MonoBehaviour {
     *
     *   public WMG_Axis_Graph myGraph;
     *
     *  void MyCustomFunction(WMG_Series series, WMG_Node node) {
     *      Debug.Log("Node: " + node.name + " on series: " + series.name + " was clicked!");
     *     }
     *           void Start() {
     *     myGraph.WMG_Click += MyCustomFunction;
     *   }
     *
     *  }
     */
    // Update is called once per frame
    void Update()
    {
        if (dataLoaded)
        {
            if (Time.time >= nextActionTime)
            {
                Mopac  m       = mopacsList [mopacCounter];
                double seconds = m.secs * 1.0;// * timeMultiplier;
                //Debug.Log (mopacCounter + " time=" + m.secs + " mx=" + m.mx);
                if (mopacCounter == 0)
                {
                    previousSeconds = seconds;
                }
                float tDelta = (float)(seconds - previousSeconds);
                //Vector3 rot = new Vector3 (((m.rx * tDelta) * Mathf.Rad2Deg), ((m.rz * tDelta) * Mathf.Rad2Deg), ((m.ry * tDelta) * Mathf.Rad2Deg));
                //transform.Rotate (rot);
                //NOTE: z and y are switched
                targetAngle  = new Vector3((m.rx * Mathf.Rad2Deg), (m.rz * Mathf.Rad2Deg), (m.ry * Mathf.Rad2Deg));
                currentAngle = new Vector3(
                    Mathf.LerpAngle(currentAngle.x, targetAngle.x, tDelta),
                    Mathf.LerpAngle(currentAngle.z, targetAngle.z, tDelta),
                    Mathf.LerpAngle(currentAngle.y, targetAngle.y, tDelta));
                if (animateMooring)
                {
                    transform.eulerAngles = currentAngle;
                }

                Vector2 animateV2 = new Vector2(mopacCounter, m.ax);
                //graphOverTime.animateAddPointFromEnd(animateV2, tDelta);
                //  animateAddPointFromEnd

                String accelText = string.Format("aX={0,5:0.00} aY={1,5:0.00} aZ={2,5:0.00}", m.ax, m.ay, m.az);
                accelerationTextLocal.text = accelText;
                String rotText = string.Format("rX={0,5:0.00} rY={1,5:0.00} rZ={2,5:0.00}", m.rx * Mathf.Rad2Deg, m.ry * Mathf.Rad2Deg, m.rz * Mathf.Rad2Deg);
                rotationTextLocal.text = rotText;
                String magText = string.Format("mX={0,5:0.00} mY={1,5:0.00} mZ={2,5:0.00}", m.mx, m.my, m.mz);

                magnetTextLocal.text = seconds + " seconds";

                //previousSeconds = mopacsList[mopacCounter].secs;
                previousSeconds = seconds;
                mopacCounter++;
                if (mopacCounter > mopacsList.Count)
                {
                    mopacCounter        = 0;
                    initialAcceleration = Input.acceleration;
                    currentAcceleration = Vector3.zero;
                    dataLoaded          = false;             //for now we stop at the end.. want to know when that is.
                    Debug.Log("DONE DONE DONE DONE DONE DONE DONE DONE");
                }
                previousM = m;
                double s = mopacsList[mopacCounter].secs;
                nextActionTime = timeBegin + (s * 1.0); //*timeMultiplier;//*timeMultiplier);
            }
        }
    }
Ejemplo n.º 2
0
    private bool Load(string fileName)
    {
        Debug.Log("beginning Load...)");
        // Handle any problems that might arise when reading the text
        try
        {
            // Create a new StreamReader, tell it which file to read and what encoding the file
            // was saved as
            StreamReader theReader = new StreamReader(fileName, Encoding.Default);
            // Immediately clean up the reader after this block of code is done.
            // You generally use the "using" statement for potentially memory-intensive objects
            // instead of relying on garbage collection.
            // (Do not confuse this with the using directive for namespace at the
            // beginning of a class!)
            using (theReader)
            {
                var bytes = default(byte[]);
                Debug.Log("Opened!!!!!!  :)");
                using (var memstream = new MemoryStream())
                {
                    var buffer    = new byte[512];
                    var bytesRead = default(int);
                    while ((bytesRead = theReader.BaseStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        memstream.Write(buffer, 0, bytesRead);
                    }
                    bytes = memstream.ToArray();
                }

//				43 bytes defined as follows
//				Byte 1      Header = 0xCB
//				Bytes 2-5   AccelX
//				Bytes 6-9   AccelY
//				Bytes 10-13     AccelZ
//				Bytes 14-17     AngRateX
//				Bytes 18-21     AngRateY
//				Bytes 22-25     AngRateZ
//				Bytes 26-29     MagX
//				Bytes 30-33     MagY
//				Bytes 34-37     MagZ
//				Bytes 38-41     Timer
//				Bytes 42-43     Checksum

                for (int i = 0; i < bytes.Length; i = i + 43)
                {
                    byte[] axbytes = null;
                    axbytes    = new byte[4];
                    axbytes[0] = bytes[i + 4];
                    axbytes[1] = bytes[i + 3];
                    axbytes[2] = bytes[i + 2];
                    axbytes[3] = bytes[i + 1];

                    byte[] aybytes = null;
                    aybytes    = new byte[4];
                    aybytes[0] = bytes[i + 8];
                    aybytes[1] = bytes[i + 7];
                    aybytes[2] = bytes[i + 6];
                    aybytes[3] = bytes[i + 5];

                    byte[] azbytes = null;
                    azbytes    = new byte[4];
                    azbytes[0] = bytes[i + 12];
                    azbytes[1] = bytes[i + 11];
                    azbytes[2] = bytes[i + 10];
                    azbytes[3] = bytes[i + 9];

                    byte[] rxbytes = null;
                    rxbytes    = new byte[4];
                    rxbytes[0] = bytes[i + 16];
                    rxbytes[1] = bytes[i + 15];
                    rxbytes[2] = bytes[i + 14];
                    rxbytes[3] = bytes[i + 13];

                    byte[] rybytes = null;
                    rybytes    = new byte[4];
                    rybytes[0] = bytes[i + 20];
                    rybytes[1] = bytes[i + 19];
                    rybytes[2] = bytes[i + 18];
                    rybytes[3] = bytes[i + 17];

                    byte[] rzbytes = null;
                    rzbytes    = new byte[4];
                    rzbytes[0] = bytes[i + 24];
                    rzbytes[1] = bytes[i + 23];
                    rzbytes[2] = bytes[i + 22];
                    rzbytes[3] = bytes[i + 21];

                    byte[] mxbytes = null;
                    mxbytes    = new byte[4];
                    mxbytes[0] = bytes[i + 28];
                    mxbytes[1] = bytes[i + 27];
                    mxbytes[2] = bytes[i + 26];
                    mxbytes[3] = bytes[i + 25];

                    byte[] mybytes = null;
                    mybytes    = new byte[4];
                    mybytes[0] = bytes[i + 32];
                    mybytes[1] = bytes[i + 31];
                    mybytes[2] = bytes[i + 30];
                    mybytes[3] = bytes[i + 29];

                    byte[] mzbytes = null;
                    mzbytes    = new byte[4];
                    mzbytes[0] = bytes[i + 36];
                    mzbytes[1] = bytes[i + 35];
                    mzbytes[2] = bytes[i + 34];
                    mzbytes[3] = bytes[i + 33];

                    byte[] tbytes = null;
                    tbytes    = new byte[4];
                    tbytes[0] = bytes[i + 40];
                    tbytes[1] = bytes[i + 39];
                    tbytes[2] = bytes[i + 38];
                    tbytes[3] = bytes[i + 37];


                    float  accelX   = BitConverter.ToSingle(axbytes, 0);
                    float  accelY   = BitConverter.ToSingle(aybytes, 0);
                    float  accelZ   = BitConverter.ToSingle(azbytes, 0);
                    float  rotX     = BitConverter.ToSingle(rxbytes, 0);
                    float  rotY     = BitConverter.ToSingle(rybytes, 0);
                    float  rotZ     = BitConverter.ToSingle(rzbytes, 0);
                    float  magX     = BitConverter.ToSingle(mxbytes, 0);
                    float  magY     = BitConverter.ToSingle(mybytes, 0);
                    float  magZ     = BitConverter.ToSingle(mzbytes, 0);
                    uint   t        = BitConverter.ToUInt32(tbytes, 0);
                    double tseconds = t / 62500.0;
                    //Byte b = bytes[i+0];
                    if (i < 1000)
                    {
                        Debug.Log(i + " " + " aX=" + accelX + " aY=" + accelY + " aZ=" + accelZ + " rx=" + rotX + " ry=" + rotY + " rz=" + rotZ + " mx=" + magX + " my=" + magY + " mz=" + magZ + " t=" + tseconds);
                    }
                    Mopac mpac = new Mopac(accelX, accelY, accelZ, rotX, rotY, rotZ, magX, magY, magZ, tseconds);
                    mopacsList.Add(mpac);
                }
                // Done reading, close the reader and return true to broadcast success
                theReader.Close();
                Debug.Log("total mopacs: " + mopacsList.Count);
                if (mopacsList.Count > 1)
                {
                    dataLoaded = true;
                    timeBegin  = Time.time;
                    Debug.Log("dataLoaded = true.. ");
                }
                return(true);
            }
        }
        // If anything broke in the try block, we throw an exception with information
        // on what didn't work
        catch (Exception e)
        {
            Debug.Log("failed to open..");
            Console.WriteLine("{0}\n", e.Message);
            return(false);
        }
    }