Skip to content

Create simple Scene

tecno-master edited this page Aug 8, 2024 · 1 revision

In order to render/simulate something you will need to create a scene. A Scene is an object that can hold spheres and constraints. Solvers require a scene in order to step the simulation.

Step 1: Create a scene

Scene scene = Verlet.createScene();

Step 2: Create spheres and add them to the scene
Creates a sphere at the coordinates (0, 0) with a radius of 50

Sphere sphere = Verlet.createSphere(0, 0, 50);
scene.addSphere(sphere);

Step 3: Create constraints and add them to the scene
Constraints are important, because once your simulation is running, your spheres would fall into the endless void without atleast one constraint.
Adds a RectangleConstraint, which is centered and has a width and height of 1000.

Constraint constraint = new RectangleConstraint(1000, 1000);
scene.addConstraint(constraint);

If you feel the need to remove a sphere or a constraint you can do that with the remove methods.

scene.removeSphere(sphere);
scene.removeConstraint(constraint);

Full code:

Scene scene = Verlet.createScene();

Sphere sphere = Verlet.createSphere(0, 0, 50);
scene.addSphere(sphere);

Constraint constraint = new RectangleConstraint(1000, 1000);
scene.addConstraint(constraint);

Clone this wiki locally