chandlerprall / Physijs

Physics plugin for Three.js
MIT License
2.77k stars 455 forks source link

Hinge constraint axis wrong #87

Open nrox opened 11 years ago

nrox commented 11 years ago

Hi,

Checking the way hinge constraints are made in bullet, the axisA is in local coordinates to bodyA and axisB in local coordinates to bodyB. The way it is implemented in Physijs: we pass only one axis, and this will be applyied as both axisA and axisB. This is an error and leads to some strange hinge constraint behavior because the axis are wrong. When you dont perform non orthogonal rotations to the bodies, this issue is not immediately noticed but as you start working with arbitrary rotations this issue will be very clear.

I changed the hinge constraint constructor to accept also axisb as an argument; the hinge constraint definition to include axisb as a parameters, and the worker part that actually calls the Ammo.js constructor. It works fine with this.

Best,

Nuno

chandlerprall commented 11 years ago

Hmm, can you setup a simple example showing how Physijs' hinge has incorrect results?

nrox commented 11 years ago

Here is the example.

Paste it next to your examples.

https://docs.google.com/file/d/0B5Eo_fEgnPl-OUU4MmNjQ2FlOGs/edit?usp=sharing

nrox commented 11 years ago

I guess the strange behavior observed is due to both the incorrect axis definition and the function convertWorldPositionToObject.

raimo commented 10 years ago

I'm also noticing similar behavior in SliderConstraints as well. This also seems to apply to linear movement

nrox commented 10 years ago

To make it coherent I had to change the worker. Those changes are embebed here https://github.com/nrox/assemblino.js/blob/master/public/Physijs/physijs_worker.js

I hope that gives you some hints.

ghost commented 8 years ago

For the slider contraint bug, by reading "Learning three.js, 2nd Edition" by J. Dirksen I found a fix to the current version which is to set the axis in which to slide like this:

• The x axis: new THREE.Vector3(0,1,0) • The y axis: new THREE.Vector3(0,0,Math.PI/2) • The z axis: new THREE.Vector3(Math.PI/2,0,0)

This works but is obviously a hack to this bug.