GithubHelp home page GithubHelp logo

armory3d / haxebullet Goto Github PK

View Code? Open in Web Editor NEW
95.0 13.0 21.0 8.51 MB

Bullet 3D Physics for Haxe

Home Page: http://bulletphysics.org

License: zlib License

C 3.07% C++ 94.66% CMake 0.53% Lua 0.03% JavaScript 0.01% Haxe 1.71%

haxebullet's Introduction

haxebullet

Bullet 3D Physics bindings for Haxe.

Based on the webidl approach, works for HL/C & JS:

Usage

Reference

In order to get HL/C build to work you need to add haxebullet/bullet and haxebullet/hl directories into your build process so the compiler is able to find bullet sources.

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

var collisionConfiguration = new bullet.Bt.DefaultCollisionConfiguration();
var dispatcher = new bullet.Bt.CollisionDispatcher(collisionConfiguration);
var broadphase = new bullet.Bt.DbvtBroadphase();
var solver = new bullet.Bt.SequentialImpulseConstraintSolver();
var dynamicsWorld = new bullet.Bt.DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

var groundShape = new bullet.Bt.StaticPlaneShape(new bullet.Bt.Vector3(0, 1, 0), 1);
var groundTransform = new bullet.Bt.Transform();
groundTransform.setIdentity();
groundTransform.setOrigin(new bullet.Bt.Vector3(0, -1, 0));
var centerOfMassOffsetTransform = new bullet.Bt.Transform();
centerOfMassOffsetTransform.setIdentity();
var groundMotionState = new bullet.Bt.DefaultMotionState(groundTransform, centerOfMassOffsetTransform);

var groundRigidBodyCI = new bullet.Bt.RigidBodyConstructionInfo(0.01, groundMotionState, cast groundShape, new bullet.Bt.Vector3(0, 0, 0));
var groundRigidBody = new bullet.Bt.RigidBody(groundRigidBodyCI);
dynamicsWorld.addRigidBody(groundRigidBody);

var fallShape = new bullet.Bt.SphereShape(1);
var fallTransform = new bullet.Bt.Transform();
fallTransform.setIdentity();
fallTransform.setOrigin(new bullet.Bt.Vector3(0, 50, 0));
var centerOfMassOffsetFallTransform = new bullet.Bt.Transform();
centerOfMassOffsetFallTransform.setIdentity();
var fallMotionState = new bullet.Bt.DefaultMotionState(fallTransform, centerOfMassOffsetFallTransform);

var fallInertia = new bullet.Bt.Vector3(0, 0, 0);
// fallShape.calculateLocalInertia(1, fallInertia);
var fallRigidBodyCI = new bullet.Bt.RigidBodyConstructionInfo(1, fallMotionState, fallShape, fallInertia);
var fallRigidBody = new bullet.Bt.RigidBody(fallRigidBodyCI);
dynamicsWorld.addRigidBody(fallRigidBody);

for (i in 0...3000) {
	dynamicsWorld.stepSimulation(1 / 60);
	
	var trans = new bullet.Bt.Transform();
	var m = fallRigidBody.getMotionState();
	m.getWorldTransform(trans);
	trace(trans.getOrigin().y());
	trans.delete();
}

// ...delete();

haxebullet's People

Contributors

anadin avatar danilko avatar donalffons avatar guzzard avatar luboslenco avatar moritzbrueckner avatar onelsonic avatar quantumcoderqc avatar robdangerous avatar sanva avatar wadison 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

Watchers

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

haxebullet's Issues

haxelib.json missing

haxelib.json disappeared in this commit: https://github.com/armory3d/haxebullet/tree/bce65966e086432981fc4c17b5818229c636ad84

It was present in the previous one, as can be seen here: https://github.com/armory3d/haxebullet/tree/2b87efd5ce0b23732a90828f7fb121379c7cf494

Without a haxelib.json, lime-based projects can't find the proper classPath, and can't resolve any classes as a result. I was previously on a very old commit which still had the haxelib, so this only recently caused me trouble when I upgraded xD

calculateLocalInertia seems to have no effect

I'm on the latest haxebullet version, but still on Haxe 3.2.0. This sample works fine with ammo.js and with older haxebullet versions, but on a latest version native build LocalInertia doesn't change at all after a calculateLocalInertia call, giving all bodies infinite rotational inertia as a result.

Sample:

var LocalInertia = BtVector3.create(0, 0, 0);
shape.ptr.calculateLocalInertia(Mass, LocalInertia.value);
trace(LocalInertia.value.x(), LocalInertia.value.y(), LocalInertia.value.z());

Output:
BPhys.hx:60: 0,0,0

Need a little help with BtRigidBody plz

Trying to get this to compile on cpp (JS is fine) and need a base var. I don't know what to plug in for the BtStridingMeshInterface.

I get the error: "cannot construct a btStridingMeshInterface, no constructor in IDL" because it's an interface.

Thinking about sticking some kind of tri or collision shape in there but not really sure which.

   public var fallRigidBody:BtRigidBody = BtRigidBody.create(BtRigidBodyConstructionInfo.create
(
	0, 
	BtDefaultMotionState.create(BtTransform.create(), BtTransform.create()), 
	BtBvhTriangleMeshShape.create(BtStridingMeshInterface.create(), false, false), 
	BtVector3.create(0, 0, 0)
));

Readme test case

