Ejemplo n.º 1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //transform.position += Vector3.up * 10.0f;
        trans = SimulateCamera(msg);

        if (msg != null && msg != "" && trans != null)
        {
            transform.position = trans.t;
            //transform.rotation = Quaternion.Euler(trans.r);
            //transform.rotation = Quaternion.LookRotation(-(trans.t) - center.position, Vector3.up);
            if (pov)
            {
                center.rotation = Quaternion.Euler(trans.r * -1);
            }
        }

        if (projection)
        {
            UpdateProjection();
        }
        else
        {
            CustomProjection();
        }
    }
Ejemplo n.º 2
0
    public TCPtrans SimulateCamera(string json)
    {
        var regex = new Regex(@"\{(.*?)\}");

        TCPmsg   msg  = new TCPmsg();
        TCPtrans rMsg = new TCPtrans();

        try {
            Match m = regex.Match(json);
            msg = JsonUtility.FromJson <TCPmsg>(m.Value);

            rMsg.t = new Vector3(
                float.Parse(msg.tx, CultureInfo.InvariantCulture.NumberFormat),
                float.Parse(msg.ty, CultureInfo.InvariantCulture.NumberFormat),
                float.Parse(msg.tz, CultureInfo.InvariantCulture.NumberFormat)
                );
            rMsg.t += new Vector3(0f, 0f, -1f);

            rMsg.r = new Vector3(
                float.Parse(msg.rx, CultureInfo.InvariantCulture.NumberFormat),
                float.Parse(msg.ry, CultureInfo.InvariantCulture.NumberFormat),
                float.Parse(msg.rz, CultureInfo.InvariantCulture.NumberFormat)
                );

            //rMsg.r = Vector3.Lerp(transform.eulerAngles, rMsg.r, 0.5f);
            rMsg.reset = msg.reset == "true" ? true : false;
            //calculate
            float curr = Time.time;
            if (curr - lastMessage > 0f)
            {
                Debug.Log(curr - lastMessage);
            }
            lastMessage = curr;
            return(rMsg);
        } catch {
            return(null);
        }
    }