nbriz / threejs_playGnd

pedagogical + experimental tool/space/editor for three.js/webGL
55 stars 16 forks source link

Mouse Movement #8

Open nsanati opened 10 years ago

nsanati commented 10 years ago

Is it possible to parent the camera movement to mouse movement?

nbriz commented 10 years ago

yes, but not in the _playGnd, the editor is a variation on Mr.doob's HTML Editor and for some reason getting mouse positions just doesn't work ( https://github.com/mrdoob/htmleditor/issues/10 )

that said, if you're working in your own editor ( outside the _playGnd ) I normally pull mouse coordinates this way: first i add the following global variables up top:

var mouseX = 0, mouseY = 0;

then I add the following listener to my setup:

document.addEventListener( 'mousemove', onDocumentMouseMove, false );

then I paste the following function:

        function onDocumentMouseMove(event) {
            mouseX = event.clientX;
            mouseY = event.clientY;
        }

( or some variation thereof ) then you can use mouseX && mouseY for whatever in the draw function

also, this exists >> http://threejs.org/examples/js/controls/TrackballControls.js example here: http://threejs.org/examples/misc_controls_trackball.html

nsanati commented 10 years ago

Hey Nick thanks for your reply, Can I ask what editor do you use? because when I paste the codes from _playGnd it says "Error creating WebGL context."

nbriz commented 10 years ago

I'm using sublime text 2, but the editor your using doesn't have any effect on how your code executes, so that shouldn't be an issue

nsanati commented 10 years ago

yea it was the browser's problem. thanks a lot for your help, I'm now able to move the camera with moving the mouse. you're the best teacher ever.