Jump to content

Camera, onChangePosition


Visam
 Share

Recommended Posts

5 minutes ago, Pryme8 said:

when are you changing the position? is it in a callable function?  just add a secondary function?

 

of course I can add event listeners like this canvas.addEventListener("mousewheel", function (evt)....

several event listeners for different events.

but for me most important thing is to know when a camera position changed to do smth.

it means, instead of adding many event listeners, add only one.

Link to comment
Share on other sites

3 minutes ago, Pryme8 said:

You obviously have a function that changes the position of the camera... 

not always.

for example, a camera position will be changed when a user uses a mouse wheel for ArcRotateCamera. or arrows for FreeCamera.

Link to comment
Share on other sites

3 minutes ago, Pryme8 said:

post the script ill show you where the response is. and show you where to strap a callback.

lets take a look at the Babylon's example

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

N3 Rotation and Scaling

var createScene = function () {
    var scene = new BABYLON.Scene(engine);

    var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI, Math.PI / 8, 150, BABYLON.Vector3.Zero(), scene);

    camera.attachControl(canvas, true);

    var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);

    //Creation of 3 boxes and 2 spheres
    var box1 = BABYLON.Mesh.CreateBox("Box1", 6.0, scene);
    var box2 = BABYLON.Mesh.CreateBox("Box2", 6.0, scene);
    var box3 = BABYLON.Mesh.CreateBox("Box3", 6.0, scene);
    var box4 = BABYLON.Mesh.CreateBox("Box4", 6.0, scene);
    var box5 = BABYLON.Mesh.CreateBox("Box5", 6.0, scene);
    var box6 = BABYLON.Mesh.CreateBox("Box6", 6.0, scene);
    var box7 = BABYLON.Mesh.CreateBox("Box7", 6.0, scene);

    //Moving boxes on the x axis
    box1.position.x = -20;
    box2.position.x = -10;
    box3.position.x = 0;
    box4.position.x = 15;
    box5.position.x = 30;
    box6.position.x = 45;

    //Rotate box around the x axis
    box1.rotation.x = Math.PI / 6;

    //Rotate box around the y axis
    box2.rotation.y = Math.PI / 3;

    //Scaling on the x axis
    box4.scaling.x = 2;

    //Scaling on the y axis
    box5.scaling.y = 2;

    //Scaling on the z axis
    box6.scaling.z = 2;

    //Moving box7 relatively to box1
    box7.parent = box1;
    box7.position.z = -10;

    return scene;
}

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