private void SetupTouch()
        {
            var uit_            = GetComponent <UITouch>();
            var BodyPortraitSR_ = Body_.GetComponent <UIAugmentedFaceBody>().ScrollViewFacesObj_.GetComponent <ScrollRect>();

            uit_.BeginDrag += (e_) => { BodyPortraitSR_.OnBeginDrag(e_); };
            uit_.Drag      += (e_) => { BodyPortraitSR_.OnDrag(e_); };
            uit_.EndDrag   += (e_) => { BodyPortraitSR_.OnEndDrag(e_); };

            uit_.OneEndDrag += (pos_, dir_, mag_, cardDir_) =>
            {
                if (cardDir_ == UIDragDirection.Up)
                {
                    var WorkerAFW_ = Worker_.GetComponent <AugmentedFaceWorker>();
                    WorkerAFW_.SetFace(FaceInfo_);
                }

                if (cardDir_ == UIDragDirection.Down)
                {
                    //#if UNITY_EDITOR
                    //					DestroyImmediate(gameObject);
                    //#else
                    //					Destroy(gameObject);
                    //#endif
                    //					Directory.Delete(FaceInfo_.FolderPath_, true);

                    var WorkerAFW_ = Worker_.GetComponent <AugmentedFaceWorker>();
                    WorkerAFW_.SetFace(null);
                }
            };
        }
