googlearchive / vrview

Library for embedding immersive media into traditional websites.
http://developers.google.com/cardboard/vrview
Apache License 2.0
1.71k stars 1.09k forks source link

Event 'getposition' not triggering? #300

Open clarklyyc opened 6 years ago

clarklyyc commented 6 years ago

When does the 'getposition' event fire?

The code snippet below doesn't seem to trigger. It was copied and slightly modified from the hotspot example (https://googlevr.github.io/vrview/examples/hotspots/index.html).

this.VRView.on('getposition', (e) => {
  console.log(`getposition triggered - ${e}`)
})

I am currently self-hosting using the minimized files from https://github.com/googlevr/vrview#downloading-files

Thanks

MarkMcCorrie commented 6 years ago

I'm getting the same problem. When I call VRView.getPosition(), it isn't triggering that callback.

It's working on one of their example pages: https://googlevr.github.io/vrview/examples/hotspots/index.html

I have hotspots working, I just need the getPosition to trigure to set the hotspots without messing around.

clarklyyc commented 6 years ago

Hey Mark,

I managed to figure this out, you need to call .getPosition() in a click event handler, as well as a 'getposition' event listener. See code:

vrview.on('click', (e) => {
  vrview.getPosition() // call in click event
}

vrview.on('getposition', (e) => {
  console.log(`Yaw: ${e.Yaw}. Pitch: ${e.Pitch}.`) 
}

Hope this helps!

MarkMcCorrie commented 6 years ago

My code already does that and it's still not working! It doesn't even run through my function when I all getPosition().

I've got it hosted here: https://www.madesnappy.co.uk/example_360?id=1

gallery.view = new VRView.Player('#' + options.view, {
    image: 'Pictures/blank.png',
    preview: 'Pictures/blank.png',
    width: gallery.width + "px",
    height: gallery.height + "px",
    is_autopan_off: true
  });
  gallery.view.on("click", function(event) {
    gallery.view.getPosition();
    if (event.id) {
      gallery.load_scene(gallery.picture_index(event.id));
    }
  });
  gallery.view.on('getposition', function(event) {
    console.log(event.Yaw);
    console.log(event.Pitch);
  });
  gallery.view.on('ready', function(event) {
    gallery.load_scene(0);
  });
MarkMcCorrie commented 6 years ago

I've moved to http://photo-sphere-viewer.js.org/ now and it has fixed all the problems I was having with vrview. When you click on the photo, it tells you the coordinates you clicked (not the camera view), and more importantly, it works without a problem. The features are a lot more sophisticated than vrview, and all round better job done of it.