Thursday, April 29, 2021

Physics Engine

Physics Engine


Matter.Engine:

The Matter.Engine module contains methods for creating and manipulating engines. An engine is a controller that manages updating the simulation of the world. See Matter.Runner for an optional game loop utility. 

Read more...

Matter.Bodies:

The Matter.Bodies module contains factory methods for creating rigid body models with commonly used body configurations (such as rectangles, circles and other polygons).

Read more...

Matter.World:

This module has now been replaced by Matter.Composite.

All usage should be migrated to the equivalent functions found on Matter.Composite. For example World.add(world,body) now becomes Composite.add(world,body).

For back-compatibility purposes this module will remain as a direct alias to Matter.Composite in the short term during migration. Eventually this alias module will be marked as deprecated and then later removed in a future release.

Read more...

Codes:

const Engine = Matter.Engine;
const World = Matter.World;
const Bodies = Matter.Bodies;

var engine, world;

function setup() {
  createCanvas(400400);

  engine = Engine.create();
  world = engine.world;

  var ground_options = {
    isStatic: true,
  };

  var ball_object = {
    restitution: 1.0,
  };

  ground = Bodies.rectangle(20039040020, ground_options);
  World.add(world, ground);

  ball = Bodies.circle(20010020, ball_object);
  World.add(world, ball);

  console.log(ground);
}

function draw() {
  background(0);

  Engine.update(engine);

  rectMode(CENTER);
  rect(ground.position.x, ground.position.y, 40020);

  ellipseMode(RADIUS);
  ellipse(ball.position.x, ball.position.y, 2020);
}



Video:






Previous Post
Next Post

post written by:

0 Comments: