ziguri Posted April 19, 2018 Share Posted April 19, 2018 Hi there, i do react on a camera change using camera.onViewMatrixChangedObservable Then i watch camera.alpha and camera.beta values and calculate their difference (considering modulo 2*PI) to the previous invocation of camera.onViewMatrixChangedObservable. Lets call it cam_alpha_diff. Using this alpha and beta values I am able to rotate a submesh (a BABYLON.Mesh.CreatePlane mesh located in the WorldMatrix origin) of my scene with mesh.rotate(AXIS, cam_alpha_diff) This works fine as long as i just wanna rotate the submesh around one axis. For instance only around the BABYLON.Axis.Y with the negative cam_alpha_diff. If i wanna rotate the submesh in both alpha and beta direction i can not use the BABYLON.Axis.Y and BABYLON.Axis.X as rotating axis anymore. (except for the first camera movement). I kind of need to re-calcutate the rotation axis after each change of the camera. My approach: Initialize a vector3 as BABYLON.Axis.Y Rotate the vector3 with the negative cam_alpha_diff using BABYLON.Matrix.RotationAxis and BABYLON.Vector3.TransformCoordinates Use the resulting vector3 as new rotation axis Do the same with another vector3 for BABYLON.Axis.X But if i do it for both alpha and beta is kind of "going round in circles". Whats the best way to apply both alpha and beta camera rotations to a submesh? Any hints? My final goal is that the submesh always faces the camera no matter how i rotate the camera (an ArcRotateCamera). Thanks. Quote Link to comment Share on other sites More sharing options...
Gijs Posted April 19, 2018 Share Posted April 19, 2018 Can't you just use billboard mode? ziguri 1 Quote Link to comment Share on other sites More sharing options...
ziguri Posted April 20, 2018 Author Share Posted April 20, 2018 @Gijs, you are totally right. This completely solves my issue. I didn't know that the billboard mode exists at all. Thank you. Appreciated. Issue solved! Gijs 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 20, 2018 Share Posted April 20, 2018 Hey ziguri... glad you found the solve. "Billboard" is sort of a strange word for "mesh look-at cam", isn't it? I think so. Can I ask... Did you do a docs search for 'lookAt' or 'look at' or something else? I'm just curious. That search would have failed to find info about billboard. I'm trying to figure a way to make billboardMode easier to find information-about. Or maybe more precise, easier to find THAT TERM and what it is used-for. I'm wondering if a new tutorial might be wise... "Aiming, Tracking, LookAts, and Billboarding" (or similar). All about making stuff aim-at or follow other stuff. - Teaches about the unwanted z-rotation problems of billboarding when nearing poles. - Tells about targets and lockedTargets. - Getting and setting directions for ALL types of nodes. Perhaps teach Up(), Forward(), and maybe POV stuff. - Teaches how to build a lockedLookAt() (when camera is the target, mesh lockedLookAt == billboardMode, right? hmm.) - Shows how to derive directions from one thing to another, and what can be done with those directions and magnitudes. - Getting distances (maybe) You know... cool aim-at junk... for dummies... like Wingnut. Thinkin' But yeah, ziguri (and anyone else), if you DID search our docs, can you tell us what words you tried? 'aim'? 'direction'? 'face'? 'lookAt'? 'towards'? *shrug*. (thx) ziguri and Gijs 2 Quote Link to comment Share on other sites More sharing options...
ziguri Posted April 20, 2018 Author Share Posted April 20, 2018 Hey wingnut, it's true i was not able to find the Billboard function. That's why i tried to implement it by myself. A tutorial would be great - a small official Playground Example even better. I was looking for: - React on camera rotation / movement - Mesh facing camera - mesh rotation matrix camera.onViewMatrixChangedObservable did help me. A hint from this observale to billboard would be great too. Thanks for your work and effort! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.