question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set camera look vector from roll, pitch and yaw values?

See original GitHub issue

When I init my ThreeJS base application I must specify camera target:

camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 2000);
camera.position.set(0, 0, 1500);
camera.target = new THREE.Vector3(0, 0, 0);

I also have one mesh which I have put on 0,0,0 coordinates.

Now I need to set camera’s rotation based on roll, pitch and yaw values that I receive from my mobile phone and these values are from -PI to +PI.

I tried something like this

camera.rotation.x = roll / Math.PI
camera.rotation.y = yaw / Math.PI
camera.rotation.z = pitch / Math.PI

but camera would always look at 0,0,0 and I need it to look at place based on roll, pitch and yaw. How can I accomplish this?

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
mrdoobcommented, Feb 21, 2012

Camera always look at 0,0,0? You must have a camera.lookAt() overriding your rotation somewhere in your code.

3reactions
Dino4674commented, Feb 21, 2012

I found this library http://www.c3dl.org/index.php/tutorials/tutorial-9-camera-basics/ and I see that it can set camera’s roll, pitch and yaw values.

How to do this with Three.js?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get camera up vector from roll, pitch, and yaw?
You can use this for looking up values, invoking methods, or whatever. So if you have a transformation matrix and you wanted to...
Read more >
Camera - LearnOpenGL
The pitch is the angle that depicts how much we're looking up or down as seen in the first image. The second image...
Read more >
Camera - SwiftGL
The pitch is the angle that depicts how much we're looking up or down as seen in the first image. The second image...
Read more >
Finding pitch/yaw values from lookat vector
I have a camera class that contains a position, a pitch, and a yaw (the pitch and the yaw correspond to y and...
Read more >
Finding camera up with yaw, pitch and roll? - Processing forum
up.x = cos(cam.getRotations()[0])*sin(cam.getRotations()[1]); up.y = -cos(cam.getRotations()[1]); up.z = sin(cam.getRotations()[0])*sin(cam.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found