Skip to content

Commit

Permalink
car can now turn!
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed Feb 7, 2013
1 parent de01bcc commit 74d2e05
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
7 changes: 6 additions & 1 deletion build/cannon.js
Original file line number Diff line number Diff line change
Expand Up @@ -5681,12 +5681,17 @@ CANNON.HingeConstraint = function(bodyA, pivotA, axisA, bodyB, pivotB, axisB, ma
// Update
this.update = function(){
// Update world positions of pivots
/*
bodyB.position.vsub(bodyA.position,normal.ni);
normal.ni.normalize();
*/
normal.ni.set(1,0,0);
t1.ni.set(0,1,0);
t2.ni.set(0,0,1);
bodyA.quaternion.vmult(pivotA,normal.ri);
bodyB.quaternion.vmult(pivotB,normal.rj);

normal.ni.tangents(t1.ni,t2.ni);
//normal.ni.tangents(t1.ni,t2.ni);
normal.ri.copy(t1.ri);
normal.rj.copy(t1.rj);
normal.ri.copy(t2.ri);
Expand Down
2 changes: 1 addition & 1 deletion build/cannon.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions demos/rotational.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

demo.addScene("car",function(){
var world = demo.getWorld();
world.gravity.set(0,0,-5);
world.gravity.set(0,0,-20);

var groundMaterial = new CANNON.Material("groundMaterial");
var wheelMaterial = new CANNON.Material("wheelMaterial");
var wheelGroundContactMaterial = new CANNON.ContactMaterial(groundMaterial,wheelMaterial, 0.1, 0.3);
var wheelGroundContactMaterial = new CANNON.ContactMaterial(groundMaterial,wheelMaterial, 0.5, 0.3);
world.addContactMaterial(wheelGroundContactMaterial);

var wheelShape = new CANNON.Sphere(1.2);
Expand Down Expand Up @@ -60,8 +60,8 @@
var leftFrontAxis = new CANNON.Vec3(0,1,0);
var rightFrontAxis = new CANNON.Vec3(0,-1,0);
if(true){
leftFrontAxis = new CANNON.Vec3(-0.3,0.7,0);
rightFrontAxis = new CANNON.Vec3(0.3,-0.7,0);
leftFrontAxis = new CANNON.Vec3(0.3,0.7,0);
rightFrontAxis = new CANNON.Vec3(-0.3,-0.7,0);
leftFrontAxis.normalize();
rightFrontAxis.normalize();
}
Expand Down Expand Up @@ -92,7 +92,7 @@
var frontRightHinge = constraints[3];
frontLeftHinge.enableMotor();
frontRightHinge.enableMotor();
var v = -8;
var v = -14;
frontLeftHinge.motorTargetVelocity = v;
frontRightHinge.motorTargetVelocity = -v;

Expand Down
7 changes: 6 additions & 1 deletion src/constraints/HingeConstraint.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ CANNON.HingeConstraint = function(bodyA, pivotA, axisA, bodyB, pivotB, axisB, ma
// Update
this.update = function(){
// Update world positions of pivots
/*
bodyB.position.vsub(bodyA.position,normal.ni);
normal.ni.normalize();
*/
normal.ni.set(1,0,0);
t1.ni.set(0,1,0);
t2.ni.set(0,0,1);
bodyA.quaternion.vmult(pivotA,normal.ri);
bodyB.quaternion.vmult(pivotB,normal.rj);

normal.ni.tangents(t1.ni,t2.ni);
//normal.ni.tangents(t1.ni,t2.ni);
normal.ri.copy(t1.ri);
normal.rj.copy(t1.rj);
normal.ri.copy(t2.ri);
Expand Down

0 comments on commit 74d2e05

Please sign in to comment.