Jump to content

ArcRotateCamera does not correctlly use upVector


chadautry
 Share

Recommended Posts

I don't believe ArcRotateCamera correctly uses the upVector.  Instead of getting into my use case, I've setup some playground demonstrations.

 

Playground 1: This is the default. upVector is Y+. 

Behavior: Move the mouse left, spins clockwise around the Y axis. Move the mouse right, spins counter clockwise. Move the mouse up, pushes the Y+ axis away from the screen, move the mouse down, pulls the Y+ axis towards the screen.

http://www.babylonjs-playground.com/#2K6AJC#2

 

This default works as expected.

 

 

Playground 2: Set the upVector to Z+

Expected Behavior: Move the mouse left and right should spin around the Z axis. Move the mouse up and down should pull the Z axis towards and away from the screen. Unfortunately, that is not the actual behavior.

http://www.babylonjs-playground.com/#2K6AJC#3

 

Thanks

Link to comment
Share on other sites

That could be it. I'm trying browse the code to figure out where to change it to use upVector for the controls. But always hard looking at unfamiliar code.

 

I'd definitely say it is an issue not using upVector in the controls as well as the drawing orientation. Kinda makes upVector pointless for the camera.

 

 

Is there a suggested work around I'm not aware of?

I'm trying to re-write an existing system to use Babylon.js, so changing the scene's co-ordinate system to work with the camera is quite a bit of re-work I don't want to do.

Link to comment
Share on other sites

Re-writting http://chad-autry.github.io/hex-grid-map/#/demo to use Babylon.js

For that framework I have the cartesian co-ordinate system aligned with the screen co-ordinates, so that means the hex grid is flat on the Z=0 

 

Basically the two world co-ordinate systems aren't the same. I'd like to get the nice behavior without re-writting my frameworks co-ordinate system.

Link to comment
Share on other sites

Yeah, I played around with it some. The controls are just changing the alpha and beta angles,

 

I think the point of change is actually https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/babylon.arcRotateCamera.ts#L521

 

Tried hacking it up a bit without total understanding and only managed to break it. I need to dig in and comprehend the trig there, I just swapped x --> y --> z --> x is obviously not what needs to happen.

Link to comment
Share on other sites

Ok, by swapping Y and Z  at lines

 

https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/babylon.arcRotateCamera.ts#L497

https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/babylon.arcRotateCamera.ts#L499

https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/babylon.arcRotateCamera.ts#L504

https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/babylon.arcRotateCamera.ts#L521

 

I'm getting the behavior I'm wanting.

 

I'll try to get an official pull request going where it uses the upVector to set everything. (It may take quite some time, getting an equivalent re-write of my framework with rotation disabled takes priority for me)

 

 

 

Of further interest: I notice that as I spin the scene with the mouse I get a very pronounced movement of my view point compared to the plane. At first I thought it was all about rounding errors (the target vector is being edited on every rotation increment) But interestingly it only happens with the mouse and not the keyboard. I'll have to investigate further.

Link to comment
Share on other sites

  • 2 years later...

I have tried to swap the controllers for keys, (please see: http://www.babylonjs-playground.com/#A83GX#30) but only succeeded partially. While rotating around the z axis (i.e. the new up vector) worked fine, rotation around the other axes lead to some strange effects. In the playground, this can be seen best by rotation around y by pressing the up/down keys. Rotation works fine until you cross the point where the up vector coincides with the view vector, after which the orientation of the y axis changes direction.

While this is somewhat understandable mathematically, this seems to be handled consistently with the default up vector (0, 1, 0), where I can rotate in all directions without any such "discontinuities". I was looking for any special handling for this in the Babylon sources, but was not able to find anything.

Any ideas, hints  to where to look?

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