Giter Club home page Giter Club logo

lbjexamples's Introduction

Libbulletjme Project logo

The LbjExamples Project provides documentation and example applications for the Libbulletjme 3-D physics library.

It contains 2 subprojects:

  1. docs: Antora documentation for Libbulletjme, including the tutorial
  2. apps: applications referenced in the tutorial

The applications make use of the SPORT graphics engine, which was formerly a subproject and is now a separate project at GitHub.

Complete source code (in Java) is provided under a 3-clause BSD license.

How to build and run LbjExamples from source

Initial build

  1. Install a Java Development Kit (JDK), if you don't already have one.
  2. Point the JAVA_HOME environment variable to your JDK installation: (In other words, set it to the path of a directory/folder containing a "bin" that contains a Java executable. That path might look something like "C:\Program Files\Eclipse Adoptium\jdk-17.0.3.7-hotspot" or "/usr/lib/jvm/java-17-openjdk-amd64/" or "/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home" .)
  • using Bash or Zsh: export JAVA_HOME=" path to installation "
  • using Fish: set -g JAVA_HOME " path to installation "
  • using Windows Command Prompt: set JAVA_HOME=" path to installation "
  • using PowerShell: $env:JAVA_HOME = ' path to installation '
  1. Download and extract the LbjExamples source code from GitHub:
  • using Git:
    • git clone https://github.com/stephengold/LbjExamples.git
    • cd LbjExamples
  1. Run the Gradle wrapper:
  • using Bash or Fish or PowerShell or Zsh: ./gradlew build
  • using Windows Command Prompt: .\gradlew build

Tutorials

The tutorial apps all have names starting with "Hello". For instance, the first tutorial app is named "HelloLibbulletjme".

To execute "HelloLibbulletjme":

  • using Bash or Fish or PowerShell or Zsh: ./gradlew HelloLibbulletjme
  • using Windows Command Prompt: .\gradlew HelloLibbulletjme

Chooser

A Swing-based chooser application is included. However, it includes only the graphical apps and doesn't work on macOS yet.

To run the chooser:

  • using Bash or Fish or PowerShell or Zsh: ./gradlew AppChooser
  • using Windows Command Prompt: .\gradlew AppChooser

Cleanup

You can restore the project to a pristine state:

  • using Bash or Fish or PowerShell or Zsh: ./gradlew clean
  • using Windows Command Prompt: .\gradlew clean

Note: these commands will delete any downloaded native libraries.

lbjexamples's People

Contributors

dependabot[bot] avatar stephengold avatar yanisbdf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

jimbok8

lbjexamples's Issues

GImpactCollisionShape object won't collide with PlaneCollisionShape

I'm using Vulkan with LWJGL to render my world. But I followed the simple HelloWorld tutorial for this physics engine.
Below is my model class that extends the rigidbody. Both the plane and mesh are successfully added to the space, and gravity works just fine, yet the mesh doesnt collide with the plane.

package engine.math;

import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.collision.shapes.GImpactCollisionShape;
import com.jme3.bullet.collision.shapes.PlaneCollisionShape;
import com.jme3.bullet.collision.shapes.infos.IndexedMesh;
import com.jme3.bullet.objects.PhysicsRigidBody;
import engine.collision.VkSimOBB;
import engine.collision.VkSimPlane;
import engine.core.VkConcurrentRenderInfo;
import engine.core.VkTransform;
import engine.util.VertexUtil;
import engine.util.VkBulletUtil;

import java.util.Arrays;

public class VkSimModel extends PhysicsRigidBody implements VkSimulate {

    public enum TYPE {PLANE,MESH,BOX};

    private VkModel model;

    private Vector3 velocity = Vector3.ZERO;
    private Vector3 orientation = Vector3.ZERO;
    private Vector3 angularVelocity = Vector3.ZERO;
    private Vector3 position;

    public VkSimModel(VkModel model, float mass) {
        super(new GImpactCollisionShape(
                new IndexedMesh(
                        VkBulletUtil.convert(Arrays.stream(VertexUtil.toVertexArray(model.getVertices()))
                                .map(v -> v.getPos()).toArray(Vector3[]::new)), model.getIndices())), mass);

        this.model = model;
        setPhysicsTransform(VkBulletUtil.convert(model.getLocalTransform()));
        getCollisionShape().setScale(VkBulletUtil.convert(model.getLocalTransform().getScaling()));
        setAngularSleepingThreshold(.001f);
        setLinearSleepingThreshold(.1f);
        setLinearDamping(.98f);
        setAngularDamping(.98f);
    }

    public VkSimModel(VkModel model, VkSimOBB obb, float mass) {

        super(new BoxCollisionShape(obb.getMax().getX() - obb.getCenter().getX(),
                        obb.getMax().getY() - obb.getCenter().getY()
                        ,obb.getMax().getZ() - obb.getCenter().getZ())
                , mass);
        this.model = model;
        setPhysicsTransform(VkBulletUtil.convert(model.getLocalTransform()));
        getCollisionShape().setScale(VkBulletUtil.convert(model.getLocalTransform().getScaling()));
        setAngularSleepingThreshold(.001f);
        setLinearSleepingThreshold(.1f);
        setLinearDamping(.98f);
        setAngularDamping(.98f);
    }

    public VkSimModel(VkModel model, VkSimPlane plane, float mass) {
        super(plane, mass);
        this.model = model;
        setPhysicsTransform(VkBulletUtil.convert(model.getLocalTransform()));
        getCollisionShape().setScale(VkBulletUtil.convert(model.getLocalTransform().getScaling()));
        setAngularSleepingThreshold(.001f);
        setLinearSleepingThreshold(.1f);
        setLinearDamping(.98f);
        setAngularDamping(.98f);
    }

    @Override
    public void update(double elapsedTime) {

        this.position = getPosition().clone();
        this.orientation = getRotation().clone();

        angularVelocity = VkBulletUtil.convert(getAngularVelocity(null))
                .mul(getAngularDamping());

        velocity = VkBulletUtil.convert(getLinearVelocity(null))
                .mul(getLinearDamping());

        // Integrate position
        position = position.add(velocity.mul((float)elapsedTime));

        Quaternion quaternionZ = Quaternion.createFromAxisAngle(Vector3.FRONT, angularVelocity.getZ());
        this.orientation = orientation.add(quaternionZ.normalize().xyz().mul(Quaternion.radToDeg));

        Quaternion quaternionY  = Quaternion.createFromAxisAngle(Vector3.UP, -angularVelocity.getY());
        this.orientation = orientation.add(quaternionY.normalize().xyz().mul(Quaternion.radToDeg));

        Quaternion quaternionX  = Quaternion.createFromAxisAngle(Vector3.RIGHT, -angularVelocity.getX());
        this.orientation = orientation.add(quaternionX.normalize().xyz().mul(Quaternion.radToDeg));


    }


    public VkConcurrentRenderInfo commit() {

        VkTransform transform = new VkTransform();
        transform.setTranslation(this.position);
        transform.setRotation(this.orientation);
        transform.setScaling(this.model.getLocalTransform().getScaling());

        setPhysicsTransform(VkBulletUtil.convert(transform));

        return this.model.updateTransform(transform);
    }

    public Vector3 getRotation() {
        return this.model.getLocalTransform().getRotation();
    }

    public Vector3 getPosition() {
        return this.model.getLocalTransform().getTranslation();
    }

}

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.