xml3d / xml3d.js

The WebGL/JS implementation of XML3D
Other
75 stars 25 forks source link

dynamic camera settings #182

Closed chriscarex closed 8 years ago

chriscarex commented 8 years ago

Hi, I would like to change the camera behaviour dynamically. After loading the initial camera settings:

function onload() { var viewElement = document.getElementById("geometry"); var cam = new XML3D.StandardCamera(viewElement, {mode: "examine", zoomSpeed: 200}); cam.examine(viewElement); }

I would like to change the value of zoomSpeed. I tried severa lmethods, such as initialising a new camera, updating the camera with cam = new XML3D.StandardCamera(viewElement, {mode: "examine", zoomSpeed: 100}); using global variables replacing the number, but none of them seem to work when applied dynamically. Any suggestion on how to solve this issue? Is there a way to stop the first camera and initialise a new one? Thanks!

csvurt commented 8 years ago

Hi,

you should be able to set it directly on the camera object:

var cam = new XML3D.StandardCamera(viewElement, {mode: "examine", zoomSpeed: 200}); 
cam.examine(viewElement); 
...
cam.zoomSpeed = 100;

If you re-initialize a camera you should always detach the old one first, otherwise all the event listeners will still be bound:

cam.detach();
cam = new XML3D.StandardCamera(viewElement);