Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TUIO and Starling #97

Open
djankey opened this issue Jan 29, 2016 · 2 comments
Open

TUIO and Starling #97

djankey opened this issue Jan 29, 2016 · 2 comments

Comments

@djankey
Copy link

djankey commented Jan 29, 2016

I'm working on AIR Starling touch application with TUIO events (Windows).
TUIO events are processed with Starling TouchProcessor.
http://forum.starling-framework.org/topic/touchprocessor-with-tuio-events#post-89081
Starling touch events are fired, but Gestouch doesn't work...

This is my Gestouch code:

Gestouch.inputAdapter = new NativeInputAdapter(Config.myStage);
Gestouch.addDisplayListAdapter(starling.display.DisplayObject, new StarlingDisplayListAdapter());
Gestouch.addTouchHitTester(new StarlingTouchHitTester(Config.star), -1);

Can Gestouch recognize Starling touch events?

@fljot
Copy link
Owner

fljot commented Jan 30, 2016

@djankey
typically you'd use NativeInputAdapter https://github.com/fljot/Gestouch/blob/features/71-fix-initialization/src/org/gestouch/input/NativeInputAdapter.as to handle input via listening to native MouseEvent and/or TouchEvent.
But if you already have some way to send data from TUIO to Starling, you could write some custom Starling-special input adapter that works with Starling events. Use NativeInputAdapter's source code as reference.

To initialize:
https://github.com/fljot/Gestouch/blob/features/71-fix-initialization/CHANGELOG.md
(that is the most recent version branch)

@djankey
Copy link
Author

djankey commented Jan 31, 2016

Thanks Pavel, it's working...

I'm adding TuioTouchEvent's to Starling TouchProcessor and Gestouch TouchesManager.
TuioTouchEvents are from TUIO ActionScript3 library Tuio-as3 https://code.google.com/archive/p/tuio-as3/downloads

TUIO > Flash connection can be done via one of three connectors (TCP, UDP, LocalConnection).
TCP and LocalConnection are working on my computer with bridge apps (udp-tcp-bridge https://code.google.com/archive/p/udp-tcp-bridge/downloads and udp-flashlc-bridge http://gkaindl.com/software/udp-flashlc-bridge)

Here is my implementation - It's not the prettiest, but it's working :)

// Add this to Starling main class
tuio = new TuioConnector(stage, tuio_ip_address, tuio_port, isTCP,  isUDP, isLocalConnection);
tuio.touchesManager = Gestouch.touchesManager;
Gestouch.addDisplayListAdapter(starling.display.DisplayObject, new StarlingDisplayListAdapter());
Gestouch.addTouchHitTester(new StarlingTouchHitTester(Config.starling), -1);

TuioConnector .as

/**
 * Created by djankey on 30.01.16.
 */
