Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  155] [ 7]  / answers: 1 / hits: 24781  / 11 Years ago, mon, september 16, 2013, 12:00:00

I have a camera in my app:



camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = 1;
camera.position.y = -5;
camera.rotateOnAxis(new THREE.Vector3(1, 0, 0), degInRad(90));
camera.up = new THREE.Vector3(0, 0, 1);


Those code in render function must rotate the camera while I'm pressing the keys:



if (leftPressed) {
camera.rotateOnAxis((new THREE.Vector3(0, 1, 0)).normalize(), degInRad(1));
} else if (rightPressed) {
camera.rotateOnAxis((new THREE.Vector3(0, 1, 0)).normalize(), degInRad(-1));
}
if (upPressed) {
camera.rotateOnAxis((new THREE.Vector3(1, 0, 0)).normalize(), degInRad(1));
} else if (downPressed) {
camera.rotateOnAxis((new THREE.Vector3(1, 0, 0)).normalize(), degInRad(-1));
}


Camera rotates, but not in way I need. I want that camera rotates like in FPS (first person shooter) on plane. See picture to understand what I want...

I'm try to use sin(1) and cos(1) but can't understand how rotateOnAxis works, cause translate functions work like a charm and moves camera in direction in what she sees.

P.S.

Here is a docs to the three.js maybe it helps.

To handle keyboard events I use KeyboardJS

And here is a degInRad function:



function degInRad(deg) {
return deg * Math.PI / 180;
}


Link on JSFiddle



camera



O - position of camera

O-O1 - current camera direction

R1 - current rotation direction

R - direction what I want

Sorry for good picture.


More From » camera

 Answers
8

You might get what you want simply by setting camera.rotation.order = 'YXZ';


[#75661] Saturday, September 14, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
monetm

Total Points: 615
Total Questions: 103
Total Answers: 119

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
monetm questions
Fri, Feb 26, 21, 00:00, 3 Years ago
Wed, Sep 9, 20, 00:00, 4 Years ago
Sun, Jul 26, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
;