Jump to content

dynamically position


JimmyBuchman
 Share

Recommended Posts

Sequence of numbers a(0), a(1), a(2). Let gap be 2 * sphere diameter + a bit. For a(i) having s spheres set the x position of a sphere to be i * gap  and the y position of the sphere be k * gap  for 0 ≤ k < s

Use this idea to produce a playground any more questions easier to refer to playground.

Link to comment
Share on other sites

5 hours ago, JohnK said:

Sequence of numbers a(0), a(1), a(2). Let gap be 2 * sphere diameter + a bit. For a(i) having s spheres set the x position of a sphere to be i * gap  and the y position of the sphere be k * gap  for 0 ≤ k < s

Use this idea to produce a playground any more questions easier to refer to playground.

JohnK, you think i'm in the right way ? if I change de values everything goes wrong


 

var createScene = function () {

    // This creates a basic Babylon Scene object (non-mesh)
    var scene = new BABYLON.Scene(engine);

    // This creates and positions a free camera (non-mesh)
    var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -149), scene);
    camera.attachControl(canvas, true);

    // This targets the camera to scene origin
    camera.setTarget(BABYLON.Vector3.Zero());

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

    // Default intensity is 1. Let's dim the light a small amount
    light.intensity = 0.7;

    
    // Spheres
    var spheresCount = 5;
    var p=[1,3,1];
    var alpha = 0;
    var alfay=0;
    var atual = 0;
  
    var x=[];
    var y=[];
    var boo = true;
    for (var index = 0; index < 3; index++) {
      
        
        if(p[index]==1){
            
            console.log('if');
              var sphere = BABYLON.Mesh.CreateSphere("Sphere" + index, 32, 4, scene);
              sphere.position.x = 10 * Math.tan(alpha+5);
      
        }else{
            console.log('else');
             console.log(p[index]);
            for(j=0;j<p[index];j++){
            var sphere = BABYLON.Mesh.CreateSphere("Sphere" + index, 32, 4, scene);
           sphere.position.y = 10 * Math.tan(alfay+5);
            sphere.position.x = 10 * Math.tan(auxx);
            alfay += (2 * Math.PI) / spheresCount;
         
            }
              
        }
       
       
       alpha += (2 * Math.PI) / spheresCount;
       
        
    }
  
    
    return scene;

};

Link to comment
Share on other sites

6 hours ago, JohnK said:

Sequence of numbers a(0), a(1), a(2). Let gap be 2 * sphere diameter + a bit. For a(i) having s spheres set the x position of a sphere to be i * gap  and the y position of the sphere be k * gap  for 0 ≤ k < s

Use this idea to produce a playground any more questions easier to refer to playground.

if i use an array = [1,3,1] its go fine but if i put an array [1,3,1,2] when i get on the number 2, the position.x goes wrong

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

what can i do ?

Link to comment
Share on other sites

29 minutes ago, iiceman said:

@JimmyBuchman I am not sure what you mean by layer by layer... like that: http://www.babylonjs-playground.com/#XALW2#13 -> click spheres (has a bug, sometimes if you click them in the wrong order it draws a wrong connection)

Something like this, but this has to do automatically, loke the image below. I can already make this connection, but have some problem that is not following the matrix of weights correctly.

thi is the code i'm using, unfortunately it wont work in the playground, but there it is > http://www.babylonjs-playground.com/#2AV3DG#0

iceman.png

Link to comment
Share on other sites

@JimmyBuchman -

Perhaps everyone is overthinking this - if I understand the original question correctly. It appears you only want to translate the objects, sprites, or whatever in X and Y - so if you will be maintaining their Z as a constant (in relation to the camera and world space), then in using a pick == true function, simply test using the following function to read your canvas cursor position and print to the console (or echo to the canvas) to use to build a function to calculate the math required to translate your objects in your final translation function. The function below will only print your canvas X,Y cursor values to the JS console:

onmousemove = function(e){console.log("mouse location:", e.clientX, e.clientY)}

Again, the above is simply a function to write to the JS console to calculate the cursor values needed for your actual function to move your objects in X and Y; so begin simply by placing this function into a script and print your canvas cursor positions to the JS console to calculate the pick and delta (X.Y move) positions. To ultimately use this in your scene as I believe you initially described, convert the X,Y cursor positions to apply as a delta on each picked object in X and Y in your BJS scene.

DB

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