I think the aim of the code sample, was to showcase a ball bumping against ground. However when ruining it, the trace(trans.getOrigin().y()); goes in negative numbers. What's missing?

'btRigidBody': no appropriate default constructor available

Hi, in the cpp build I'm still getting "error C2512: 'btRigidBody': no appropriate default constructor available" (which is a repeated problem with other files, ie btDiscreteDynamicsWorld).

I tried this type of construction, but not really sure what to do at this point : #19

error C2819: type 'btRigidBody' does not have an overloaded member 'operator ->'

I'm on Haxe 3.2.0 (afraid of migrating because of my the legacy openfl/lime/haxeflixel stuff I use for other projects), and I'm having some trouble building the most recent commit. I'm using hxcpp 3.3.49 (which I think is the latest on haxelib).

Here's what the compiler outputs:

Error: While running :cl.exe -Iinclude -IC:\HaxeToolkit\haxe\lib\haxebullet/git/Sources/../cpp/bullet -nologo /WX- /fp:precise -DHX_WINDOWS -D_USING_V120_SDK71_ -GR -Od -Zi -FdC:\Users\Anon\Desktop\HAXEDEV\BlipEngine\bin\windows\cpp\debug\obj\obj/msvc18-debug-ncxp/vc.pdb -FS -Oy- -c -EHs -GS- -arch:SSE -IC:/HaxeToolkit/haxe/lib/hxcpp/3,3,49/include -DHXCPP_DEBUG -DHXCPP_VISIT_ALLOCS -DHXCPP_CHECK_POINTER -DHXCPP_STACK_TRACE -DHXCPP_STACK_LINE -DHXCPP_API_LEVEL=321 -D_CRT_SECURE_NO_DEPRECATE -D_ALLOW_MSC_VER_MISMATCH -D_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH -wd4996 -MT ./src/subsector/Player.cpp -FoC:/Users/Anon/Desktop/HAXEDEV/BlipEngine/bin/windows/cpp/debug/obj/obj/msvc18-debug-ncxp/025d0416_Player.obj
Player.cpp
./src/subsector/Player.cpp(153) : error C2819: type 'btRigidBody' does not have an overloaded member 'operator ->'
        C:\HaxeToolkit\haxe\lib\haxebullet\git\cpp\bullet\BulletDynamics/Dynamics/btRigidBody.h(62) : see declaration of 'btRigidBody'
        did you intend to use '.' instead?
./src/subsector/Player.cpp(153) : error C2232: '->btCollisionObject::setUserIndex' : left operand has 'class' type, use '.'

Here's Player.cpp(153):

this->phys->body->get_value()->setUserIndex((int)666);

And this is the original Haxe line:

phys.body.value.setUserIndex(666);

body is a cpp.Pointer, so it seems that the generated code mistakes the return value of the get_value() for a pointer. Is this just a Haxe 3.2/3.3 incompatibility?

Managing pointers in cpp target

At the moment my code looks something like this

class BGame extends BGroup {
    #if cpp
    public var world:Pointer<BtDiscreteDynamicsWorld>;
    #else
    public var world:BtDiscreteDynamicsWorld;
    #end
}

Luckily .value() works equivalently in js and cpp targets, but I still feel like these conditionals are annoying. I also suppose ammo.js has automatic garbage collection, but in cpp we need to call pointer.destroy(), right?

I think those are the only two things keeping the js and cpp versions not fully unified.

Collision callback

Hi Lubos,

I've been sifting through Bullet's docs and forums to find how to process collisions. My first use case is to detect collisions of certain objects with the player, for which the gContactProcessedCallback method from http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Collision_Callbacks_and_Triggers seems well suited. However I'm not sure how to use the bindings to achieve this or what to add to the bindings. I'm wondering if you have any advice on how to process collisions in general.

Thank you for your time

Wrong path to bullet .h files generated

Hi,
on my machine I have haxe 3.1.3 and hxcpp 3.2.81 and this line in Bullet.hx:

@:include("LinearMath/btVector3.h")

generates this line in Main.cpp file:

#include <LinearMath/btVector3.h.h>    // (note the double .h.h !!)

Removing ".h" from @:include generates correct path in Main.cpp.

It would be nice if you could create a simple test project that will show us the right way of
haxebullet usage. How do you integrate it into your build process without having to manually change stuff for every different cpp target ?

lime cpp target?

For web it's nice and cozy (in project.xml): <dependency if="web" path="dependencies/ammo.js" />

For cpp on the other hand, I just couldn't find any info about adding header/source files. I suppose I would have to inject it into the hxcpp build process somehow but I have no clue how that can be done.

What Do We Need To Autogenerate Javascript Bindings?

I was looking around because I needed some extra bindings that I found were not in Bt.hx but were in the WebIDL and I found that the Javascript bindings were not generated automatically yet.

// These will be eventually auto-generated, similar to the above

If it is worth your time to explain, I might be able to do the work to get that done. Before I started on anything I just wanted to make sure you haven't already figured out what we need to do. If it isn't worth the time right now, no problem, I don't care either way, I'll just add the extra bindings that I need to Bt.hx for now.

Crash on android

On Android 4.4 application crashes on dynamicsWorld.stepSimulation(1/60) call. I also tested It on Android 5.0, linux, html5 and it works fine. There are no any errors in logcat and I don't know how to capture this error. Can somebody suggest solution? I tested on 2 smartphones with Android 4.4.2 and 4.4.3, both crashes

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.