josephg / chipmunk-js Goto Github PK
View Code? Open in Web Editor NEWPort of slembcke/Chipmunk-Physics to Javascript
Home Page: http://dl.dropbox.com/u/2494815/demo/Joints.html
Port of slembcke/Chipmunk-Physics to Javascript
Home Page: http://dl.dropbox.com/u/2494815/demo/Joints.html
Demo link off
box1.shape.setCollisionType(3);
box2.shape.setCollisionType(8);
Space.addCollisionHandler(3,8, null, function(){alert(1)});
Alert is called
But real world application requires a target for function to call
box1.shape.setCollisionType(3);
box2.shape.setCollisionType(8);
box1.hi = "hello";
box1.sayHi = function(){
alert(this.hi);
};
Space.addCollisionHandler(3,8, null, box1.sayHi);
you get undefined, because what ever object calling "sayHi()" it does not have .hi attribute
Any idea how to fix this?
In cocos2d-html5, our callback handler function accepts a function with a target like
X.addCallback(target, obj.func)
Port the C code to emscripten and benchmark it.
Probably wrong context is used in SpatialIndex.prototype.collideStatic.
SpatialIndex.prototype.collideStatic = function(staticIndex, func)
{
if(staticIndex.count > 0){
var query = staticIndex.query;
var self = this;
this.each(function(obj) {
// Wrong call: query(self, obj, new BB(obj.bb_l, obj.bb_b, obj.bb_r, obj.bb_t), func);
query.call(self, obj, new BB(obj.bb_l, obj.bb_b, obj.bb_r, obj.bb_t), func);
});
}
};
Hey I am using the "Tank Demo" method of controlling a top down player. That is, a control body is created attached to the player body via pivot and gear constraint, and then when movement controls are pressed I set the velocity of the control body.
Here is how I create and attach my bodies:
var body = new cp.Body(1, Infinity),
cbody = new cp.Body(Infinity, Infinity),
cpivot = new cp.PivotJoint(cbody, body, cp.vzero, cp.vzero),
cgear = new cp.GearJoint(cbody, body, 0, 1);
cpivot.maxBias = 0; //disable join correction
cpivot.maxForce = 10000; //emulate linear friction
cgear.errorBias = 0; //attempt to fully correct the joint each step
cgear.maxBias = 1.2; //but limit the angular correction
cgear.maxForce = 50000; //emulate angular friction
space.addBody(body);
space.addBody(cbody);
space.addConstraint(cpivot);
space.addConstraint(cgear);
Each frame I step the space and update my sprites like so:
space.step(dt); //dt is time since last frame in seconds
//go through each changed shape
space.activeShapes.each(function(shape) {
var spr = shape.sprite; //I set this when the shape is created so I have the ref here
spr.position.x = shape.body.p.x;
spr.position.y = shape.body.p.y;
spr.rotation = shape.body.a;
});
What I am seeing is jerky movement. Specifically there are micro teleportations as the player moves. I have tried everything I can think of, but I can't figure out why the movement isn't smooth. Happen to have any ideas?
Google closure compiler advanced mode obfuscate codes.
commercial release has the need to protect their code
Please look into this to make chipmunk viable for commercial release
Currently the benchmarks take upwards of 15 minutes to run. It's really hard to determine, for a given change, whether a performance regression was introduced.
Possible solutions:
It would also be nice to be able to easily compute baseline numbers, e.g. by 'node bench.js --did-i-regress' performing a git clone into a temporary directory and running the benchmarks at origin/master, then running with your changes.
Why? When I was looking for a better 3D matrix lib a few months ago, glMatrix was the all-around winner in these benchmarks. Apparently using Arrays instead of Objects is a big win in JS. Vectors in chipmunk-js currently aren't very OO-like, so this change might be reasonable...
Pros: faster! (and less cumbersome IMHO)
Cons: unlike Chipmunk-C conventions; requires 146 changes; will break any code that manipulates .x/.y
I might be willing to try this in my fork. Any thoughts?
Hi,
I'm writting a 2d math library: js-2dmath to do a real test, I choose to rewrite some of your code (cpVec2 atm) and use mine. The speed boost was so good... I'm really happy but...
There is a problem, js-2dmath use arrays and Chipmunk-js objects/prototypes.
So before PR and cleanup are you really interested ? it's a hard change.
Another possibility is to use falafel to rewrite the code, dont know if it's really possible...
These are my numbers
Firefox (10%)
Chrome (16%)
Test my fork with
git clone https://github.com/llafuente/Chipmunk-js
cd Chipmunk-js && npm install
firefox benchmark/bench.html
DropBox is blocked by China GFW, Our Chinese people can only access your demo page by VPN. it's a little bit inconvenience for us.
A Demo branch would be more convenience, we will appreciate you so much :)
I know you haven't maintained this repo for a while... but i found an issue with static bodies...
I tried creating a static body and moving it and it doesnt seem to work.
I tried also moving the static shape using shape.update() but it also doesn't work
There is no way to move a static shapes?
If space don't have static objects, in 2565 lines in cp.js file
if(this.root) subtreeQuery(this.root, bb, func);
this
- global node js object, and it have root
property. And the condition is true, although this
don't cp.BBTree
. Additional check on the this instanceof cp.BBTree
solves the problem.
npm WARN engine [email protected]: wanted: {"node":"~0.6.5"} (current: {"node":"0.10.34","npm":"2.6.1"})```
Hi,
In my opinion CP shouldn't set the window.cp global if module.exports exists. i.e. If someone is using commonJS module system, they probably don't want the global being there and will instead 'require' in the lib as needed.
So the top should look something like:
var cp;
if(typeof exports === 'undefined'){
cp = {};
if(typeof window === 'object'){
window.cp = cp;
}
} else {
cp = exports;
}
Hi guys,
I am creating JavaScript bindings (to be used in mobile games) for the Chipmunk (the C version), and the JS API that I am generating will be 100% compatible with yours.
So, people will be able to use the same JS API for mobile games, and web games.
The JS bindings for Chipmunk project could be found here:
https://github.com/zynga/jsbindings#readme
And more info about cocos2d+chipmunk JS Bindings here:
https://github.com/cocos2d/cocos2d-iphone/wiki/cocos2d-and-JavaScript
What the best way to be in contact with you ?
My email is: ricardoquesada at gmail
https://github.com/josephg/Chipmunk-js/blob/master/lib/cpBBTree.js#L33
this.count = 0;
https://github.com/josephg/Chipmunk-js/blob/master/lib/cpBBTree.js#L617
BBTree.prototype.count = function()
I'm sure it can't be both.
I downloaded the cp.min.js file, then tried to create a body. Then I get an error Uncaught TypeError: this.setMass is not a function. I use cp.js and the same error happens. I delete all other libraries that I'm using, and still it doesn't work. To reproduce:
var space = new cp.Space();
var mass = 100;
var radius = 25;
var moment = cp.momentForCircle(mass, 20, radius, cp.vzero);
var body = cp.Body(mass, moment);
In https://github.com/slembcke/Chipmunk2D/blob/dbc983e3f3f2f7269aca8d21ba64085c00130172/src/cpRotaryLimitJoint.c
getImpulse takes a 'joint' argument.
This is missing, here:
https://github.com/josephg/Chipmunk-js/blob/master/cp.js#L5913
NoCollide node.js:134 throw e; // process.nextTick error, or 'error' event on first tick ^ ReferenceError: Exception is not defined at [object Object].begin (/Users/jeremya/Source/Chipmunk-js/bench.js:6541:2)
Remove or implement :)
seg2seg function does nothing. implement method from chipmunk proper.
This issue serves as a report about a potential bug in the function cp.Body.applyForce
. I believe that it is mis-implemented as the function cp.Body.applyForce
.
According to Chipmunk documentations, this function applys force $
However, in line 1767, cp.js
, the function is implemented as
Body.prototype.applyForce = function(force, r)
{
this.activate();
this.f = vadd(this.f, force);
this.t += vcross(r, force);
};
This leads to add $
To apply force, the code should be
Body.prototype.applyForce = function(force, r)
{
this.activate();
// this.f = vadd(this.f, force);
this.f = force;
this.t += vcross(r, force);
};
I hope the team could check and fix this bug. Thanks for your attention.
These would not only let Typescript users use chipmunk-js conveniently, it'd also let some other languages like F# and Scala (which I'm using) interop more conveniently. Given that chipmunk-js follows the C library pretty closely, it should be pretty straightforward (if tedious) to mark out the type signatures for the various functions and methods.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.