package utils {
import flash.net.LocalConnection;

import org.tuio.ITuioListener;
import org.tuio.TuioBlob;
import org.tuio.TuioClient;
import org.tuio.TuioCursor;
import org.tuio.TuioObject;
import org.tuio.TuioTouchEvent;
import org.tuio.connectors.LCConnector;
import org.tuio.connectors.TCPConnector;
import org.tuio.connectors.UDPConnector;

import starling.core.Starling;
import starling.display.Stage;
import starling.events.TouchPhase;
import starling.events.TouchProcessor;

import org.gestouch.core.IInputAdapter;
import org.gestouch.core.TouchesManager;
import org.gestouch.core.gestouch_internal;

public class TuioConnector implements ITuioListener, IInputAdapter {
    private var _localConnection:LocalConnection;
    private var _lcConnector:LCConnector;
    private var _udpConnector:UDPConnector;
    private var _tcpConnect:TCPConnector;
    private var tuioClient:TuioClient;

    protected var _stage:Stage;
    protected var _touchesManager:TouchesManager;

    use namespace gestouch_internal;


    public function TuioConnector(stage:Stage, address:String = "127.0.0.1", port:int = 3333, isTCP:Boolean = false, isUDP:Boolean = false, isLocalConnection:Boolean = true) {
        _stage = stage;

        if (isTCP == true) {
            _tcpConnect = new TCPConnector(address, port);
            tuioClient = new TuioClient(_tcpConnect);
            tuioClient.addListener(this);
        } else if (isUDP == true) {
            _udpConnector = new UDPConnector(address, port);
            tuioClient = new TuioClient(_udpConnector);
            tuioClient.addListener(this);
        } else if (isLocalConnection == true) {
            _localConnection = new LocalConnection();
            _localConnection.connect("_MyConnection");
            _localConnection.allowDomain('*');
            _localConnection.client = this;
            _lcConnector = new LCConnector();
            tuioClient = new TuioClient(_lcConnector);
            tuioClient.addListener(this);
        } else {
            return;
        }

        init();
    }

    public function init():void {
        Starling.current.nativeStage.addEventListener(TuioTouchEvent.TOUCH_DOWN, addTuioCursor);
        Starling.current.nativeStage.addEventListener(TuioTouchEvent.TOUCH_UP, removeTuioCursor);
        Starling.current.nativeStage.addEventListener(TuioTouchEvent.TAP, addTuioCursor);
        Starling.current.nativeStage.addEventListener(TuioTouchEvent.TOUCH_MOVE, updateTuioCursor);

        //Starling.current.nativeStage.addEventListener(TuioTouchEvent.TOUCH_OVER, addTuioCursor);
        //Starling.current.nativeStage.addEventListener(TuioTouchEvent.TOUCH_OUT, removeTuioCursor);
        //Starling.current.nativeStage.addEventListener(TuioTouchEvent.ROLL_OVER, addTuioCursor);
        //Starling.current.nativeStage.addEventListener(TuioTouchEvent.ROLL_OUT, removeTuioCursor);
    }

    public function set touchesManager(value:TouchesManager):void {
        _touchesManager = value;
    }

    public function onDispose():void {
        _touchesManager = null;
    }

    public function addTuioCursor(tuioCursor:TuioCursor):void {
        var stgX:Number = tuioCursor.x * stgW;
        var stgY:Number = tuioCursor.y * stgH;

        if(_touchesManager) _touchesManager.onTouchBegin(tuioCursor.sessionID, stgX, stgY);
        touchProcessor.enqueue(tuioCursor.sessionID, TouchPhase.BEGAN, stgX, stgY);
    }

    public function updateTuioCursor(tuioCursor:TuioCursor):void {
        var stgX:Number = tuioCursor.x * stgW;
        var stgY:Number = tuioCursor.y * stgH;

        if (_touchesManager) _touchesManager.onTouchMove(tuioCursor.sessionID, stgX, stgY);
        touchProcessor.enqueue(tuioCursor.sessionID, TouchPhase.MOVED, stgX, stgY);
    }

    public function removeTuioCursor(tuioCursor:TuioCursor):void {
        var stgX:Number = tuioCursor.x * stgW;
        var stgY:Number = tuioCursor.y * stgH;

        if (_touchesManager)_touchesManager.onTouchEnd(tuioCursor.sessionID, stgX, stgY);
        touchProcessor.enqueue(tuioCursor.sessionID, TouchPhase.ENDED, stgX, stgY);
    }

        public function addTuioBlob(tuioBlob:TuioBlob):void {

        }

        public function updateTuioBlob(tuioBlob:TuioBlob):void {

        }

        public function removeTuioBlob(tuioBlob:TuioBlob):void {

        }

        public function addTuioObject(tuioObject:TuioObject):void {

        }

        public function updateTuioObject(tuioObject:TuioObject):void {

        }

        public function removeTuioObject(tuioObject:TuioObject):void {

        }

        public function newFrame(id:uint):void {

        }

        private function get touchProcessor():TouchProcessor {
            return Starling.current.touchProcessor;
        }

        private function get stgW():Number {
            return Starling.current.nativeStage.stageWidth;
        }

        private function get stgH():Number {
            return Starling.current.nativeStage.stageHeight;
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants