Permalink
Browse files

checkpoint

  • Loading branch information...
1 parent dd9c40f commit 7a957d233f41a81bd8d136041a36c49d72099a23 Nicholas Kinsey committed Dec 31, 2010
View
@@ -1 +1 @@
-module.exports = require './lib/bullet.coffee'
+module.exports = require './lib/bullet'
View
@@ -0,0 +1,36 @@
+#include "BoxShape.h"
+
+Persistent<FunctionTemplate> BoxShape::constructor;
+
+void
+BoxShape::Initialize(Handle<Object> target) {
+ HandleScope scope;
+
+ constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(BoxShape::New));
+ constructor->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor->SetClassName(String::NewSymbol("BoxShape"));
+
+ Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
+
+ target->Set(String::NewSymbol("BoxShape"), constructor->GetFunction());
+}
+
+Handle<Value>
+BoxShape::New(const Arguments &args) {
+ HandleScope scope;
+
+ BoxShape* boxShape = new BoxShape();
+ boxShape->Wrap(args.This());
+
+ return args.This();
+}
+
+BoxShape::BoxShape(): ObjectWrap() {
+ _btBoxShape = new btBoxShape(btVector3(btScalar(1.0),btScalar(1.0),btScalar(1.0)));
+}
+
+BoxShape::~BoxShape() {
+ if (_btBoxShape) {
+ free(_btBoxShape);
+ }
+}
View
@@ -0,0 +1,28 @@
+#ifndef __NODE_BOXSHAPE_H__
+#define __NODE_BOXSHAPE_H__
+
+#include <v8.h>
+#include <node.h>
+#include <node_object_wrap.h>
+
+#include "btBulletDynamicsCommon.h"
+
+using namespace v8;
+using namespace node;
+
+class BoxShape: public node::ObjectWrap {
+ public:
+ static Persistent<FunctionTemplate> constructor;
+
+ static void Initialize(Handle<Object> target);
+ static Handle<Value> New(const Arguments &args);
+
+ BoxShape();
+
+ btBoxShape* _btBoxShape;
+
+ private:
+ ~BoxShape();
+};
+
+#endif
View
@@ -0,0 +1,32 @@
+#include "DbvtBroadphase.h"
+
+Persistent<FunctionTemplate> DbvtBroadphase::constructor;
+
+void
+DbvtBroadphase::Initialize(Handle<Object> target) {
+ HandleScope scope;
+
+ constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(DbvtBroadphase::New));
+ constructor->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor->SetClassName(String::NewSymbol("DbvtBroadphase"));
+
+ Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
+
+ target->Set(String::NewSymbol("DbvtBroadphase"), constructor->GetFunction());
+}
+
+Handle<Value>
+DbvtBroadphase::New(const Arguments &args) {
+ HandleScope scope;
+
+ DbvtBroadphase* dbvtBroadphase = new DbvtBroadphase();
+ dbvtBroadphase->Wrap(args.This());
+
+ return args.This();
+}
+
+DbvtBroadphase::DbvtBroadphase(): ObjectWrap() {
+}
+
+DbvtBroadphase::~DbvtBroadphase() {
+}
View
@@ -0,0 +1,24 @@
+#ifndef __NODE_DBVTBROADPHASE_H__
+#define __NODE_DBVTBROADPHASE_H__
+
+#include <v8.h>
+#include <node.h>
+#include <node_object_wrap.h>
+
+using namespace v8;
+using namespace node;
+
+class DbvtBroadphase: public node::ObjectWrap {
+ public:
+ static Persistent<FunctionTemplate> constructor;
+
+ static void Initialize(Handle<Object> target);
+ static Handle<Value> New(const Arguments &args);
+
+ DbvtBroadphase();
+
+ private:
+ ~DbvtBroadphase();
+};
+
+#endif
@@ -0,0 +1,113 @@
+#include "DiscreteDynamicsWorld.h"
+
+#include <iostream>
+using namespace std;
+
+Persistent<FunctionTemplate> DiscreteDynamicsWorld::constructor;
+
+void
+DiscreteDynamicsWorld::Initialize(Handle<Object> target) {
+ HandleScope scope;
+
+ constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(DiscreteDynamicsWorld::New));
+ constructor->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor->SetClassName(String::NewSymbol("DiscreteDynamicsWorld"));
+
+ NODE_SET_PROTOTYPE_METHOD(constructor, "setGravity", SetGravity);
+ NODE_SET_PROTOTYPE_METHOD(constructor, "addRigidBody", AddRigidBody);
+ NODE_SET_PROTOTYPE_METHOD(constructor, "stepSimulation", StepSimulation);
+
+ Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
+
+ target->Set(String::NewSymbol("DiscreteDynamicsWorld"), constructor->GetFunction());
+
+ return;
+}
+
+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);
+ discreteDynamicsWorld->Wrap(args.This());
+
+ return scope.Close(args.This());
+}
+
+Handle<Value>
+DiscreteDynamicsWorld::SetGravity(const Arguments &args) {
+ DiscreteDynamicsWorld* discreteDynamicsWorld = ObjectWrap::Unwrap<DiscreteDynamicsWorld>(args.This());
+ discreteDynamicsWorld->_btDiscreteDynamicsWorld->setGravity(btVector3(0, -10, 0));
+
+ return Undefined();
+}
+
+Handle<Value>
+DiscreteDynamicsWorld::AddRigidBody(const Arguments &args) {
+ DiscreteDynamicsWorld* discreteDynamicsWorld = ObjectWrap::Unwrap<DiscreteDynamicsWorld>(args.This());
+
+ Local<Object> rigidBodyHandle = args[0]->ToObject();
+ RigidBody* rigidBody = ObjectWrap::Unwrap<RigidBody>(rigidBodyHandle);
+
+ discreteDynamicsWorld->_btDiscreteDynamicsWorld->addRigidBody(rigidBody->_btRigidBody);
+
+ return Undefined();
+}
+
+Handle<Value>
+DiscreteDynamicsWorld::StepSimulation(const Arguments &args) {
+ DiscreteDynamicsWorld* discreteDynamicsWorld = ObjectWrap::Unwrap<DiscreteDynamicsWorld>(args.This());
+
+ discreteDynamicsWorld->_btDiscreteDynamicsWorld->stepSimulation(100.0);
+
+ // btCollisionObject* obj = discreteDynamicsWorld->_btDiscreteDynamicsWorld->getCollisionObjectArray()[0];
+ // btRigidBody* 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()));
+ // }
+ //
+ // 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 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() {
+ if (_btDiscreteDynamicsWorld) {
+ free(_btDiscreteDynamicsWorld);
+ }
+}
@@ -0,0 +1,38 @@
+#ifndef __NODE_DISCRETEDYNAMICSWORLD_H__
+#define __NODE_DISCRETEDYNAMICSWORLD_H__
+
+#include <v8.h>
+#include <node.h>
+#include <node_object_wrap.h>
+
+#include "CollisionDispatcher.h"
+#include "DbvtBroadphase.h"
+#include "SequentialImpulseConstraintSolver.h"
+#include "DefaultCollisionConfiguration.h"
+#include "RigidBody.h"
+
+#include "btBulletDynamicsCommon.h"
+
+using namespace v8;
+using namespace node;
+
+class DiscreteDynamicsWorld: public node::ObjectWrap {
+ public:
+ static Persistent<FunctionTemplate> constructor;
+
+ static void Initialize(Handle<Object> target);
+ static Handle<Value> New(const Arguments &args);
+
+ static Handle<Value> SetGravity(const Arguments &args);
+ static Handle<Value> AddRigidBody(const Arguments &args);
+ static Handle<Value> StepSimulation(const Arguments &args);
+
+ DiscreteDynamicsWorld(CollisionDispatcher* collisionDispatcher, DbvtBroadphase* dbvtBroadphase, SequentialImpulseConstraintSolver* sequentialImpulseConstraintSolver, DefaultCollisionConfiguration* defaultCollisionConfiguration);
+
+ btDiscreteDynamicsWorld* _btDiscreteDynamicsWorld;
+
+ private:
+ ~DiscreteDynamicsWorld();
+};
+
+#endif
View
@@ -0,0 +1,47 @@
+#include "RigidBody.h"
+
+Persistent<FunctionTemplate> RigidBody::constructor;
+
+void
+RigidBody::Initialize(Handle<Object> target) {
+ HandleScope scope;
+
+ constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(RigidBody::New));
+ constructor->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor->SetClassName(String::NewSymbol("RigidBody"));
+
+ Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
+
+ target->Set(String::NewSymbol("RigidBody"), constructor->GetFunction());
+}
+
+Handle<Value>
+RigidBody::New(const Arguments &args) {
+ HandleScope scope;
+
+ RigidBody* rigidBody = new RigidBody();
+ rigidBody->Wrap(args.This());
+
+ return scope.Close(args.This());
+}
+
+RigidBody::RigidBody(): ObjectWrap() {
+ btTransform transform;
+ transform.setIdentity();
+ transform.setOrigin(btVector3(0, 0, 0));
+
+ btScalar mass(1.0);
+ btVector3 localInertia(0, 0, 0);
+
+ btDefaultMotionState* defaultMotionState = new btDefaultMotionState(transform);
+ btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(1.0), btScalar(1.0), btScalar(1.0)));
+ groundShape->calculateLocalInertia(mass, localInertia);
+ btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, defaultMotionState, groundShape, localInertia);
+ _btRigidBody = new btRigidBody(rbInfo);
+}
+
+RigidBody::~RigidBody() {
+ if (_btRigidBody) {
+ free(_btRigidBody);
+ }
+}
View
@@ -0,0 +1,28 @@
+#ifndef __NODE_RIGIDBODY_H__
+#define __NODE_RIGIDBODY_H__
+
+#include <v8.h>
+#include <node.h>
+#include <node_object_wrap.h>
+
+#include "btBulletDynamicsCommon.h"
+
+using namespace v8;
+using namespace node;
+
+class RigidBody: public node::ObjectWrap {
+ public:
+ static Persistent<FunctionTemplate> constructor;
+
+ static void Initialize(Handle<Object> target);
+ static Handle<Value> New(const Arguments &args);
+
+ RigidBody();
+
+ btRigidBody* _btRigidBody;
+
+ private:
+ ~RigidBody();
+};
+
+#endif
Oops, something went wrong.

0 comments on commit 7a957d2

Please sign in to comment.