Code Monkey home page Code Monkey logo

dyn4j's Introduction

alt tag

Actions Status License Language Java Maven Central javadoc Code Coverage

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 a samples project:

Requirements

  • Java 1.6+

Getting Started

dyn4j comes with a lot of features and extensibility, but getting started is easy. If you are looking for a quick start, take a look at the following video.

Getting started with dyn4j

Step 1: Add dyn4j to Your Project

Add dyn4j to your classpath by adding a Maven dependency from Maven Central or GitHub Packages

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

If you are not using Maven you can download the jar from either of the links above.
NOTE: Releases are no longer being created as of 3.4.0.

Step 2: Create a World

World<Body> world = new World<Body>();

This creates a new simulation environment with default settings. The default settings use the meter-kilogram-seconds system and include the default pipeline classes for collision detection, manifold generation, and collision resolution. You can adjust the pipeline classes using the respective methods on the World class and update the settings using the getSettings method.

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 one or more BodyFixtures. Each Fixture has one Shape. 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 by calling a setMass method. The mass type 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 immovable.

Step 4: Add Some Joints

PinJoint<Body> joint = new PinJoint<Body>(body, new Vector2(0, 0));
joint.setSpringEnabled(true);
joint.setSpringDamperEnabled(true);
joint.setMaximumSpringForceEnabled(true);
joint.setSpringFrequency(8.0);
joint.setSpringDampingRatio(0.3);
joint.setMaximumSpringForce(1000.0);
world.addJoint(joint);

A Joint is a constraint on the motion of one or more Bodys. 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. Review each joint's class documentation for details on usage.

Step 5: Run the Simulation

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

Unlike this example, a GUI based application you would call the World.update(elapsedTime) method in it's render loop. 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.

Step 6: Get output from the simulation

After each update of the world, each body's Transform reflects the changes caused by the simulation. Each Body stores it's current position and rotation in a Transform. Using the Transform you can convert from local body space to world space coordinates. For example:

for (Body body : world.getBodies()) {
    // get the updated body center
    Vector2 xy = body.getWorldCenter();
    
    for (BodyFixture fixture : body.getFixtures()) {
        Convex c = fixture.getShape();

        // if your fixture shape has vertices
        if (c instanceof Wound) {
            Wound w = (Wound)c;
            Vector2[] vertices = w.getVerticies();
            for (int i = 0; i < vertices.length; i++) {
                // get the updated fixture vertices
                xy = body.getWorldPoint(vertices[i]);
                // or
                // body.getTransform().getTransformed(vertices[i]);
            }
        }
    }
}

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 full getting started documentation.

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

Contributors

caiquejhones avatar dependabot[bot] avatar harold avatar io7m avatar mtsamis avatar salk31 avatar wnbittle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dyn4j's Issues

Java 9

Hello.

Do you have any plans to publish Java 9 modules for the project? I suspect with the lack of dependencies, you'll have an easier time of it than most.

none UTF8 character in javadoc comment

[javac] /home/chris/development/SpritePlacer2/src/org/dyn4j/collision/manifold/ClippingManifoldSolver.java:47: error: unmappable character for encoding UTF8
[javac]  * Uses Sutherland๏ฟฝHodgman clipping to clip the closest features of the two {@link Convex} {@link Shape}s to obtain

Possibly as my build.xml treats warnings as errors? is there a javadoc UTF8 compatible way to express the included character?

NPE in new World.detect methods

An NPE occurs in some of the new detect methods due to a bug in the code.

You can find a [http://forum.dyn4j.org/viewtopic.php?f=3&t=96#p457 fixed beta 
version here] until a new release is made.

Original issue reported on code.google.com by [email protected] on 24 Apr 2014 at 4:45

WeldJoint fails when bodies have FIXED_LINEAR_VELOCITY

When the one or more of the bodies joined using a WeldJoint have 
FIXED_LINEAR_VELOCITY mass type the joint doesn't constraint the linear motion.

You can get a [http://forum.dyn4j.org/viewtopic.php?f=3&t=96#p457 fixed beta 
version here] until a new release is made.

Original issue reported on code.google.com by [email protected] on 24 Apr 2014 at 4:48

warnings caused by missing overrides

