javascript - Keyboard Controls With DeviceOrientationControls -


i creating vr web app using three.js. camera controls using device orientation controls used here in google cardboard three.js demo.

what need add keyboard controls this(e.g arrow go forward etc). i've fiddled around moving camera on 2 axis (x , z) here:

if (e.keycode == '38') {     camera.position.set(0, 10, camera.position.z+4);      controls.target.set(         camera.position.x +4,         camera.position.y,         camera.position.z     );     effect.render(scene, camera); ... 

however want make character move relative looking (e.g 1 way , press arrow , character moves way looking). first person view.

does have ideas on how done? ive tried using first person controls three.js eliminates head tracking essential vr game.

any answers appreciated. (my source code practically google cardboard three.js demo code function added in detect key presses)

i solved different approach. created object3d moving in scene. model , camera child of object.

i'm rotating object 3d camera , in same time rotate model in opposite direction. when rotate camera object looks keeping direction. when want move object, translatex object camera , make model rotation 0. did trick.

on long distances (i have millions of units) started jerky. reason lost precision.

i solved keeping position of object @ 0,0,0 , move other things in opposite direction. makes model still on 0,0,0 coords right rotation , world moving around.

most simple example:

you trying like

scene.add(character_model); scene.add(camera); //camera.rotate .... character_model.translatex(1); character_model.rotatex(1); //etc ... 

and trying move camera around pivot (character_model), overcomplicated mathematics.

try:

var controls_dimension = new three.object3d(); scene.add(controls_dimension); controls_dimension.add(character_model); controls_dimension.add(camera);  //use controls rotate object, not character_model controls_dimension.rotatex(2);  // in same rotate model opposite direction. can make  // illusion of rotating camera, not model. character_model.rotatex(2*-1);  /*  when want go in camera direction=controls_dimension=controls_dimension.translatex(1)  , moving (you animate model rotation controls_dimension.rotation) */ 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -