Skip to content

Commit

Permalink
back to _X
Browse files Browse the repository at this point in the history
  • Loading branch information
lo-th committed Feb 10, 2017
1 parent 62912ca commit 6c3e7e7
Show file tree
Hide file tree
Showing 15 changed files with 6,002 additions and 4,918 deletions.
5,359 changes: 2,923 additions & 2,436 deletions build/oimo.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions build/oimo.min.js

Large diffs are not rendered by default.

5,359 changes: 2,923 additions & 2,436 deletions build/oimo.module.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions examples/test_vehicle.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@
//var axis2 = new OIMO.Vec3( x[2], x[5], x[8]);
var axis2 = new OIMO.Vec3( x[1], x[4], x[7]);
//var axis2 = new OIMO.Vec3( x[0], x[3], x[6]);
var axis3 = new OIMO.Vec3().sub(axis2, axis1.scaleEqual(axis1.dot(axis2)));
w.orientation.mul( new OIMO.Quat().arc(axis2, axis3.normalize(axis3)), w.orientation );
w.orientation.normalize( w.orientation );
var axis3 = new OIMO.Vec3().subVectors( axis2, axis1.scaleEqual( axis1.dot(axis2) ) ).normalize();
//w.orientation.multiply( new OIMO.Quat().arc( axis2, axis3 ) );
w.orientation.multiply( new OIMO.Quat().setFromUnitVectors( axis2, axis3 ) );
w.orientation.normalize();
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oimo",
"version": "1.0.7",
"version": "1.0.8",
"description": "JavaScript 3D physics engine.",
"main": "build/oimo.js",
"repository": "lo-th/oimo",
Expand Down
8 changes: 4 additions & 4 deletions src/Oimo.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ export { JointConfig } from './constraint/joint/JointConfig.js';



//export { RigidBody } from './core/RigidBody.js';
//export { World } from './core/World.js';
export { RigidBody } from './core/RigidBody.js';
export { World } from './core/World.js';

// test version

export { RigidBody } from './core/RigidBody_X.js';
export { World } from './core/World_X.js';
//export { RigidBody } from './core/RigidBody_X.js';
//export { World } from './core/World_X.js';
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* the physics engine.
*/

export var REVISION = '1.0.7';
export var REVISION = '1.0.8';

