# dynamically position

## Recommended Posts

How can I dynamically do spheres be created and according to a numbering that I enter make the spheres position themselves in this way as the example shows

Can someone show an example? Thanks

The example is below

##### Share on other sites

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.

##### Share on other sites

I've got this weird feeling that you're trying to make us your homework. Please tell me I'm wrong!

David

##### Share on other sites

2 hours ago, davrous said:

I've got this weird feeling that you're trying to make us your homework. Please tell me I'm wrong!

David

You're wrong i don't 'study i just wanna do this for a game idea

##### 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;

};

##### 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 ?

##### Share on other sites

Good job with the playground!

I tired to simplify it a bit, not sure if i succeeded: http://www.babylonjs-playground.com/#XALW2#1

The positions might not be exactly right, but maybe you can play around and make it better.

Does that help?

##### Share on other sites

6 hours ago, iiceman said:

Good job with the playground!

I tired to simplify it a bit, not sure if i succeeded: http://www.babylonjs-playground.com/#XALW2#1

The positions might not be exactly right, but maybe you can play around and make it better.

Does that help?

thanks iiceman, i will study the code now

##### Share on other sites

I would say, lets make them swim

edit:mother with little fishy children, so the mother try to teach how to

##### Share on other sites

You can use an arc rotate camera

##### Share on other sites

3 hours ago, JohnK said:

You can use an arc rotate camera

but in that way only spin 180

##### Share on other sites

21 minutes ago, Nabroski said:

Thank you.

I found the nice advice to set the limits to null!

It is useful for me!

##### Share on other sites

the funny thing is i was looking around for a good implementation. i found a math formula, and i said, okay, okay no need to hurry, maybe in 2-3 weeks or something ...

##### Share on other sites

@iiceman IS A GANGSTA CODER!!!

##### Share on other sites

actually... I just google things, forgot to give the source, here it is:

...credit goes to Deltakosh... as always

##### Share on other sites

@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)

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

##### Share on other sites

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

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.