javascript - Three.js: Get the Direction in which the Camera is Looking -
i'm sure question has been duplicated many times, cannot find answers specific problem!
i'm creating game in using html5 , three.js, , have photographic camera rotates euler order of 'yxz'.
this photographic camera rotation up, down, left , right head. in first person view.
with euler order, z property in camera.rotation not used (always 0). x used specify pitch or latitude in radians, , y used depict longitude.
i have number of targets moving around user in spherical manner, photographic camera @ center of sphere. lets sphere has radius of 1000.
my aim calculate angle between photographic camera looking, , target is.
i wrote code calculates angle between 2 vectors:
var = new three.vector3(1,0,0); var b = new three.vector3(0,1,0); var theta = math.acos( a.dot(b) / a.length() / b.length() ); // theta = pi/2;
i have vector of target (targets[0].position).
the thing cannot figure out way vector of photographic camera looking.
i've looked @ vector3.applyprojection , applyeuler methods, , played around still cannot results.
i believe euler order must first changed 'xyz' before projections made? i've tried, , i'm not sure how this, documentation pretty hard understand.
say if photographic camera looking straight right, need vector radius distance away center in direction of current rotation.
so end 2 vectors, can calculations on!
thank in advanced!
the photographic camera looking downwards it's internal negative z-axis. create vector pointing downwards negative z-axis:
var vector = new three.vector3( 0, 0, -1 );
now, apply same rotation vector applied camera:
vector.applyquaternion( camera.quaternion );
you can angle in radians target so:
angle = vector.angleto( target.position );
edit: updated three.js r.59
javascript html5 vector three.js
No comments:
Post a Comment