Our services include creating and managing business websites, ecommerce + customer portals. We also offer software architecture and design, AR/VR product visualisation, business systems / integrations, mobile app creation, AI-driven chatbots and on-site SEO.
Codebricks offer a range of Umbraco plugins from Push Notifications to Ecommerce and coming soon - 3D, AR and VR experiences!
In this article we will show you how to easily calculate the angle of your camera in either degrees or radians for ThreeJS.
First of all you should add the following code to your ThreeJS Animate function:
var cameraAngle = getCameraAngle(yourCamera.getWorldDirection()); console.log('camera angle:' + cameraAngle);
Next you need to declare the following two functions:
/// /// Get ThreeJS Camera Angle /// function getCameraAngle(cameraVector) { return radiansToDegrees(Math.atan2(cameraVector.x, cameraVector.z)); } /// /// Convert Radians to Degrees /// function radiansToDegrees(radians) { return radians * 180 / Math.PI; }
The code above returns the camera angle in degrees, to switch this to Radians just change the getCameraAngle function to the following:
/// /// Get ThreeJS Camera Angle /// function getCameraAngle(cameraVector) { return Math.atan2(cameraVector.x, cameraVector.z); }
Thats how you get the angle your ThreeJS camera is pointing in, in either degrees or radians!
We use cookies to improve your experience, support our business, and ensure essential service functionality. Learn more in our Privacy Policy.