Jump to content

[solved] Rotate Mesh based on Camera Rotation in Alpha AND Beta


ziguri
 Share

Recommended Posts

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.

Link to comment
Share on other sites

  • ziguri changed the title to Rotate Mesh based on Camera Rotation in Alpha AND Beta
  • ziguri changed the title to [solved] Rotate Mesh based on Camera Rotation in Alpha AND Beta

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)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...