even if you've no use for the overrides, should they not be at least empty methods ?
although the likes of hashcode could come in useful later...

[javac] Compiling 209 source files to /home/chris/development/dyn4j-test/bin
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/dynamics/Step.java:37: warning: [overrides] Class Step overrides equals, but neither it nor any superclass overrides hashCode method
[javac] public class Step {
[javac]        ^
[javac] error: warnings found and -Werror specified
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/dynamics/RaycastResult.java:39: warning: [overrides] Class RaycastResult overrides equals, but neither it nor any superclass overrides hashCode method
[javac] public class RaycastResult implements Comparable<RaycastResult> {
[javac]        ^
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/dynamics/ConvexCastResult.java:37: warning: [overrides] Class ConvexCastResult overrides equals, but neither it nor any superclass overrides hashCode method
[javac] public class ConvexCastResult implements Comparable<ConvexCastResult> {
[javac]        ^
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/geometry/AABB.java:47: warning: [overrides] Class AABB overrides equals, but neither it nor any superclass overrides hashCode method
[javac] public class AABB implements Translatable {
[javac]        ^
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/dynamics/DetectResult.java:35: warning: [overrides] Class DetectResult overrides equals, but neither it nor any superclass overrides hashCode method
[javac] public class DetectResult {
[javac]        ^
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/dynamics/Force.java:36: warning: [overrides] Class Force overrides equals, but neither it nor any superclass overrides hashCode method
[javac] public class Force {
[javac]        ^
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/dynamics/Torque.java:35: warning: [overrides] Class Torque overrides equals, but neither it nor any superclass overrides hashCode method
[javac] public class Torque {
[javac]        ^
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/BinarySearchTreeNode.java:36: warning: [overrides] Class BinarySearchTreeNode overrides equals, but neither it nor any superclass overrides hashCode method
[javac] final class BinarySearchTreeNode<E extends Comparable<E>> implements Comparable<BinarySearchTreeNode<E>> {
[javac]       ^
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/Reference.java:38: warning: [overrides] Class Reference overrides equals, but neither it nor any superclass overrides hashCode method
[javac] public class Reference<T> {
[javac]        ^
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/collision/CategoryFilter.java:93: warning: [overrides] Class CategoryFilter overrides equals, but neither it nor any superclass overrides hashCode method
[javac] public class CategoryFilter implements Filter {
[javac]        ^
[javac] /home/chris/development/dyn4j-test/src/org/dyn4j/geometry/decompose/SweepLineEdge.java:40: warning: [overrides] Class SweepLineEdge overrides equals, but neither it nor any superclass overrides hashCode method
[javac] final class SweepLineEdge implements Comparable<SweepLineEdge> {
[javac]       ^
[javac] 1 error
[javac] 11 warnings

intersecion function performs same calculation as union function

The intersection function in Interval.java perfoms the same calculation as the 
union function. It should be changed to:

public void intersection(Interval interval) {
    if (this.overlaps(interval)) {
        this.min = Math.max(interval.min, this.min);
        this.max = Math.min(interval.max, this.max);
    } else {
        this.min = 0;
        this.max = 0;
    }
}

(because its hard to spot, the change is that the min and max functions have 
been swapped)

Original issue reported on code.google.com by [email protected] on 23 Dec 2013 at 8:50

Infinite Loop in SweepLine

The attached simple polygon causes an infinite loop in the SweepLine algorithm. 
 EarClipping is not experiencing this same problem.

Original issue reported on code.google.com by [email protected] on 6 Jan 2014 at 5:03

Attachments:

Wrong values returned from getRadius(Vector2) method for HalfEllipse

Hello William,
in the org.dyn4j.geometry.HalfEllipse class in the getRadius method you say:

in the half ellipse case, if the point is on the side of the flat edge
then we do the ellipse code, else we can just return the farthest of the
two points that make up the flat side

But this is not true if the height is greater than half the width and the Point is below the evolute of the ellipse. Then it is possible, that the point with the maximal distance is on the ellipse. But this point isn't on the opposite quadrant, as this is a half-ellipse, but on the neighbour quadrant. And to make things worse, there is as well a local minimum. Therefore the distance function isn't unimodal in this quadrant, which has to be for the Golden Section Search.

Thus I suggest to restrict the ellipse further:

grafik

Greetings
Andreas

Originally posted by @TeamFinal in #21 (comment)

null in joint constructor when exporting code via sandbox

What steps will reproduce the problem?
1. open scene in sandbox
2. use a distancejoint in the scene (or for example load the default 
JointCollision scene)
3. export as a java file

What is the expected output? What do you see instead?
should create code for the joint something like this:
DistanceJoint joint1 = new DistanceJoint(body1, body2, new Vector2(-0.4, -1.4), 
new Vector2(1.6, -1.5));

instead it creates this:
DistanceJoint joint1 = new DistanceJoint(null, null, new Vector2(-0.4, -1.4), 
new Vector2(1.6, -1.5));

constructor should not recieve "null", but instead the two bodies

What version of the product are you using? On what operating system?
win 7, java 6, dyn4j 3.1.8

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 17 Feb 2014 at 7:50

Polygon.contains( ... ) unprecise!

Hello,
I tried to write myself an algorithm to map squares to any given polygon shape. I therefore use the contains() method of the Polygon class a lot, checking which corners of the square are inside the polygon shape.
With some shapes this works perfect. But with some shapes the method sometimes returns true for points that are clearly outside of the polygon shape. For example:

Polygon( Vector2(2.0, 0.0), Vector2(4.0, 0.0), Vector2(7.0, 3.0), Vector2(7.0, 5.0), Vector2(5.0, 7.0), Vector2(3.0, 7.0), Vector2(0.0, 4.0), Vector2(0.0, 2.0) )

When I call contains(Vector2(0.0, 0.0)) on this polygon object it returns true. Though the point (0, 0) is definetly not inside the polygon shape.

What do you think? Is this a precision issue of the conatins() method or some other issue?

How to update, if FPS varies

The gameloop I use does not guarantee the same frequency when I call world.update.
As I understood, this is normal (because swapping buffers might run a little longer sometimes), and this is why we pass an elapsed time to the update method. My problem is however, when my elapsed time has spikes in it, then when I query the position changes and apply on my world items, then the scene became laggy for the frame when the spike appears.

Example of my elapsed times:

0.016895125
0.01651961
0.016706764
0.016958213
0.116231636 <- SPIKE
0.016778305
0.016688048
0.01665092

You can see, there is one frame, where the elapsed time is 0.116231636. In that frame, my let's say player sprite jumps a little bit more, than in the other frames. Why?

Every frame I run thiscode:

long time = System.nanoTime();
long diff = time - this.lastUpdateTime;
lastUpdateTime = time;
double elapsedTime = (double) diff / 1.0e9;
System.out.println(elapsedTime);
boolean updated=this.world.update(elapsedTime);

After this, if the world was updated, I iterate through the world items, and I use the body.getChangeInPosition method to retrieve the changes, and apply to my item's positions.

The interesting thing is that if I print the changes for the Y axis, when the spike appears I see no problem in the changes, see below 5 frames I debugged out. The spike appears in the 3rd frame.

ELAPSED: 0.017004399
CHANGE Y: -0.10072222222222216

ELAPSED: 0.015985317
CHANGE Y: -0.10344444444444445

ELAPSED: 0.115819294 <- SPIKE
CHANGE Y: -0.10616666666666674

ELAPSED: 0.017143254
CHANGE Y: -0.10888888888888859

ELAPSED: 0.016584209
CHANGE Y: -0.11161111111111088

Destructible Simulation Issue

What steps will reproduce the problem?
1. Run the dyn4j-Sandbox webstart
2. Go to Tests->Compiled->Destructible and load it
3. Set the circle shape to the coordinates (0.4062, 3.2812)
4. Run the simulation

What is the expected output? What do you see instead?
The circle shape should split its geometry into a bunch of triangles over the 
two rectangular stacked shapes onto the rectangular platform.

Instead the circle shape will either break in half part of it above the 
rectangular platform and part of it below the rectangular platform or it will 
jump to below the platform and begin breaking apart.

What version of the product are you using? On what operating system?
The newest dyn4j-Sandbox webstart on the Project Home page.

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 9 May 2012 at 3:27

UUIDs

Is there any reason that UUIDs are used for each id needed? UUIDs are very 'heavy' objects, they require a lot of memory for storage and also have very expensive creation. Simple integers can be used instead (I think box2d has ints as well).

Manifold Resolution - Multithreaded - Delayed Resolution

Hi,

I was planning to make a multithreaded project by trying to make a physics engine... well, multithreaded as much as possible for a research project.
Yes, I know many have tried and failed and that physics engines are not naturally very threading-friendly.

Maybe someone can answer me what would possibly happen if - due to threading - the collision resolving would happen delayed about X frames (fixed) after the initial collision.
X is a number between 1 and 32 or something.

AFAIK the resolver normally applies an impulse on the objects to possibly uncollide them next frame. (Don't know what happens when the time step is not fixed.).
A delayed resolution would mean that the impulse gets applied X frames later, so the objects penetrate even further before the single impulses apply. Would that work or become possibly unstable?

Strange computations in SequentialImpulse

There are some calculations in SequentialImpulses::solvePositionContraints that look odd to me. Specifically in line 517 onwards
// could be 1 or 0 if one object has infinite mass
double invMass1 = mass1 * m1.getInverseMass();
double invI1 = mass1 * m1.getInverseInertia();
// could be 1 or 0 if one object has infinite mass
double invMass2 = mass2 * m2.getInverseMass();
double invI2 = mass2 * m2.getInverseInertia();

Why multiply all the inverse values with the masses? Apart from the fact that invMass1 will be 1 or 0 (as stated) which does not seems meaningful based on the computations below that code, the name also seems strange because that is not the inverse mass.
Sequential impulses where based on the corresponding contact solver from box2d, and after taking a look at it I saw it uses just the inverse values without multiplying by the masses.
Is this by accident or there's a reason for the multiplication?

Bayazit Fails on Test Case

Looks like Bayazit is failing due to finding a closest vertex that is not 
visible from the current point.

See JUnit test BayazitTest.successZoom1 for the failure case.

Original issue reported on code.google.com by [email protected] on 1 Apr 2014 at 1:23

Quadratic complexity of island creation step

While tweaking the dyn4j source I noticed a strange massive slowdown when adding beyond 5k bodies and things went horribly wrong beyond that. Performance scaled pretty well up to that, so something seemed of. After a bit of digging a bit I found that the step that resets static bodies to not being on an island has quadratic complexity and was the sole slowdown reason.

Luckily the fix is very easy and gives tremendous speedup when using a lot of bodies (I got like a 10x speedup just at 7k bodies with the fix)

The only change needed (in World.java:633) is to replace

for (int j = 0; j < size; j++) {
    Body body = this.bodies.get(j);
    if (body.isStatic()) {
        body.setOnIsland(false);
    }
}

with

for (int j = 0; j < isize; j++) {
    Body body = island.bodies.get(j);
    if (body.isStatic()) {
        body.setOnIsland(false);
    }
}

Strange code in BroadphaseKey.java

BroadphaseKey's equals method has this code (line 77) which looks like a bug:
if (obj == this) return false;
Is this intentional for some reason I don't know or just some typo that needs to be fixed?

Arc shape

How would I go about creating an Arc shape for collision? Basically I want to have a circle labyrinth such as:

circle-maze-or-labyrinth-vector-17823038

Particle System for dyn4j

While digging liquidfun code I realized that it is lot similar to dyn4j. Can liquidfun particle system be embedded in dyn4j? William please have a look on jbox2d particle system (more or less a port of liquidfun).
What do you think? Do you have some plans for adding it to dyn4j or anything similar?

EarClipping algorithm hangs

I've been playing with EarClipping decomposer and found out that for certain vertices the code falls into indefinite loop freezing the application.
Version affected: 3.2.3

Could you please make a fix ?

@Test(timeout = 5000) public void indefiniteLoop() throws Exception { new EarClipping().decompose( new Vector2(48.0, 1.0), new Vector2(70.0, -28.0), new Vector2(51.0, -58.0), new Vector2(17.0, -49.0), new Vector2(78.69931639118523, -52.394108883581644) ); }

inconsistent world.update

hi im using dyn4j version 3.3.0

im facing issue when updating world. when calling update with delta 0.100 the simulation speed slowing down but when calling with update with 0.016 the simulation speed goes faster.

step to reproduce
1 creating world
2 set gravity to none
3 add circle and set linear velocity to 10

run world with different delta aka elapsed time and observe the different

Method does not compute what it says it computes

The function public double distance(double x, double y) in Vector2 does not 
give the distance between the current point and the specified coordinates:

return Math.hypot(x, y);

I Suggest replacing it with

return Math.hypot(this.x - x, this.y - y);

Original issue reported on code.google.com by [email protected] on 15 Dec 2013 at 6:06

Raycast not hitting object

I am trying to cast a ray onto the wall from the rectangle.
However, the ray is being stopped much before as evident from the following image.
It is as if there are invisible walls to the left and to the right.
I know I am probably missing some concept.
Can you please help me to get the raycast point to the wall?

Raycast

AABB and Vector2

The AABB class currently uses two vectors for representation. I suggest to change that to 4 doubles (same with before, just unpacked). The vectors add a level of indirection, increase memory and add extra work for the GC to do. This also helps for mobile/low end devices, since all AABB are created at each step etc.
I have tested this version and it also provides some speed benefits. If you are ok with such change William, please reply here and I'll make it into a pull request.

Thanks

Increase usability of broadphases

I'm working on some improvements for the CCD which give huge performance gains. I need to use a broadphase detector that acts just on bodies, but all broadphases currently only work with <Body, Fixture> pairs. I was thinking that broadphases are useful in a wide range of scenarios, not just for <Body, Fixture> pairs.

It would be useful (maybe?) to make them more general, that is they should work for any 'object' with a corresponding 'createAABB' method.
@wnbittle I'm searching for some design ideas on how to achieve this while not changing much the current interface of broadphase detectors (Maybe a more general broadphase class which has a subclass that provides the exact functionality they currently have?).
The CCD improvement is huge, so this is overall quite useful.

Any help/discussion apreciated

Internal Edge Problem

See this topic on the forum http://forum.dyn4j.org/viewtopic.php?f=3&t=262&p=950#p950.

This is something that's pretty frustrating for users to work with and is a tough problem to solve. Putting this on the list of things that really need to be done.

My thought is to add a new flag to the body class that would effectively compute the 'border' of all the fixtures. Bear in mind that it's possible that this process could create multiple 'borders' if the fixtures are not connected. Either way, this would be computed when the setMass methods are called after fixture modification. Then, during collision detection, we would do a post processing step with these specially flagged bodies and apply the 'internal edge fix' before creating the contact constraints. I think this would fit in well, but there some details here that could get cumbersome and/or slow.

Vector3

Why is there a vector3 class in your 2D library?

Strange behaviour if a block moves over a serie of blocks all with the same size

I do some game prototype and for the physics I use dyn4j as it looks quite simple. I have now a very strange issue I can not overcome easily:
I have placed a series of 1x1 blocks as a surface and move with a 1x1 block over those blocks. If I move the block over that surface it feels like it would slide over a randomly rough terrain. It even happens that the moving block stuck completely and no force can move it in either direction, not even upward from that ground. As I attached the camera directly to that block without smoothing there is a small very fast jitter visible when it stuck.

I'm not sure if that is wellknown issue. If I use circle without inerta it is a bit better, in that case it does not stuck, but it still looks like a randomly rough terrain.

Sap.detect(aabb, filter) returns false when it should return true

I'm using Sap (and Sat) on their own. Every Collidable inside the Sap is a rectangle.
When I call Sap.detect(aabb) with aabb overlapping the rightmost Collidable inside the tree such that aabb.getMinX > rightmost.getMinX, Sap.detect returns false. The problem is that tree.ceiling ignores rightmost because of how SapProxy.compareTo is implemented.
The result is that the aabb will be able to collide with the left side of the rightmost rectangle, but will pass through its top, bottom and right side.

For now I switched to DynamicAABBTree, which works fine.

Greetings,
schosin

Basic wall obstacles failing

I'm trying to implement a simple world:

  • No gravity
  • Have multiple square blocks (that are static, wall-like)
  • Have a player (square block) controlled by arrows

I'm using setLinearVelocity to control the player's movement. The problem is, when I get closer to the square blocks, sometimes it seems my player body gets stuck while touching the square block.

Also, when the player is moving, it slides over the block. I want it to stop completely. Here's a gif of what's happening:

Only moving to the right, (10, 0) of linear velocity.
sex0124

NPE in SweepLine

Forum post: http://forum.dyn4j.org/viewtopic.php?f=3&t=83

The stacktrace:
at org.dyn4j.geometry.decompose.SweepLine.end(SweepLine.java:619)
at org.dyn4j.geometry.decompose.SweepLine.decompose(SweepLine.java:367)

See the attached file for the simple polygon data.

Original issue reported on code.google.com by [email protected] on 30 Dec 2013 at 1:15

Attachments:

Change minimum version to Java 8 (currently it's Java 6)

I was wondering how viable would it be to increase dyn4j's source level to Java 8.
Java 8 brings some cool features to use and it has very good adoption as of today (and with the new licensing around Java, devs will have to start using only the latest release).

Do you believe there can be some point where dyn4j can drop support for Java 6?
Although not the most necessary change, it would be great to have all of the new features (I was actually doing some neat changes with default interfaces).

Max translation and max rotation

While reading through the Island class, in lines 205 onwards:

// compute the translation and rotation for this time step
Vector2 translation = body.velocity.product(dt);
double rotation = body.angularVelocity * dt;

// make sure the translation is not over the maximum
if (translation.getMagnitudeSquared() > maxTranslationSqrd) {
	double ratio = maxTranslation / translation.getMagnitude();
	body.velocity.multiply(ratio);
}

// make sure the rotation is not over the maximum
if (rotation * rotation > maxRotationSqrd) {
	double ratio = maxRotation / Math.abs(rotation);
	body.angularVelocity *= ratio;
}

I can't understand why we multiply translation and rotation by dt when comparing to the settings maximum. As I imagine it one would want to limit the maximum velocity and rotation a body can obtain regardless of the current step time.
What is the logical interpretation of limiting those based on the current step time?

How do I build this project.

As the title of the issue says, how do I build this project? I am trying to make it as a gradle project, however, the examples wouldn't compile. My gradle file looks like this -

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'org.dyn4j:dyn4j:3.2.3'
    compile 'org.jogamp.jogl:jogl-all:2.3.1'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

I always get this error while building the project -

Error:(174, 21) java: cannot access com.jogamp.common.type.WriteCloneable
  class file for com.jogamp.common.type.WriteCloneable not found

Strange behaviour on collision for objects moving from right to left

After building the latest code (from upcoming release 3.3.1), I observed a strange behavior.

For any object moving from right to left hitting another object of infinite mass, it is displaying erratic behavior as can be seen in the following GIF.

Behavior when executed in version 3.3.1
ezgif com-crop

To compare, I have executed the same code in version 3.3.0
ezgif com-crop (2)

Here the moving object is a rectangular fixture and the fixed object is a set of links.
Strangely, this behavior can only be reproduced if the object is moving from right to left.

It seems like a regression to me.
Can you please check if it is a bug or am I missing something?

Help designing a mix of a joint with a fixture

I need to somehow implement a distance joint that is rigid (preferably with some thickness) and other bodies can collide with. I'm currently searching of possible ways to implement this and though I could get some extra opinions.
So I want to have two bodies b1, b2 that are connected as a system with a distance joint so that other bodies can collide with the joint it and interact with the system.
Making a fixture that changes shape on every frame shouldn't be a big problem (I think) but I'm not sure how this can be combined to work with the linked bodies b1, b2.

I'm working on implementing jelly/soft bodies for dyn4j, that's where this is needed.
There are some 'lower quality' solutions that I have tried and they work decently, but I was wondering if the above can somehow be implemented.

Any help appreciated.

Fix possible bug in SAP

After the new unit test for broad-phase detectors a possible bug in SAP#detect(AABB) was found and currently the master branch fails this test. I have not yet determined the cause of it, but we should have a look at it and fix this. I don't know if this is related somehow to the changes after #20.
You can add this for the 3.3.1 milestone as well.

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.