// BroadPhase
export var BR_NULL = 0;
Expand Down
13 changes: 12 additions & 1 deletion src/constraint/contact/Contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ function Contact(){
this.constraint = null;
// Whether the shapes are touching or not.
this.touching = false;
// shapes is very close and touching
this.close = false;

this.dist = _Math.INF;

this.b1Link = new ContactLink( this );
this.b2Link = new ContactLink( this );
Expand Down Expand Up @@ -95,9 +99,13 @@ Object.assign( Contact.prototype, {
this.detector.detectCollision(this.shape1,this.shape2,this.manifold);
var num=this.manifold.numPoints;
if(num==0){
this.touching=false;
this.touching = false;
this.close = false;
this.dist = _Math.INF;
return;
}

if( this.touching || this.dist < 0.001 ) this.close = true;
this.touching=true;
i = num;
while(i--){
Expand Down Expand Up @@ -134,6 +142,9 @@ Object.assign( Contact.prototype, {
index=j;
}
}

if( minDistance < this.dist ) this.dist = minDistance;

}
if(index!=-1){
var tmp=this.buffer[index];
Expand Down
5 changes: 4 additions & 1 deletion src/constraint/contact/ContactConstraint.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ContactConstraint.prototype = Object.assign( Object.create( Constraint.prototype
this.num = this.manifold.numPoints;

var c = this.cs;
var p, rvn, len, norImp, norTar, sepV;
var p, rvn, len, norImp, norTar, sepV, i1, i2;;

for( var i=0; i < this.num; i++ ){

Expand Down Expand Up @@ -154,6 +154,9 @@ ContactConstraint.prototype = Object.assign( Object.create( Constraint.prototype
c.tanT2.crossVectors( this.tmpP2, c.tan );
c.binT2.crossVectors( this.tmpP2, c.bin );

i1 = this.i1;
i2 = this.i2;

c.norTU1.copy( c.norT1 ).applyMatrix3( i1, true );
c.tanTU1.copy( c.tanT1 ).applyMatrix3( i1, true );
c.binTU1.copy( c.binT1 ).applyMatrix3( i1, true );
Expand Down
1 change: 1 addition & 0 deletions src/constraint/contact/Contact_X.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Object.assign( Contact.prototype, {
if( num === 0 ){
this.touching = false;
this.close = false;
this.dist = _Math.INF;
return;
}

Expand Down
68 changes: 54 additions & 14 deletions src/core/RigidBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function RigidBody ( Position, Rotation, scale, invScale ) {
// possible link to three Mesh;
this.mesh = null;

this.id = NaN;
this.name = "";
// The maximum number of shapes that can be added to a one rigid.
//this.MAX_SHAPES = 64;//64;
Expand All @@ -53,6 +54,9 @@ function RigidBody ( Position, Rotation, scale, invScale ) {
this.controlRot = false;
this.controlRotInTime = false;

this.quaternion = new Quat();
this.pos = new Vec3();



// Is the translational velocity.
Expand Down Expand Up @@ -87,6 +91,9 @@ function RigidBody ( Position, Rotation, scale, invScale ) {
this.isStatic = false;
// I indicates that this rigid body to determine whether it is a rigid body dynamic.
this.isDynamic = false;

this.isKinematic = false;

// It is a rotation matrix representing the orientation.
this.rotation = new Mat33();

Expand Down Expand Up @@ -121,6 +128,18 @@ function RigidBody ( Position, Rotation, scale, invScale ) {

Object.assign( RigidBody.prototype, {

setParent: function ( world ) {

this.parent = world;
this.scale = this.parent.scale;
this.invScale = this.parent.invScale;
this.id = this.parent.numRigidBodies;
if( !this.name ) this.name = this.id;

this.updateMesh();

},

/**
* I'll add a shape to rigid body.
* If you add a shape, please call the setupMass method to step up to the start of the next.
Expand Down Expand Up @@ -336,19 +355,22 @@ Object.assign( RigidBody.prototype, {
break;
case BODY_DYNAMIC:

if(this.controlPos){
if( this.isKinematic ){

this.angularVelocity.set(0,0,0);
this.linearVelocity.set(0,0,0);
this.linearVelocity.x = (this.newPosition.x - this.position.x)/timeStep;
this.linearVelocity.y = (this.newPosition.y - this.position.y)/timeStep;
this.linearVelocity.z = (this.newPosition.z - this.position.z)/timeStep;
this.angularVelocity.set(0,0,0);

}

if(this.controlPos){

this.linearVelocity.subVectors( this.newPosition, this.position ).multiplyScalar(1/timeStep);
this.controlPos = false;

}
if(this.controlRot){

this.angularVelocity.set(0,0,0);
this.angularVelocity.copy( this.getAxis() );
this.orientation.copy( this.newOrientation );
this.controlRot = false;

Expand All @@ -357,6 +379,8 @@ Object.assign( RigidBody.prototype, {
this.position.addScaledVector(this.linearVelocity, timeStep);
this.orientation.addTime(this.angularVelocity, timeStep);

this.updateMesh();

break;
default: printError("RigidBody", "Invalid type.");
}
Expand All @@ -366,6 +390,12 @@ Object.assign( RigidBody.prototype, {

},

getAxis: function () {

return new Vec3( 0,1,0 ).applyMatrix3( this.inverseLocalInertia, true ).normalize();

},

rotateInertia: function ( rot, inertia, out ) {

this.tmpInertia.multiplyMatrices( rot, inertia );
Expand All @@ -388,12 +418,10 @@ Object.assign( RigidBody.prototype, {
},


/**
* Apply impulse force.
*
* @method applyImpulse
* @return void
*/
//---------------------------------------------
// APPLY IMPULSE FORCE
//---------------------------------------------

applyImpulse: function(position, force){
this.linearVelocity.addScaledVector(force, this.inverseMass);
var rel = new Vec3().copy( position ).sub( this.position ).cross( force ).applyMatrix3( this.inverseInertia, true );
Expand All @@ -408,11 +436,13 @@ Object.assign( RigidBody.prototype, {
setPosition: function(pos){
this.newPosition.copy( pos ).multiplyScalar( this.invScale );
this.controlPos = true;
if( !this.isKinematic ) this.isKinematic = true;
},

setQuaternion: function(q){
this.newOrientation.set(q.x, q.y, q.z, q.w);
this.controlRot = true;
if( !this.isKinematic ) this.isKinematic = true;
},

setRotation: function ( rot ) {
Expand Down Expand Up @@ -457,22 +487,32 @@ Object.assign( RigidBody.prototype, {

getPosition:function () {

return new Vec3().scale( this.position, this.scale );
return this.pos;

},

getQuaternion: function () {

return new Quat().setFromRotationMatrix( this.rotation );
return this.quaternion;

},

//---------------------------------------------
// AUTO UPDATE THREE MESH
//---------------------------------------------

connectMesh: function ( mesh ) {

this.mesh = mesh;
this.updateMesh();

},

updateMesh: function(){

this.pos.scale( this.position, this.scale );
this.quaternion.copy( this.orientation );

if( this.mesh === null ) return;

this.mesh.position.copy( this.getPosition() );
Expand Down
3 changes: 1 addition & 2 deletions src/core/RigidBody_X.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ Object.assign( RigidBody.prototype, {

if( this.controlPos ){

this.tmpPos.sub( this.newPosition, this.position );
this.linearVelocity.scale( this.tmpPos, (1/timeStep) );
this.linearVelocity.subVectors( this.newPosition, this.position ).multiplyScalar(1/timeStep);
this.controlPos = false;

}
Expand Down
Loading

0 comments on commit 6c3e7e7

Please sign in to comment.