Jump to content

[Solved] How to make UniversalCamera rotate without mouse down?


ShiftedClock
 Share

Recommended Posts

Hi Steven,

Here is one way -- paste this into your createScene function:

        // other stuff ...

    var
    rotationRate = .00002,
    winCntrX = engine.getRenderWidth(true)/2,
    winCntrY = engine.getRenderHeight(true)/2;

    window.addEventListener("resize", function () {// in case user adjusts window
        engine.resize();
        winCntrX = engine.getRenderWidth(true)/2,  // current screen center X
        winCntrY = engine.getRenderHeight(true)/2; // current screen center Y
    });


    scene.registerBeforeRender(function(){
        // other stuff ...
        var
           mx  = (scene.pointerX-winCntrX) * rotationRate, // get rotation increments
           my  = -(scene.pointerY-winCntrY) * rotationRate;
        camera.rotation.y += mx; // increment rotation
        camera.rotation.x += -my;
        if (camera.rotation.x > Math.PI/2.2) camera.rotation.x = Math.PI/2.2;  // up limit
        if (camera.rotation.x < -Math.PI/2.2) camera.rotation.x = -Math.PI/2.2;  // down limit

        // other stuff ...
    });

 

Here's an example: https://www.babylonjs-playground.com/index.html#PFC6AM

Have fun!    ?

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