Jump to content

I need help with drawing in Babylon js


Maria D
 Share

Recommended Posts

Hi! I'm trying to learn Babylon js and it's my first time using it ☺️.

I'm doing a kind of planetary system and the planet's movement can be changed using a slider. I also draw a circle made with lines (the orbit) to show the path followed by the planet when the slider also changes. But I have problem: I don't know how to remove the  previous drawn circle. So as a result when the planet changes its orbit, many circles are still drawn.

Something like this:

image.thumb.png.18b9568e1c3e7540dd422866fbdf4553.png

Here is a part of my code inside createScene function:

 

//Creation of slider
var slider = new BABYLON.GUI.Slider();
slider.minimum = 0;
slider.maximum = 1;
slider.value = 0;
slider.paddingRight="10";
slider.horizontalAlignment= BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
slider.height = "20px";
slider.width = "200px";
slider.top="10";
slider.color="blue";
for(var i = 0; i < div; i++){
divArray.push(Math.PI*(MitadDiv*i));
}
slider.onValueChangedObservable.add(function(value) {
 
e = value;
a = Math.sqrt(-(b*b)/((e*e)-1));
text.text = "Excentricidad: "+(value);
for(var i = 0; i < divArray.length; i++){
Path.push(new BABYLON.Vector3((b * Math.cos(divArray[i])+offset.x), (0+offset.y), (a * Math.sin(divArray[i])+offset.x)));
}
var lines = BABYLON.MeshBuilder.CreateDashedLines("lines", {points: Path, dashNb:500}, scene);
 
});
guiManager.addControl(slider);
 
scene.beforeRender = function () {
 
planet.position = new BABYLON.Vector3((b * Math.cos(Math.PI*(MitadDiv*alpha))+offset.x), (0+offset.y), (a * Math.sin(Math.PI*(MitadDiv*alpha))+offset.x));
sun.rotate(BABYLON.Axis.Y, Math.sin(-0.001), BABYLON.Space.WORLD);
planet.rotate(BABYLON.Axis.Y, Math.sin(2 * -Math.PI/180), BABYLON.Space.WORLD);
alpha += 0.09;
 
 
};
 
 
 
 
 
return scene;

Thanks!!!

 

 

Link to comment
Share on other sites

  • 3 months later...

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