Clamp Pan on X

I want to clamp x axis paning please help how i do that ?
Like Min -80
and Max 80

 var camera = this.entity.camera;
        posx = Math.ceil(camera.entity.getLocalPosition().x);
        distance = this.orbitCamera.distance;



        camera.screenToWorld(screenPoint.x, screenPoint.y * 0, distance, fromWorldPoint);
        camera.screenToWorld(this.lastPoint.x, this.lastPoint.y * 0, distance, toWorldPoint);

        console.log(Math.ceil(camera.entity.getLocalPosition().x));


        worldDiff.sub2(toWorldPoint, fromWorldPoint);
        this.orbitCamera.pivotPoint.add(worldDiff);

The math API has a clamp() method you can use: math | PlayCanvas API Reference

I tired but i know don’t where i use math clamp can you please me where

Can you post a link to your project?

Sorry this project is private can you please tell I share the code

 var fromWorldPoint = MouseInput.fromWorldPoint;
        var toWorldPoint = MouseInput.toWorldPoint;
        var worldDiff = MouseInput.worldDiff;


        var camera = this.entity.camera;
        distance = this.orbitCamera.distance;





        camera.screenToWorld(screenPoint.x, screenPoint.y * 0, distance, fromWorldPoint);
        camera.screenToWorld(this.lastPoint.x, this.lastPoint.y * 0, distance, toWorldPoint);

        console.log(toWorldPoint);
        console.log(fromWorldPoint);





        worldDiff.sub2(toWorldPoint, fromWorldPoint);
        this.orbitCamera.pivotPoint.add(worldDiff);

Please help me i want to limit x axis paning please help anyone

MouseInput.prototype.pan = function (screenPoint) {

    if (msd) {

        var fromWorldPoint = MouseInput.fromWorldPoint;

        var toWorldPoint = MouseInput.toWorldPoint;

        var worldDiff = MouseInput.worldDiff;

        var camera = this.entity.camera;

        distance = this.orbitCamera.distance;

        console.log(fromWorldPoint);

        console.log(toWorldPoint);

        camera.screenToWorld(screenPoint.x, screenPoint.y * 0, distance, fromWorldPoint);

        camera.screenToWorld(this.lastPoint.x, this.lastPoint.y * 0, distance, toWorldPoint);

        worldDiff.sub2(toWorldPoint, fromWorldPoint);

        this.orbitCamera.pivotPoint.add(worldDiff);

    }

};

I’m not sure of the effect that you are looking for.

Do you want to clamp the range of X on the World axis where it has to be between -8 and 8 for example or do you want to only pan on the World X axis?

If that’s the case, clamp the x property of this.orbitCamera.pivotPoint after adding worldDiff


Here is example what i mean i want to limit x axis

Please tell me and you have any example

Adding the worldDiff is what pans the camera on all 3 axis of the world. If you only want it to move on X, then zero out the Y and Z property of worldDiff before adding it to the pivot point.

Sir you have any code example please

Example code?

@Jack I will do my best to jump in here but I think there is confusion on what you would like to have as a solution. I will take a stab at what you are asking but the information is sketchy and since your project is private we are doing our best to understand. So you would like the following I think. Your x pan is to be clamped.

-80---------------------------0------------------------------80< this is x clamp preferred.

@Devortel and @yaustar have offered a solution to use pc.math.clamp Definition here and also in the documentation provided above.

image

So I think that you would use pc.math.clamp(xItemToClamp,-80,80) This will return the value of the clamped number. Others can verify.

Here are more examples of clamp from a forum search.
https://forum.playcanvas.com/search?q=clamp

There are several examples contained that relate I think to your question. I realize that you are expecting an out of the box solution but would suggest that you experiment with what has been sent. The forum search is a great resource. Hope this will help.

1 Like


I just want to limit x pan i dont understand your point

Is this what you want?

https://playcanvas.com/project/1011422/overview/f-model-viewer-clamp-x

If so:

MouseInput.prototype.pan = function(screenPoint) {
    var fromWorldPoint = MouseInput.fromWorldPoint;
    var toWorldPoint = MouseInput.toWorldPoint;
    var worldDiff = MouseInput.worldDiff;
    
    // For panning to work at any zoom level, we use screen point to world projection
    // to work out how far we need to pan the pivotEntity in world space 
    var camera = this.entity.camera;
    var distance = this.orbitCamera.distance;
    
    camera.screenToWorld(screenPoint.x, screenPoint.y, distance, fromWorldPoint);
    camera.screenToWorld(this.lastPoint.x, this.lastPoint.y, distance, toWorldPoint);

    worldDiff.sub2(toWorldPoint, fromWorldPoint);
       
    // Remove Y and Z movement
    worldDiff.y = 0;
    worldDiff.z = 0;

    this.orbitCamera.pivotPoint.add(worldDiff);    

    // Clamp X
    this.orbitCamera.pivotPoint.x = pc.math.clamp(this.orbitCamera.pivotPoint.x, -4, 4); 
};
1 Like

Finally Thanks man really appreciated