示例#1
0
    public void updateCursor(TuioCursor cursor)
    {
        if (!activeEvents.ContainsKey(cursor.getSessionID()))
        {
            return;
        }
        mtCntrEvent anEvent = activeEvents[cursor.getSessionID()];

        anEvent.eventState = mtEventState.Moved;

        if (cursor.getContour() != null)
        {
            List <TuioPoint> contr      = cursor.getContour();
            List <Vector3>   cntrPoints = new List <Vector3>();
            foreach (TuioPoint pnt in contr)
            {
                float xC = pnt.getX();
                float yC = pnt.getY();
                cntrPoints.Add(new Vector3(xC * cameraPixelWidth, 0, (1.0f - yC) * cameraPixelHeight));
            }
            anEvent.contour = cntrPoints.ToArray();

            //calibrate and CoM (center of mass)
            float  xCoM = 0.0F;
            float  yCoM = 0.0F;
            Matrix mat  = Matrix.Translate(xTCalib, yTCalib, 0.0F);
            for (int i = 0; i < anEvent.contour.Length; i++)
            {
                anEvent.contour[i] = mat.TransformVector(anEvent.contour[i]);
                xCoM += anEvent.contour[i].x;
                yCoM += anEvent.contour[i].y;
            }
            xCoM /= anEvent.contour.Length;
            yCoM /= anEvent.contour.Length;

            //translate to 0
            for (int i = 0; i < anEvent.contour.Length; i++)
            {
                anEvent.contour[i].x -= xCoM;
                anEvent.contour[i].y -= yCoM;
            }

            anEvent.lastScreenPosition = anEvent.screenPosition;
            anEvent.screenPosition     = new Vector3(xCoM, 0, yCoM);
        }

        lock (eventQueueLock) eventQueue.Add(anEvent);
        didChange = true;
    }
示例#2
0
    public void removeCursor(TuioCursor cursor)
    {
        if (!activeEvents.ContainsKey(cursor.getSessionID()))
        {
            return;
        }
        mtCntrEvent anEvent = activeEvents[cursor.getSessionID()];

        anEvent.eventState = mtEventState.Ended;
        lock (eventQueueLock) {
            eventQueue.Add(anEvent);
        }
        activeEvents.Remove(cursor.getSessionID());
        didChange = true;
    }
示例#3
0
    public void newCursor(TuioCursor cursor)
    {
        mtCntrEvent newEvent = new mtCntrEvent(cursor.getSessionID());
        newEvent.tuioPosition = new Vector2(cursor.getX(),(1.0f - cursor.getY()));
        //switching y and z (y is up axis by default in unity)
        newEvent.screenPosition = new Vector3(cursor.getX() * cameraPixelWidth, 0,(1.0f - cursor.getY()) * cameraPixelHeight);
        newEvent.lastScreenPosition = newEvent.screenPosition;
        newEvent.eventState = mtEventState.Began;

        if (activeEvents.ContainsKey(cursor.getSessionID())) {
            //Already on list, remove old - add new
            activeEvents.Remove(cursor.getSessionID());
        }
        activeEvents.Add( cursor.getSessionID(), newEvent );
        // queue it up for processing
        lock (eventQueueLock) eventQueue.Add(newEvent);
        didChange = true;
    }
示例#4
0
    public void newCursor(TuioCursor cursor)
    {
        mtCntrEvent newEvent = new mtCntrEvent(cursor.getSessionID());

        newEvent.tuioPosition = new Vector2(cursor.getX(), (1.0f - cursor.getY()));
        //switching y and z (y is up axis by default in unity)
        newEvent.screenPosition     = new Vector3(cursor.getX() * cameraPixelWidth, 0, (1.0f - cursor.getY()) * cameraPixelHeight);
        newEvent.lastScreenPosition = newEvent.screenPosition;
        newEvent.eventState         = mtEventState.Began;

        if (activeEvents.ContainsKey(cursor.getSessionID()))
        {
            //Already on list, remove old - add new
            activeEvents.Remove(cursor.getSessionID());
        }
        activeEvents.Add(cursor.getSessionID(), newEvent);
        // queue it up for processing
        lock (eventQueueLock) eventQueue.Add(newEvent);
        didChange = true;
    }
示例#5
0
    public void updateCursor(TuioCursor cursor)
    {
        if (!activeEvents.ContainsKey(cursor.getSessionID()))
        {
            return;
        }
        mtCntrEvent anEvent = activeEvents[cursor.getSessionID()];

        anEvent.eventState = mtEventState.Moved;

        if (cursor.getContour() != null)
        {
            List <TuioPoint> contr      = cursor.getContour();
            List <Vector3>   cntrPoints = new List <Vector3>();
            foreach (TuioPoint pnt in contr)
            {
                float xC = pnt.getX();
                float yC = pnt.getY();
                cntrPoints.Add(new Vector3(xC * cameraPixelWidth, (1.0f - yC) * cameraPixelHeight, 0));
            }
            anEvent.contour = cntrPoints.ToArray();
            //calibrate and CoM (center of mass)
            float  xCoM = 0.0F;
            float  yCoM = 0.0F;
            Matrix mat  = Matrix.Translate(xTCalib, yTCalib, 0.0F);
            for (int i = 0; i < anEvent.contour.Length; i++)
            {
                anEvent.contour[i] = mat.TransformVector(anEvent.contour[i]);
                xCoM += anEvent.contour[i].x;
                yCoM += anEvent.contour[i].y;
            }
            xCoM /= anEvent.contour.Length;
            yCoM /= anEvent.contour.Length;

            //translate to 0
            for (int i = 0; i < anEvent.contour.Length; i++)
            {
                anEvent.contour[i].x -= xCoM;
                anEvent.contour[i].y -= yCoM;
            }

            anEvent.lastScreenPosition = anEvent.screenPosition;
            anEvent.screenPosition     = new Vector3(xCoM, 0, yCoM);



            /*
             * anEvent.lastTime = anEvent.currentTime;
             * anEvent.currentTime = Time.time;
             * float dt = anEvent.currentTime - anEvent.lastTime; //delta time
             * if(dt > 0)
             * {
             *      float dx = anEvent.lastScreenPosition.x - anEvent.screenPosition.x;
             *      float dy = anEvent.lastScreenPosition.z - anEvent.screenPosition.z;
             *      float distance = (float)Mathf.Sqrt(dx*dx+dy*dy);
             *      float lastMspeed = anEvent.mAccel;
             *      anEvent.x_speed = dx / dt; // delta x / delta time = velocity x
             *      anEvent.y_speed = dy / dt; // -||-
             *      anEvent.mSpeed = distance / dt;
             *      anEvent.mAccel = (anEvent.mSpeed - lastMspeed) / dt;
             * }
             */
        }

        lock (eventQueueLock) eventQueue.Add(anEvent);
        didChange = true;
    }