Exemple #2
0
        DiscreteStep(int Action_)
        {
            base.DiscreteStep(Action_);

            switch (Action_)
            {
            case TurnRight:
                Head.transform.eulerAngles = new Vector3(Head.transform.eulerAngles.x,
                                                         Head.transform.eulerAngles.y + TurnSpeed * DeltTimeAgentStep,
                                                         Head.transform.eulerAngles.z);
                break;

            case TurnLeft:
                Head.transform.eulerAngles = new Vector3(Head.transform.eulerAngles.x,
                                                         Head.transform.eulerAngles.y - TurnSpeed * DeltTimeAgentStep,
                                                         Head.transform.eulerAngles.z);
                break;

            default:
                break;
            }

            // keep moving forward
            Head.transform.position += Head.transform.forward * MovementSpeed * DeltTimeAgentStep;

            // update the movement of the bodies
            foreach (GameObject Body_ in Bodies)
            {
                Body_.GetComponent <SnakeBody>().UpdateMovement();
            }
        } // DiscreteStep
    private void ReceiveCallback(System.IAsyncResult ar)
    {
        ReceiveStateObject state = (ReceiveStateObject)ar.AsyncState;

        byte[] buff = state.buffer;

        try{
            Body_ b = new Body_();
            b.FromBytes(buff);
            //Debug.Log ("Received " + b.name + " translation, (x,y,z)=" + b.translation.x + "," + b.translation.y + "," + b.translation.z + "\n");
            StateMutex.WaitOne();
            Bodies_[b.name] = b;
            StateMutex.ReleaseMutex();
        }
        catch (Exception ex)
        {
            Debug.Log("Caught: " + ex.Message);
        }
        viconSocket.BeginReceive(state.buffer, 0, state.BufferSize, 0, new System.AsyncCallback(ReceiveCallback), state);
    }
    void Start()
    {
        // START EDITABLE SECTION: Here we declare a body adjustment for each Vicon tracker to address Blade's limitations for creating objects

        // Adjustment for RiftDK1
        Body_ RiftDK1 = new Body_();

        RiftDK1.name                   = "RiftDK1";
        RiftDK1.translation.x          = -0.022f;
        RiftDK1.translation.y          = -0.095f;
        RiftDK1.translation.z          = -0.018f;
        RiftDK1.euler.h                = 342.5f;
        RiftDK1.euler.p                = 347.0f;
        RiftDK1.euler.r                = 196.5f;
        BodyAdjustments_[RiftDK1.name] = RiftDK1;

        // Adjustment for RightGlove
        Body_ RightGlove = new Body_();

        RightGlove.name                   = "RightGlove";
        RightGlove.translation.x          = 0f;
        RightGlove.translation.y          = 0f;
        RightGlove.translation.z          = 0f;
        RightGlove.euler.h                = 87.83496f;
        RightGlove.euler.p                = 7.07246f;
        RightGlove.euler.r                = 86.11337f;
        BodyAdjustments_[RightGlove.name] = RightGlove;

        // Adjustment for RightWiimote
        Body_ RightWiimote = new Body_();

        RightWiimote.name                   = "RightWiimote";
        RightWiimote.translation.x          = 0f;
        RightWiimote.translation.y          = 0f;
        RightWiimote.translation.z          = 0f;
        RightWiimote.euler.h                = 90f;
        RightWiimote.euler.p                = 5f;
        RightWiimote.euler.r                = 90f;
        BodyAdjustments_[RightWiimote.name] = RightWiimote;

        // Adjustment for LeftGlove
        Body_ LeftGlove = new Body_();

        LeftGlove.name                   = "LeftGlove";
        LeftGlove.translation.x          = 0f;
        LeftGlove.translation.y          = 0f;
        LeftGlove.translation.z          = 0f;
        LeftGlove.euler.h                = 86.82818f;
        LeftGlove.euler.p                = 359.3969f;
        LeftGlove.euler.r                = 271.8313f;
        BodyAdjustments_[LeftGlove.name] = LeftGlove;

        // Adjustment for LeftWiimote
        Body_ LeftWiimote = new Body_();

        LeftWiimote.name                   = "LeftWiimote";
        LeftWiimote.translation.x          = 0f;
        LeftWiimote.translation.y          = 0f;
        LeftWiimote.translation.z          = 0f;
        LeftWiimote.euler.h                = 90f;
        LeftWiimote.euler.p                = -10f;
        LeftWiimote.euler.r                = 74f;
        BodyAdjustments_[LeftWiimote.name] = LeftWiimote;

        // Adjustment for RightShoe
        Body_ RightShoe = new Body_();

        RightShoe.name                    = "RightShoe";
        RightShoe.translation.x           = 0.0f;
        RightShoe.translation.y           = -0.015f;
        RightShoe.translation.z           = 0.0f;
        RightShoe.euler.h                 = 232.4361f;
        RightShoe.euler.p                 = 18.79926f;
        RightShoe.euler.r                 = 112.5233f;
        BodyAdjustments_ [RightShoe.name] = RightShoe;

        // Adjustment for LeftShoe
        Body_ LeftShoe = new Body_();

        LeftShoe.name                    = "LeftShoe";
        LeftShoe.translation.x           = 0.0f;
        LeftShoe.translation.y           = -0.005f;
        LeftShoe.translation.z           = 0.0f;
        LeftShoe.euler.h                 = 310.6974f;
        LeftShoe.euler.p                 = 17.13592f;
        LeftShoe.euler.r                 = 255.4526f;
        BodyAdjustments_ [LeftShoe.name] = LeftShoe;

        // END EDITABLE SECTION

        viconSocket = new Socket(AddressFamily.InterNetwork,
                                 SocketType.Stream, ProtocolType.Tcp);
        //Debug.Log ("Trying to open a connection to: " + ViconServerIP);
        IPAddress ipAddress;

        IPAddress.TryParse(ViconServerIP, out ipAddress);

        System.IAsyncResult result = viconSocket.BeginConnect(ipAddress, ViconServerPort, null, null);
        result.AsyncWaitHandle.WaitOne(1000, true);
        if (!viconSocket.Connected)
        {
            //Debug.Log ("Closing the socket");
            viconSocket.Close();
            Destroy(this);
            return;
        }

        ReceiveStateObject state = new ReceiveStateObject();

        state.sock       = viconSocket;
        state.BufferSize = Body_.BufferSize;
        state.buffer     = new byte[state.BufferSize];
        viconSocket.BeginReceive(state.buffer, 0, state.BufferSize, 0, new System.AsyncCallback(ReceiveCallback), state);
    }