Rotate camera with mouse

This commit is contained in:
Tanner Collin 2021-03-24 06:20:41 +00:00
parent 52691e8f0b
commit 605a4ff40b

View File

@ -47,19 +47,17 @@ export const scene = ({ ref }) => {
renderer.setSize(ref.current.clientWidth, ref.current.clientHeight); renderer.setSize(ref.current.clientWidth, ref.current.clientHeight);
}); });
ref.current.addEventListener('mousemove', (e) => {
const x = e.clientX;
const ratio = x / ref.current.clientWidth;
camera.position.set(5, 2, ratio*4 - 2);
camera.lookAt(new THREE.Vector3(0, 0, 0));
});
const animate = () => { const animate = () => {
const deltaTime = 0.075; const deltaTime = 0.075;
t += deltaTime; t += deltaTime;
// register mouse event for 'onmove'
// get mouse x & y
// const mu = mousex / ref.width
// const mv = mousey / ref.heigh
// camera.x = sin(mu * Math.PI * 2)
// camera.z = cos(mu * Math.PI * 2)
//
const direction = Math.random() > 0.5 ? 1 : -1; const direction = Math.random() > 0.5 ? 1 : -1;
if (t > nextShip) { if (t > nextShip) {
@ -76,7 +74,6 @@ export const scene = ({ ref }) => {
const bolt = new Laser(ship); const bolt = new Laser(ship);
bolts.push(bolt); bolts.push(bolt);
scene.add(bolt.mesh); scene.add(bolt.mesh);
console.log(bolt.mesh.position);
ship.firing = false; ship.firing = false;
} }