Jump to content

Mesh facing the camera


Ahiru
 Share

Recommended Posts

Maybe I am just a bit slow understanding, but how can I actually bring a mesh to face the camera? (And further more: Only do that turning around its local "Z"-Axe)

Here my trials so far:

http://playground.babylonjs.com/#12U7QB#2

Even tried to find out the angle between the actual rotation and the camera, but the actual rotation does not really look right?

Link to comment
Share on other sites

how can I actually bring a mesh to face the camera? 

 

I added a feature in Babylon 2.2 that is available since yesterday: getFrontPosition (distance) to place an object in front of the camera and whatever the rotation and position of the camera.

 

exemple:

sphere.position = camera.getFrontPosition(12); //Sphere has 12 unit front the camera.

This what you were asking?

Link to comment
Share on other sites

No - nice function, but probably not what I need at the moment.

 

You see the cylinder lying on the box, right? And I want it to turn its face always to the camera. (But without standing up - it still has to lie flat like it does now - only this movement like shown at the moment allowed)

Link to comment
Share on other sites

If you want to rotate a mesh into a known target system (ex : cube top sides and camera axis) so it always face the cam, you may use Vector3.RotationFromAxis() to get the needed rotation angles.

 

doc : http://doc.babylonjs.com/overviews/How_Rotations_and_Translations_Work  ("generating a rotation from a target system" part)

ex : http://www.babylonjs-playground.com/#VYM1E#5

Link to comment
Share on other sites

Well - it can't completely face you, because it's fixed on the "Ship" - maybe it's clearer now like this? http://playground.babylonjs.com/#12U7QB#5

 

So it can't completely face you (only when the box is aligned correctly), but it can at least turn in your direction on the axis it CAN move. I tried to find out the angle, so I can put it into the quaternion rotation, but I am still not sure how to find this angle. If the cannon would move like you suggested it will break the ship :D

Link to comment
Share on other sites

Hmm, I see... well, then I don't know either :P

Just an idea: maybe you can make them use the same (imaginary) plane for the calculation and then rotate according to that?

Trying to illustrate the idea: http://playground.babylonjs.com/#12U7QB#8

By the way: how do I get the coordinates of a mesh in world space?? I somehow couldn't figure it out... might be too late... or just my lack of knowledge... but please tell me :D

Link to comment
Share on other sites

plane.position = cylinder.getAbsolutePosition(); (Don't get confused by the console.log show 0,0,0 - if you expand it the real numbers are shown - no idea why that is)

 

But I am struggling with getting the "absolute" rotation of the cylinder. After I rotate it with the .rotate() function - which is done with quaternions - the rotation is always (0,0,0). So now I try to find out how to rotate with quaternions manually.

 

Because how much I have to turn depends not only on the cylinders position, but also on the rotation, right?

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...