Touch input on android

67 views
Skip to first unread message

tomhog

unread,
Apr 11, 2013, 7:18:56 AM4/11/13
to os...@googlegroups.com
Hi

I've been using osgjs a bit again lately, loving the new features and getting great frame rates using exporter plugin.

So I have recently been asked to try it out on Android devices, I have a Gallaxy S2. If I run one of the example, say shadows
example, the touch input works as expected (and the shadows seem to work, which is amazing). However in my own application
only touch start seems to work.

Basically dragging to rotate the scene doesn't work, it's like touch moved isn't being called.

Is there something I need to do to my canvas or similar that i'm missing? I'm a real newbie at html side of things


Thanks
Tom

tomhog

unread,
Apr 11, 2013, 12:40:04 PM4/11/13
to os...@googlegroups.com
I think I've spotted my mistake,

The source for OrbitManipulator that I have has the touch code in it, but the built version i'm including in my project doesn't

I'll update, which should fix my problem (wonder why buttons were still working with no touch code)

Thanks
Tom

Cedric Pinson

unread,
Apr 16, 2013, 9:07:39 PM4/16/13
to os...@googlegroups.com
Hi Thomas,

On Apr 11, 2013, at 12:40 , tomhog <thomas....@gmail.com> wrote:

I think I've spotted my mistake,

The source for OrbitManipulator that I have has the touch code in it, but the built version i'm including in my project doesn't

I'll update, which should fix my problem (wonder why buttons were still working with no touch code)
I played a bit with hammer.js to have a better touch control. I don't have time right now to implement it in the good way, but if you are motivated.
Here a piece of code, I hope it will help you. You should have your manipulator defined like this:
 var manipulator = viewer.getManipulator();

    if (isMobile.any()) {
        var computeTouches = function(ev) {
            if (ev.originalEvent.changedTouches !== undefined)
                return ev.originalEvent.changedTouches.length;
            return 1; // mouse
        };

        var dragCB = function(ev) {
            return "touches " + computeTouches(ev) + " distance " + ev.distance + " x " + ev.distanceX + " y " + ev.distanceY;
        };

        hammer.ondragstart = function(ev) {
            if (computeTouches(ev) === 2) {
                padMode = true;
            }

            if (padMode) {
                manipulator.getPanInput().reset();
                manipulator.getPanInput().set(ev.position.x*panFactorX, ev.position.y*panFactorY);
            } else {
                manipulator.getRotateInput().reset();
                manipulator.getRotateInput().set(ev.position.x*rotateFactorX, ev.position.y*rotateFactorY);
            }
        };
        hammer.ondrag = function(ev) {
            if (padMode) {
                manipulator.getPanInput().setTarget(ev.position.x*panFactorX, ev.position.y*panFactorY);
            } else {
                manipulator.getRotateInput().setTarget(ev.position.x*rotateFactorX, ev.position.y*rotateFactorY);
            }
        };
        hammer.ondragend = function(ev) {
            padMode = false;
        };

        var toucheScale = undefined;
        hammer.ontransformstart = function(ev) {
            toucheScale = ev.scale;
            var scale = ev.scale;
            manipulator.getZoomInput().reset();
            manipulator.getZoomInput().set(ev.scale);
        };
        hammer.ontransformend = function(ev) {
        };
        hammer.ontransform = function(ev) {
            var scale = (ev.scale - toucheScale)*zoomFactor;
            toucheScale = ev.scale;
            var target = manipulator.getZoomInput().getTarget()[0];
            manipulator.getZoomInput().setTarget(target-scale);

        };

    }


Thanks
Tom

On Thursday, April 11, 2013 12:18:56 PM UTC+1, tomhog wrote:
Hi

I've been using osgjs a bit again lately, loving the new features and getting great frame rates using exporter plugin.

So I have recently been asked to try it out on Android devices, I have a Gallaxy S2. If I run one of the example, say shadows
example, the touch input works as expected (and the shadows seem to work, which is amazing). However in my own application
only touch start seems to work.

Basically dragging to rotate the scene doesn't work, it's like touch moved isn't being called.

Is there something I need to do to my canvas or similar that i'm missing? I'm a real newbie at html side of things


Thanks
Tom

--
You received this message because you are subscribed to the Google Groups "osgjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osgjs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages