when i touch the canvas with two fingers,how can i get the touch positions with babylon api;i want to calculate the center of them as the zoom center.
and how to listen the touch event ? I can’t find anything in BABYLON.PointerEventTypes…
thanks
when i touch the canvas with two fingers,how can i get the touch positions with babylon api;i want to calculate the center of them as the zoom center.
and how to listen the touch event ? I can’t find anything in BABYLON.PointerEventTypes…
thanks
Adding @PolygonalSun who may help here.
Hey @ecojust,
So something that comes to mind is to use scene.onPointerObservable. You could add a method to this and grab the direct event from it to get whatever values you need:
scene.onPointerObservable.add((eventData) => {
// eventData.event is the event object
// eventData.type is the PointerEventTypes object, in case you need it
});
@PolygonalSun thanks for your reply,
In fact,i know this way you said , but i don’t know which type is used to respond to touch events(which i can get two fingers position from the callback)
mouse zoom:
scene.onPointerObservable.add(zoomFn, BABYLON.PointerEventTypes.POINTERWHEEL);
touch zoom:
scene.onPointerObservable.add(zoomFn, BABYLON.PointerEventTypes.???);
With touch, it may be a bit more complicated than a single PointerEventType. You have to use multiple types for your scenario. First, you’ll have to use PointerEventTypes.POINTERDOWN to register that there’s a point down. Next, if you have at least one registered point, you’ll have to then use PointerEventTypes.POINTERMOVE to get the location for each point (you’ll have to use pointerId to distinguish between them). Finally, you’ll need to use PointerEventTypes.POINTERUP to deregister a point.
While this isn’t the most elegant example, here’s a example PG:
Touch test | Babylon.js Playground
@PolygonalSun thanks for your idea.
Admittedly, that is a good solution at a business logic level,
I think I should spend some time with the “onMultiTouch” API