javascript - ThreeJS camera facing point -


in threejs, if camera rotated @ given angle, how can determine coordinate of point 1 unit in direction camera facing.

if unfamiliar threejs camera rotation angles, rotations very weird.

for example, if of rotation variable 0, function return (0, 0, -1).

if rotation x pi / 2 (90 degrees), function return (1, 0, 0)

how create function this? don't need everything, math.

you want world position of point 1 unit in front of camera.

one way add object in front of, , child of, camera. need query world position of object.

by default, when camera's rotation ( 0, 0, 0 ), camera looking down negative z-axis. here pattern follow:

var object = new three.object3d(); object.position.set( 0, 0, - 1 );  scene.add( camera ); // required when camera has children camera.add( object ); 

now, can point need so:

var worldpos = new three.vector3(); // create once , reuse  ...  camera.updatematrixworld(); // called in render loop, may not have call again. experiment.  worldpos.setfrommatrixposition( object.matrixworld ); 

three.js r.71


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -