Giter VIP home page Giter VIP logo

haxebullet's Introduction

haxebullet

Native Bullet 3D Physics for Haxe. Includes library file for Kha.

Package is available on haxelib:

haxelib install haxebullet

Docs

Refer to original Bullet documentation.

Remarks

Based on Bullet 2.82, works on C++ and JS targets. Using original C++ sources of Bullet and Ammo.js for JavaScript respectively. The goal of this repository is to provide top class 3D physics solution for Haxe.

The bindings are not complete but it's very easy to add missing stuff based on what's already there. Feel free to contribute!

Usage

C++ Reference

In order to get C++ build to work you need to add 'haxebullet/cpp/bullet' directory into your build process so compiler is able to find bullet sources.

JS Reference

In order to get JS build to work you need to add 'haxebullet/js/ammo/ammo.js' script either by embedding or including it with a script tag.

var groundShape = BtStaticPlaneShape.create(BtVector3.create(0, 1, 0).value, 1);
var groundTransform = BtTransform.create();
groundTransform.value.setIdentity();
groundTransform.value.setOrigin(BtVector3.create(0, -1, 0).value);
var centerOfMassOffsetTransform = BtTransform.create();
centerOfMassOffsetTransform.value.setIdentity();
var groundMotionState = BtDefaultMotionState.create(groundTransform.value, centerOfMassOffsetTransform.value);

var groundRigidBodyCI = BtRigidBodyConstructionInfo.create(0.01, groundMotionState, groundShape, BtVector3.create(0, 0, 0).value);
var groundRigidBody = BtRigidBody.create(groundRigidBodyCI.value);
dynamicsWorld.value.addRigidBody(groundRigidBody);


var fallShape = BtSphereShape.create(1);
var fallTransform = BtTransform.create();
fallTransform.value.setIdentity();
fallTransform.value.setOrigin(BtVector3.create(0, 50, 0).value);
var centerOfMassOffsetFallTransform = BtTransform.create();
centerOfMassOffsetFallTransform.value.setIdentity();
var fallMotionState = BtDefaultMotionState.create(fallTransform.value, centerOfMassOffsetFallTransform.value);

var fallInertia = BtVector3.create(0, 0, 0);
fallShape.value.calculateLocalInertia(1, fallInertia.value);
var fallRigidBodyCI = BtRigidBodyConstructionInfo.create(1, fallMotionState, fallShape, fallInertia.value);
var fallRigidBody = BtRigidBody.create(fallRigidBodyCI.value);
dynamicsWorld.value.addRigidBody(fallRigidBody);

for (i in 0...3000) {
	dynamicsWorld.value.stepSimulation(1 / 60);
	
	var trans = BtTransform.create();
	var m = fallRigidBody.value.getMotionState();
	m.value.getWorldTransform(trans.value);
	trace(trans.getOrigin().y());
}

// .destroy()...

haxebullet's People

Contributors

luboslenco avatar

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.