kripken / box2d.js

Port of Box2D to JavaScript using Emscripten
1.33k stars 196 forks source link

Odd results from op_add/op_sub #10

Open iforce2d opened 11 years ago

iforce2d commented 11 years ago

This:

var a = new b2Vec2( 9, 6 );
var b = new b2Vec2( 2, 3 );
a.op_add(b);
console.log( a.get_x() + ", " + a.get_y() );

... prints "11, 9" -> correct

Changing the third line to

a.op_sub(b);

... prints "9, 6" -> incorrect

Interestingly, assigning the return value like:

var c = a.op_sub(b);
console.log( c.get_x() + ", " + c.get_y() );

... prints "-9, -6" while:

var c = a.op_add(b);
console.log( c.get_x() + ", " + c.get_y() );

... gives: Uncaught TypeError: Cannot call method 'get_x' of undefined

On a related note:

 a.op_set(b);

... gives: Uncaught TypeError: Object # has no method 'op_set'

Given that embind will replace these bindings I guess this is very low priority, but I just thought I would point out that there is something weird going on here :)