Coder Social home page Coder Social logo

Moving Camera about webvr-boilerplate HOT 5 CLOSED

borismus avatar borismus commented on August 29, 2024
Moving Camera

from webvr-boilerplate.

Comments (5)

JohnRodney avatar JohnRodney commented on August 29, 2024 1

@borismus I've manually updated the position by using the camera.position.set() method according to the THREE.js docs and it seems to keep itself right where it was. I did the same code outside of the VR boiler plate and the camera's moved fine.

My temporary workaround is to write a function to translate the entire scene opposite a vector I derive by creating a down vector and applying the THREE.js camera quaternion to it. This isn't ideal as I'd rather just move the camera, but hey working is working.

I appreciate your response and I'm assuming you've manually adjusted the camera position in a VR scene in order to be sure that it is not the VR library. I am working with other technologies as well so it is possible that something else is overriding my changes other than the VR boiler plate.

Anyways thanks for this great repo its been very helpful in getting cardboard, and rift based websites running quickly.

from webvr-boilerplate.

borismus avatar borismus commented on August 29, 2024

John, sounds more like a THREE.js question to me than something VR-specific. You should take a look at THREE.Camera APIs. There's a lot of THREE sample code out there.

from webvr-boilerplate.

brianpeiris avatar brianpeiris commented on August 29, 2024

@JohnRodney The boilerplate uses VRControls from Three.js. The controls do set the camera's position, so setting it manually will have no effect. This is due to Three.js more than it is due to the boilerplate, as Boris said. It is normal for most of the Three.js controls to override the camera position.

It is not obvious to novices, but one workaround is to apply the VRControls camera position on top of your manual camera position before rendering the scene, and then reset it after.

Working example:
http://jsbin.com/zaboju/2/edit?html,js,output
http://output.jsbin.com/zaboju/2

Relevant snippet:

var BASE_POSITION  = new THREE.Vector3(-1, -2, 0);
var BASE_QUATERNION  = new THREE.Quaternion().setFromAxisAngle(
  new THREE.Vector3(0, 1, 0),
  -Math.PI / 8
);

var render = function() {
  requestAnimationFrame(render);

  vrControls.update();

  // Store the VR camera transformation
  // temporarily
  var cameraPos = camera.position.clone();
  var cameraQuat = camera.quaternion.clone();

  // Use the manual transformation and apply the
  // VR transformation on top of it.
  var rotatedPos = cameraPos.clone().applyQuaternion(BASE_QUATERNION);
  camera.position.copy(BASE_POSITION).add(rotatedPos);
  camera.quaternion.multiplyQuaternions(BASE_QUATERNION, camera.quaternion);

  vrEffect.render(scene, camera);

  // Reset the camera to the VR transform
  // so that VRControls can pick up where
  // it left off
  camera.position.copy(cameraPos);
  camera.quaternion.copy(cameraQuat);
};

@borismus Maybe this should be part of the example in the boilerplate, since it seems to be one of the first things that users try to do once they get things running. I suggest incorporating FirstPersonControls.

from webvr-boilerplate.

borismus avatar borismus commented on August 29, 2024

@brianpeiris Thanks for the detailed explanation!

Not sure what you mean about incorporating FirstPersonControls. The polyfill provides virtual PositionalDevices powered by mouse/keyboard which alleviates the need for anything except VRControls. To mitigate the FF issue, we could do a deeper check to see if getVRDevices actually returns any VR devices.

from webvr-boilerplate.

brianpeiris avatar brianpeiris commented on August 29, 2024

@borismus I meant the example should allow users to move around with WASD while they are in VR mode with a VR device on.

from webvr-boilerplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.