GithubHelp home page GithubHelp logo

lasselindqvist / dyn4j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dyn4j/dyn4j

0.0 2.0 0.0 9.31 MB

Java Collision Detection and Physics Engine

Home Page: http://www.dyn4j.org

License: BSD 3-Clause "New" or "Revised" License

HTML 0.04% Java 99.96%

dyn4j's Introduction

alt tag

Java Collision Detection and Physics Engine

A 100% Java 2D collision detection and physics engine. Designed to be fast, stable, extensible, and easy to use. dyn4j is free for use in commercial and non-commercial applications.

The project is comprised of the main project and tests managed here and two others:

  • dyn4j-samples A collection of samples to help get started
  • dyn4j-sandbox A non-trivial desktop application that allows users to build scenes, run, save, and load them - all built with dyn4j as the simulation engine.

Requirements

  • Java 1.6+

Getting Started

dyn4j comes with a lot of features and extensibility, but getting started is easy.

Step 1 Add dyn4j to Your Project

Add dyn4j to your classpath by downloading a release from Releases or Maven Central

Or by adding a Maven dependency:

<dependency>
    <groupId>org.dyn4j</groupId>
    <artifactId>dyn4j</artifactId>
    <version>3.2.4</version>
</dependency>

Step 2 Create a World

World world = new World();

This create a new simulation environment with default settings. The default settings use the meter-kilogram-seconds system and include the default pipeline classes.

Step 3 Add Some Bodies

Body body = new Body();
body.addFixture(Geometry.createCircle(1.0));
body.translate(1.0, 0.0);
body.setMass(MassType.Normal);
world.addBody(body);

A body is the primary unit of simulation and completely rigid. A body is comprised of many fixtures or shapes. While the shapes of dyn4j are all convex (and must be), a collection of these shapes can be used to create a body that is not. A body can be initially placed in a scene by translating or rotating it. Once the shape(s) of a body is defined, it must be given a mass. The mass is typically MassType.NORMAL or MassType.INFINITE. When set to NORMAL, the mass will be calculated based on the shapes. An INFINITE mass body might represent a floor, ground, or something unmovable.

Step 4 Add Some Joints

PinJoint joint = new PinJoint(body, new Vector2(0, 0), 4, 0.7, 1000);
world.addJoint(joint);

A joint is a constraint on the motion of one or more bodies. There are many joint types that serve different purposes. Generally, joints are used to link bodies together in a specified way. Bodies can have multiple joints attached to them making for some interesting combinations.

Step 5 Run the Simulation

for (int i = 0; i < 100; i++) {
    world.step(1);
}

In a GUI based application you would call the World.update(elapsedTime) method. Either way, each time the world is advanced forward in time (which may or may not occur when using the World.update(elapsedTime) methods) the bodies added to it will be moved based on the world gravity (if any) and will interact with other bodies placed in the world.

Next Steps

From here you should take a look at the dyn4j-samples sub project to get a jump start with a simple Java2D framework. You can also check out the documentation here.

Links

Building

  • Maven build goals: clean package
  • Check artifact class version: ** javap -verbose -classpath /path/to/jar/dyn4j.jar org.dyn4j.Version 50 ** javap -verbose -classpath /path/to/jar/dyn4j.jar module-info 53+

dyn4j's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.