Jump to content

free camera rotation?


Xav
 Share

Recommended Posts

Hello,

I think I am not very well understood the function of the rotation properties on a free camera ...
Watch this playground:

http://www.babylonjs-playground.com/#HAAJ3#0

Why does my variable rot changed?
I think I must be so tired to understand the problem :(

If someone has an explanation for this problem thank you.


Ps: It works very well with an arcRotatecamera by adjusting Alpha and Beta values.

Thanks ;)

Link to comment
Share on other sites

@Deltakosh There seems to be something wrong when assigning something to a Vector3 method like .position or .rotation, I've noticed this behavior before and I thought that I was doing something wrong, what I did is create two box meshes "Box1" and "Box2" and set :

box1.position = box2.position;

This somehow affected the box2.position.

And @Xav's example shows exactly whats wrong, but using a variable instead.

camera.rotation=rot; 

Is also acting like :

rot = camera.rotation; 

 

Link to comment
Share on other sites

Object assign in JavaScript won't create a copy but a reference.

When you say camera.rotation = rot; and later change rot, camera rotation will change as well. It is a reference to the same object. The only object types that are being copied and not referenced are the primitives (numbers, string, booleans). 

So, this is just the way JavaScript works. Want to prevent that? use the clone() function of the vector (box1.position = box2.position.clone()). this will create a standalone clone with the same details of the original vector3.

Just to explain what happens in the demo - 

after clicking you assign camera.rotation = rot. Then you change the camera rotation object, which is now the rot variable. so they both change (they are the same object). Then you click again, but rot is already camera.rotation. And nothing happens. camera.rotation.copyFrom(rot) will be the right way to go here.

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