Jump to content

ArcCamera turning problem, need solution =]


Ariel Yust
 Share

Recommended Posts

Hello once more =]

 

recently Babylonjs was update to 1.9.0 again :P and this time the camera turning by a mouse drag was disabled...

instead the arrow keys started to turn the world around the camera, wierd stuff.

 

I'd like to know how to disable the keys and bring back the mouse dragging, also I'd like to know how can I invert the mouse dragging camera direction turn (if that made any sense) :P

 

"Invert the mouse dragging camera direction turn" = when I drag mouse left the camera turns right unlike the previous babylonjs versions, where when I drag left the 

camera also turned left... so ye

 

Help would be appreciated =]

 

btw here is the code im using that makes the draging work, of course it's a prototype just for testing =]

var lastMouseX = -1, lastMouseY = -1, dx = 0, dy = 0, MouseMode = false;;        window.addEventListener("mousedown", function (evt) {            MouseMode = true;        });        window.addEventListener("mouseup", function (evt) {            MouseMode = false;            dx = 0;        });        window.addEventListener("mousemove", function (evt) {            if (MouseMode) {                if (lastMouseX == -1 || lastMouseY == -1) {                    lastMouseX = evt.clientX;                    lastMouseY = evt.clientY;                }                else {                    dx = lastMouseX - evt.clientX;                    dy = lastMouseY - evt.clientY;                }            }        });        Shared.Scene.registerBeforeRender(function () {            Shared.Camera.alpha += 0.0001 * dx;        });

is there a better way ? I'm sure this is already implemented in babylon... isn't it?

Link to comment
Share on other sites

Hi Ariel!  Good to hear from you again!

 

Mouse-drag camera movement was NOT disabled in BJS 1.9.0.  I use it all the time.  Are you sure that hand.js is being loaded-in by a <script> element in your source code?  I think it is needed.  Report back if/when you can... and also tell us which browser(s) you are using.

 

MAYBE... you will need to make a modified hand.js... to reverse your mousing directions.  Smarter people than I... may add more answers... soon.  Take care!

Link to comment
Share on other sites

Hi Wingnut, thanks for the help buddy!

 

I'm loading the latest hand.js as you can see in the picture, but nothing happens.

 

Instead, I wrote my own dragging system using the window events and babylon.js registerBeforeRender (a system that works just like on mobile phone's scroll by dragging),

but I'm sure that the babylon.js code exists in the background may be on may be off... should I disable or use it that's the question... because I'd like to disable it because my latest code works better for my needs.

 

I also would like to override the arrow keys for the scrolling, can that also be done ?

 

Oh and I don't want to mess with people's libraries and change them... because I don't want to maintain them in the future, the moment someone updates his script,

I'd have to look for the changes I made and do them again to the new script... so ye, I don't want that :P

post-5734-0-33627600-1395296772.png

Link to comment
Share on other sites

 

Oh and I don't want to mess with people's libraries and change them... because I don't want to maintain them in the future, the moment someone updates his script, I'd have to look for the changes I made and do them again to the new script... so ye, I don't want that

 

:)  Well, you would make your own script... starting with a normal working hand.js.  Create ariel_hand.js... make it work how YOU want it to work, and then it travels with your project, forever, and you never update it to newer versions.  *shrug*  Be sure to give some credit to the person who wrote hand.js... because you would be using MOST of that person's code... in your 'special' version.

 

 

I also would like to override the arrow keys for the scrolling, can that also be done ?

 

http://doc.babylonjs.com/page.php?p=24622

 

Look for keysDown, keysLeft, keysRight, keysUp.  Check your camera.  There are numbers in those properties by default, I think.  Empty those properties on your camera, and that will disable its keypresses.  By the way, using those properties is also how you change your camera to work with WASD controlling, too... should you ever need that.  Hope this helps.  Be well.

Link to comment
Share on other sites

try to return has a previous version of Hand.js.

 

I want the latest version and don't want to modify hand.js.

 

Look for keysDown, keysLeft, keysRight, keysUp.  Check your camera.  There are numbers in those properties by default, I think.  Empty those properties on your camera, and that will disable its keypresses.  By the way, using those properties is also how you change your camera to work with WASD controlling, too... should you ever need that.  Hope this helps.  Be well.

 

Thank you, Wingnut, for your research!  :) 

 

I was looking at these properties, even switched between the numbers to flip scrolling, in debugging I could see that the change was made, but, nothing happens...

I mean... the scroll with keys turns to the same way even after my change - wierd :P tried to clear cache, still same issue...

 

Do you know another way that I can use to switch the keys or disable them ?

I don't need the mouse turning because I'm using my own system now, but I fear that the original will come back once a new BabylonJs version arrives...

if there could be a way to disable it as well just in case  :rolleyes:

Link to comment
Share on other sites

Hi Again, AY.

 

Here is my function that I use to change all cameras to WASD control...

var adjustCameraKeys = function() {	var cam,c;	// switch the hot keys.	for (cam in scene.cameras) {		c = scene.cameras[cam];		c.keysUp = [87]; // w		c.keysLeft = [65]; // a		c.keysDown = [83]; // s		c.keysRight = [68]; // d	}}

I'm not sure what else I can offer.  You do realize that it is not a permanent change, right?  If you remove that camera from the scene, and then add it again later, you need to re-run the cam keys adjusting function. So, for you, you would create all the cameras you need, then...

var clearCameraKeys = function() {	var cam,c;	// clear the camera keys.	for (cam in scene.cameras) {		c = scene.cameras[cam];		c.keysUp = [];		c.keysLeft = [];		c.keysDown = [];		c.keysRight = [];	}}

Or, do a single camera without a function or loop...

		mycam.keysUp = [];		mycam.keysLeft = [];		mycam.keysDown = [];		mycam.keysRight = [];

That should work, as best I can tell.  Remember, it is not permanent.  If you remove the camera, and then add it again, then you will need to re-clear the keys.  Keep us posted.  Good luck, be well.

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