Skip to content
Browse files

checkpoint

  • Loading branch information...
1 parent 9f25b0e commit 2d5c20ca03b9f5e51209e0d99bfa96d545da4451 Nicholas Kinsey committed Jan 9, 2011
View
6 package.coffee
@@ -11,7 +11,7 @@
licenses: [
{
type: 'FEISTY'
- url: 'http://github.com/feisty/license/LICENSE'
+ url: 'http://github.com/feisty/license/raw/master/LICENSE'
}
]
@@ -36,8 +36,8 @@
main: './lib/bullet.coffee'
dependencies:
- 'coffee-script': '= 1.0.0'
+ 'coffee-script': '>= 1.0.0'
engines:
- node: '= 0.3.2'
+ node: '>= 0.3.3'
}
View
37 package.js
@@ -0,0 +1,37 @@
+(function() {
+ ({
+ name: 'bullet',
+ description: '"Bullet" physics for node.js',
+ keywords: ['bullet', 'physics', 'dynamics', 'engine', 'binding', 'wrapper'],
+ version: '0.1.0',
+ author: 'Feisty Studios <node-bullet@feistystudios.com> (http://feistystudios.com/)',
+ licenses: [
+ {
+ type: 'FEISTY',
+ url: 'http://github.com/feisty/license/LICENSE'
+ }
+ ],
+ contributors: ['Nicholas Kinsey <nicholas.kinsey@feistystudios.com>'],
+ repository: {
+ type: 'git',
+ url: 'http://github.com/feisty/node-bullet.git',
+ private: 'git@github.com:feisty/node-bullet.git',
+ web: 'http://github.com/feisty/node-bullet'
+ },
+ bugs: {
+ mail: 'node-bullet@feistystudios.com',
+ web: 'http://github.com/feisty/node-bullet/issues'
+ },
+ directories: {
+ lib: './lib',
+ doc: './doc'
+ },
+ main: './lib/bullet.coffee',
+ dependencies: {
+ 'coffee-script': '= 1.0.0'
+ },
+ engines: {
+ node: '= 0.3.2'
+ }
+ });
+}).call(this);
View
6 package.json
@@ -7,7 +7,7 @@
licenses: [
{
type: 'FEISTY',
- url: 'http://github.com/feisty/license/LICENSE'
+ url: 'http://github.com/feisty/license/raw/master/LICENSE'
}
],
contributors: ['Nicholas Kinsey <nicholas.kinsey@feistystudios.com>'],
@@ -27,9 +27,9 @@
},
main: './lib/bullet.coffee',
dependencies: {
- 'coffee-script': '= 1.0.0'
+ 'coffee-script': '>= 1.0.0'
},
engines: {
- node: '= 0.3.2'
+ node: '>= 0.3.3'
}
}
View
4 src/CollisionDispatcher.cc
@@ -29,7 +29,11 @@ CollisionDispatcher::New(const Arguments &args) {
}
CollisionDispatcher::CollisionDispatcher(DefaultCollisionConfiguration* defaultCollisionConfiguration): ObjectWrap() {
+ _btCollisionDispatcher = new btCollisionDispatcher(defaultCollisionConfiguration->_btDefaultCollisionConfiguration);
}
CollisionDispatcher::~CollisionDispatcher() {
+ if (_btCollisionDispatcher) {
+ delete _btCollisionDispatcher;
+ }
}
View
4 src/CollisionDispatcher.h
@@ -7,6 +7,8 @@
#include "DefaultCollisionConfiguration.h"
+#include "btBulletDynamicsCommon.h"
+
using namespace v8;
using namespace node;
@@ -18,6 +20,8 @@ class CollisionDispatcher: public node::ObjectWrap {
static Handle<Value> New(const Arguments &args);
CollisionDispatcher(DefaultCollisionConfiguration* defaultCollisionConfiguration);
+
+ btCollisionDispatcher* _btCollisionDispatcher;
private:
~CollisionDispatcher();
View
4 src/DbvtBroadphase.cc
@@ -26,7 +26,11 @@ DbvtBroadphase::New(const Arguments &args) {
}
DbvtBroadphase::DbvtBroadphase(): ObjectWrap() {
+ _btDbvtBroadphase = new btDbvtBroadphase();
}
DbvtBroadphase::~DbvtBroadphase() {
+ if (_btDbvtBroadphase) {
+ delete _btDbvtBroadphase;
+ }
}
View
4 src/DbvtBroadphase.h
@@ -5,6 +5,8 @@
#include <node.h>
#include <node_object_wrap.h>
+#include "btBulletDynamicsCommon.h"
+
using namespace v8;
using namespace node;
@@ -16,6 +18,8 @@ class DbvtBroadphase: public node::ObjectWrap {
static Handle<Value> New(const Arguments &args);
DbvtBroadphase();
+
+ btDbvtBroadphase* _btDbvtBroadphase;
private:
~DbvtBroadphase();
View
4 src/DefaultCollisionConfiguration.cc
@@ -26,7 +26,11 @@ DefaultCollisionConfiguration::New(const Arguments &args) {
}
DefaultCollisionConfiguration::DefaultCollisionConfiguration(): ObjectWrap() {
+ _btDefaultCollisionConfiguration = new btDefaultCollisionConfiguration();
}
DefaultCollisionConfiguration::~DefaultCollisionConfiguration() {
+ if (_btDefaultCollisionConfiguration) {
+ delete _btDefaultCollisionConfiguration;
+ }
}
View
4 src/DefaultCollisionConfiguration.h
@@ -5,6 +5,8 @@
#include <node.h>
#include <node_object_wrap.h>
+#include "btBulletDynamicsCommon.h"
+
using namespace v8;
using namespace node;
@@ -16,6 +18,8 @@ class DefaultCollisionConfiguration: public node::ObjectWrap {
static Handle<Value> New(const Arguments &args);
DefaultCollisionConfiguration();
+
+ btDefaultCollisionConfiguration* _btDefaultCollisionConfiguration;
private:
~DefaultCollisionConfiguration();
View
54 src/DiscreteDynamicsWorld.cc
@@ -28,19 +28,19 @@ Handle<Value>
DiscreteDynamicsWorld::New(const Arguments &args) {
HandleScope scope;
- // Local<Object> collisionDispatcherHandle = args[0]->ToObject();
- // CollisionDispatcher* collisionDispatcher = ObjectWrap::Unwrap<CollisionDispatcher>(collisionDispatcherHandle);
- //
- // Local<Object> dbvtBroadphaseHandle = args[1]->ToObject();
- // DbvtBroadphase* dbvtBroadphase = ObjectWrap::Unwrap<DbvtBroadphase>(dbvtBroadphaseHandle);
- //
- // Local<Object> sequentialImpulseConstraintSolverHandle = args[2]->ToObject();
- // SequentialImpulseConstraintSolver* sequentialImpulseConstraintSolver = ObjectWrap::Unwrap<SequentialImpulseConstraintSolver>(sequentialImpulseConstraintSolverHandle);
- //
- // Local<Object> defaultCollisionConfigurationHandle = args[3]->ToObject();
- // DefaultCollisionConfiguration* defaultCollisionConfiguration = ObjectWrap::Unwrap<DefaultCollisionConfiguration>(defaultCollisionConfigurationHandle);
-
- DiscreteDynamicsWorld* discreteDynamicsWorld = new DiscreteDynamicsWorld(/*collisionDispatcher, dbvtBroadphase, sequentialImpulseConstraintSolver, defaultCollisionConfiguration*/);
+ Local<Object> collisionDispatcherHandle = args[0]->ToObject();
+ CollisionDispatcher* collisionDispatcher = ObjectWrap::Unwrap<CollisionDispatcher>(collisionDispatcherHandle);
+
+ Local<Object> dbvtBroadphaseHandle = args[1]->ToObject();
+ DbvtBroadphase* dbvtBroadphase = ObjectWrap::Unwrap<DbvtBroadphase>(dbvtBroadphaseHandle);
+
+ Local<Object> sequentialImpulseConstraintSolverHandle = args[2]->ToObject();
+ SequentialImpulseConstraintSolver* sequentialImpulseConstraintSolver = ObjectWrap::Unwrap<SequentialImpulseConstraintSolver>(sequentialImpulseConstraintSolverHandle);
+
+ Local<Object> defaultCollisionConfigurationHandle = args[3]->ToObject();
+ DefaultCollisionConfiguration* defaultCollisionConfiguration = ObjectWrap::Unwrap<DefaultCollisionConfiguration>(defaultCollisionConfigurationHandle);
+
+ DiscreteDynamicsWorld* discreteDynamicsWorld = new DiscreteDynamicsWorld(collisionDispatcher, dbvtBroadphase, sequentialImpulseConstraintSolver, defaultCollisionConfiguration);
discreteDynamicsWorld->Wrap(args.This());
return scope.Close(args.This());
@@ -86,34 +86,16 @@ DiscreteDynamicsWorld::StepSimulation(const Arguments &args) {
// body->getMotionState()->getWorldTransform(trans);
// printf("world pos = %f,%f,%f\n",float(trans.getOrigin().getX()),float(trans.getOrigin().getY()),float(trans.getOrigin().getZ()));
// }
- //
- // obj = discreteDynamicsWorld->_btDiscreteDynamicsWorld->getCollisionObjectArray()[1];
- // body = btRigidBody::upcast(obj);
- // if (body && body->getMotionState())
- // {
- // btTransform trans;
- // body->getMotionState()->getWorldTransform(trans);
- // printf("world pos = %f,%f,%f\n",float(trans.getOrigin().getX()),float(trans.getOrigin().getY()),float(trans.getOrigin().getZ()));
- // }
return scope.Close(Undefined());
}
-DiscreteDynamicsWorld::DiscreteDynamicsWorld(/*CollisionDispatcher* collisionDispatcher, DbvtBroadphase* dbvtBroadphase, SequentialImpulseConstraintSolver* sequentialImpulseConstraintSolver, DefaultCollisionConfiguration* defaultCollisionConfiguration*/): ObjectWrap() {
- // TODO Create and use the actual binded objects instead of this hack
-
- btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
- btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
- btDbvtBroadphase* broadphase = new btDbvtBroadphase();
- btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver();
-
- _btDiscreteDynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
-
- // _btDiscreteDynamicsWorld = new btDiscreteDynamicsWorld(collisionDispatcher, dbvtBroadphase, sequentialImpulseConstraintSolver, defaultCollisionConfiguration);;
+DiscreteDynamicsWorld::DiscreteDynamicsWorld(CollisionDispatcher* collisionDispatcher, DbvtBroadphase* dbvtBroadphase, SequentialImpulseConstraintSolver* sequentialImpulseConstraintSolver, DefaultCollisionConfiguration* defaultCollisionConfiguration): ObjectWrap() {
+ _btDiscreteDynamicsWorld = new btDiscreteDynamicsWorld(collisionDispatcher->_btCollisionDispatcher, dbvtBroadphase->_btDbvtBroadphase, sequentialImpulseConstraintSolver->_btSequentialImpulseConstraintSolver, defaultCollisionConfiguration->_btDefaultCollisionConfiguration);
}
DiscreteDynamicsWorld::~DiscreteDynamicsWorld() {
- // if (_btDiscreteDynamicsWorld) {
- // free(_btDiscreteDynamicsWorld);
- // }
+ if (_btDiscreteDynamicsWorld) {
+ delete _btDiscreteDynamicsWorld;
+ }
}
View
2 src/DiscreteDynamicsWorld.h
@@ -27,7 +27,7 @@ class DiscreteDynamicsWorld: public node::ObjectWrap {
static Handle<Value> AddRigidBody(const Arguments &args);
static Handle<Value> StepSimulation(const Arguments &args);
- DiscreteDynamicsWorld(/*CollisionDispatcher* collisionDispatcher, DbvtBroadphase* dbvtBroadphase, SequentialImpulseConstraintSolver* sequentialImpulseConstraintSolver, DefaultCollisionConfiguration* defaultCollisionConfiguration*/);
+ DiscreteDynamicsWorld(CollisionDispatcher* collisionDispatcher, DbvtBroadphase* dbvtBroadphase, SequentialImpulseConstraintSolver* sequentialImpulseConstraintSolver, DefaultCollisionConfiguration* defaultCollisionConfiguration);
btDiscreteDynamicsWorld* _btDiscreteDynamicsWorld;
View
11 src/RigidBody.cc
@@ -13,8 +13,6 @@ RigidBody::Initialize(Handle<Object> target) {
Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
target->Set(String::NewSymbol("RigidBody"), constructor->GetFunction());
-
- scope.Close();
}
Handle<Value>
@@ -27,7 +25,7 @@ RigidBody::New(const Arguments &args) {
return scope.Close(args.This());
}
-RigidBody::RigidBody(): ObjectWrap() {
+RigidBody::RigidBody(): ObjectWrap() {
btTransform transform;
transform.setIdentity();
transform.setOrigin(btVector3((float)rand()/(float)RAND_MAX*1000.0, (float)rand()/(float)RAND_MAX*1000.0, (float)rand()/(float)RAND_MAX*1000.0));
@@ -44,8 +42,7 @@ RigidBody::RigidBody(): ObjectWrap() {
}
RigidBody::~RigidBody() {
- // if (_btRigidBody) {
- // free(_btRigidBody);
- // _btRigidbody = NULL;
- // }
+ if (_btRigidBody) {
+ //delete _btRigidBody;
+ }
}
View
4 src/SequentialImpulseConstraintSolver.cc
@@ -26,7 +26,11 @@ SequentialImpulseConstraintSolver::New(const Arguments &args) {
}
SequentialImpulseConstraintSolver::SequentialImpulseConstraintSolver(): ObjectWrap() {
+ _btSequentialImpulseConstraintSolver = new btSequentialImpulseConstraintSolver();
}
SequentialImpulseConstraintSolver::~SequentialImpulseConstraintSolver() {
+ if (_btSequentialImpulseConstraintSolver) {
+ delete _btSequentialImpulseConstraintSolver;
+ }
}
View
4 src/SequentialImpulseConstraintSolver.h
@@ -5,6 +5,8 @@
#include <node.h>
#include <node_object_wrap.h>
+#include "btBulletDynamicsCommon.h"
+
using namespace v8;
using namespace node;
@@ -16,6 +18,8 @@ class SequentialImpulseConstraintSolver: public node::ObjectWrap {
static Handle<Value> New(const Arguments &args);
SequentialImpulseConstraintSolver();
+
+ btSequentialImpulseConstraintSolver* _btSequentialImpulseConstraintSolver;
private:
~SequentialImpulseConstraintSolver();
View
34 src/init.cc
@@ -1,13 +1,13 @@
-// #include "btBulletDynamicsCommon.h"
+#include "btBulletDynamicsCommon.h"
-// #include "Bullet.h"
-// #include "DefaultCollisionConfiguration.h"
-// #include "CollisionDispatcher.h"
-// #include "DbvtBroadphase.h"
-// #include "SequentialImpulseConstraintSolver.h"
-// #include "DiscreteDynamicsWorld.h"
-// #include "BoxShape.h"
-// #include "Transform.h"
+#include "Bullet.h"
+#include "DefaultCollisionConfiguration.h"
+#include "CollisionDispatcher.h"
+#include "DbvtBroadphase.h"
+#include "SequentialImpulseConstraintSolver.h"
+#include "DiscreteDynamicsWorld.h"
+#include "BoxShape.h"
+#include "Transform.h"
#include "RigidBody.h"
#include <v8.h>
@@ -19,14 +19,14 @@ using namespace node;
extern "C" {
static void init (Handle<Object> target) {
- // Bullet::Initialize(target);
- // DefaultCollisionConfiguration::Initialize(target);
- // CollisionDispatcher::Initialize(target);
- // DbvtBroadphase::Initialize(target);
- // SequentialImpulseConstraintSolver::Initialize(target);
- // DiscreteDynamicsWorld::Initialize(target);
- // BoxShape::Initialize(target);
- // Transform::Initialize(target);
+ Bullet::Initialize(target);
+ DefaultCollisionConfiguration::Initialize(target);
+ CollisionDispatcher::Initialize(target);
+ DbvtBroadphase::Initialize(target);
+ SequentialImpulseConstraintSolver::Initialize(target);
+ DiscreteDynamicsWorld::Initialize(target);
+ BoxShape::Initialize(target);
+ Transform::Initialize(target);
RigidBody::Initialize(target);
}
View
70 test/master.coffee
@@ -1,47 +1,51 @@
Bullet = require '../index'
-#
-# bullet = new Bullet.Bullet
-# console.log bullet
-
-# defaultCollisionConfiguration = new Bullet.DefaultCollisionConfiguration
-# console.log 'defaultCollisionConfiguration', defaultCollisionConfiguration
-# #
-# collisionDispatcher = new Bullet.CollisionDispatcher defaultCollisionConfiguration
-# console.log 'collisionDispatcher', collisionDispatcher
-# #
-# dbvtBroadphase = new Bullet.DbvtBroadphase
-# console.log 'dbvtBroadphase', dbvtBroadphase
-# #
-# sequentialImpulseConstraintSolver = new Bullet.SequentialImpulseConstraintSolver
-# console.log 'sequentialImpulseConstraintSolver', sequentialImpulseConstraintSolver
-
-# discreteDynamicsWorld = new Bullet.DiscreteDynamicsWorld #collisionDispatcher, dbvtBroadphase, sequentialImpulseConstraintSolver, defaultCollisionConfiguration
-# console.log 'discreteDynamicsWorld', discreteDynamicsWorld
-
-# discreteDynamicsWorld.setGravity()
+
+bullet = new Bullet.Bullet
+console.log 'bullet', bullet
+
+defaultCollisionConfiguration = new Bullet.DefaultCollisionConfiguration
+console.log 'defaultCollisionConfiguration', defaultCollisionConfiguration
+
+collisionDispatcher = new Bullet.CollisionDispatcher defaultCollisionConfiguration
+console.log 'collisionDispatcher', collisionDispatcher
+
+dbvtBroadphase = new Bullet.DbvtBroadphase
+console.log 'dbvtBroadphase', dbvtBroadphase
+
+sequentialImpulseConstraintSolver = new Bullet.SequentialImpulseConstraintSolver
+console.log 'sequentialImpulseConstraintSolver', sequentialImpulseConstraintSolver
+
+discreteDynamicsWorld = new Bullet.DiscreteDynamicsWorld collisionDispatcher, dbvtBroadphase, sequentialImpulseConstraintSolver, defaultCollisionConfiguration
+console.log 'discreteDynamicsWorld', discreteDynamicsWorld
+
+discreteDynamicsWorld.setGravity()
# # boxShape = new Bullet.BoxShape
# # console.log 'boxShape', boxShape
#
# # transform = new Bullet.Transform
# # console.log 'transform', transform
-for i in [0..1]
+for i in [0...1000]
rigidBody = new Bullet.RigidBody
console.log 'rigidBody', rigidBody
-# discreteDynamicsWorld.addRigidBody rigidBody
-
-# fps = 0
+discreteDynamicsWorld.addRigidBody rigidBody
gc()
-# setInterval(->
-# fps++
-# # discreteDynamicsWorld.stepSimulation()
-# , 0)
-#
-# setInterval(->
-# console.log fps
-# fps = 0
-# , 1000)
+fps = 0
+
+tick = ->
+ fps++
+ discreteDynamicsWorld.stepSimulation()
+ gc()
+ process.nextTick tick
+
+process.nextTick ->
+ tick()
+
+setInterval(->
+ console.log fps
+ # fps = 0
+, 1000)
View
29 test/master.js
@@ -1,20 +1,33 @@
(function() {
- var Bullet, discreteDynamicsWorld, fps, i, rigidBody;
+ var Bullet, bullet, collisionDispatcher, dbvtBroadphase, defaultCollisionConfiguration, discreteDynamicsWorld, fps, i, rigidBody, sequentialImpulseConstraintSolver, tick;
Bullet = require('../index');
- discreteDynamicsWorld = new Bullet.DiscreteDynamicsWorld;
+ bullet = new Bullet.Bullet;
+ console.log('bullet', bullet);
+ defaultCollisionConfiguration = new Bullet.DefaultCollisionConfiguration;
+ console.log('defaultCollisionConfiguration', defaultCollisionConfiguration);
+ collisionDispatcher = new Bullet.CollisionDispatcher(defaultCollisionConfiguration);
+ console.log('collisionDispatcher', collisionDispatcher);
+ dbvtBroadphase = new Bullet.DbvtBroadphase;
+ console.log('dbvtBroadphase', dbvtBroadphase);
+ sequentialImpulseConstraintSolver = new Bullet.SequentialImpulseConstraintSolver;
+ console.log('sequentialImpulseConstraintSolver', sequentialImpulseConstraintSolver);
+ discreteDynamicsWorld = new Bullet.DiscreteDynamicsWorld(collisionDispatcher, dbvtBroadphase, sequentialImpulseConstraintSolver, defaultCollisionConfiguration);
console.log('discreteDynamicsWorld', discreteDynamicsWorld);
- for (i = 0; i < 10; i++) {
+ discreteDynamicsWorld.setGravity();
+ for (i = 0; i < 1; i++) {
rigidBody = new Bullet.RigidBody;
console.log('rigidBody', rigidBody);
- discreteDynamicsWorld.addRigidBody(rigidBody);
}
+ discreteDynamicsWorld.addRigidBody(rigidBody);
fps = 0;
- setInterval(function() {
+ tick = function() {
fps++;
discreteDynamicsWorld.stepSimulation();
- // gc();
- return;
- }, 0);
+ return process.nextTick(tick);
+ };
+ process.nextTick(function() {
+ return tick();
+ });
setInterval(function() {
console.log(fps);
return fps = 0;

0 comments on commit 2d5c20c

Please sign in to comment.
Something went wrong with that request. Please try again.