using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Linq;

public class Camera_SfM : MonoBehaviour
{

    public float scale_factor = 1.0f;

    public Transform endoscopic_transform;
    public Transform light_transform;

    static UdpClient udp;

    // Use this for initialization
    void Start()
    {
        int LOCAL_PORT = 50007;

        udp = new UdpClient(LOCAL_PORT);
        udp.Client.ReceiveTimeout = 1000;
    }

    // Update is called once per frame
    void Update()
    {

        IPEndPoint remoteEP = null;

        try
        {
            byte[] data = udp.Receive(ref remoteEP);
            string text = Encoding.UTF8.GetString(data);
            Debug.Log(text);
            string[] pose_arr = text.Split(',');
            List<float> pose_list = pose_arr.Select(x => float.Parse(x)).ToList();

            endoscopic_transform.Translate(new Vector3(scale_factor * pose_list[0], scale_factor * pose_list[1], scale_factor * pose_list[2]));
            endoscopic_transform.Rotate(new Vector3(pose_list[3], pose_list[4], pose_list[5]));
            light_transform.position = endoscopic_transform.position;
        }
        catch
        {

        }

    }
}
