ShiftedClock

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

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!    💥

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.