This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The "optimal" velocity is the velocity needed to bring us to | |
// the target angle in a single physics step. | |
var optimalVelocity = targetAngle / dt; | |
// The "optimal" torque is the amount of torque needed this | |
// frame to achieve the "optimal" velocity. | |
var optimalTorque = ( optimalVelocity - angularVelocity ) / ( dt * inverseInertia ); | |
var desiredTorqueSign = nonZeroSign( desiredTorque ); | |
if ( desiredTorqueSign === nonZeroSign(optimalTorque) ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We're traveling in the same direction we want to go, so do we | |
// need to brake? | |
var brakeDist = 0; | |
var wantsBrake = false; | |
if ( result.ccw === angularVelocity > 0 ) { | |
var brakeTime = -angularVelocity / ( brakeTorque * inverseInertia ); | |
brakeDist = brakeTime * angularVelocity * 0.5; | |
wantsBrake = Math.abs(brakeDist) - Math.abs(targetAngle) > -0.01; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( Math.abs(targetAngle) < 0.01 ) { | |
var freeze = false; | |
var freezeAccel; | |
if ( angularVelocity > 0 ) { | |
freezeAccel = maxCW * inverseInertia; | |
freeze = angularVelocity + freezeAccel * dt < 0; | |
} else { | |
freezeAccel = maxCCW * inverseInertia; | |
freeze = angularVelocity + freezeAccel * dt > 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Target angle is closest via CW. | |
var brakeTorque, desiredTorque; | |
if ( targetAngle < 0 ) { | |
if ( targetAngle < -Math.PI ) { | |
console.warn( 'targetAngle < -π: targetAngle =', targetAngle ); | |
} | |
desiredTorque = maxCW; | |
brakeTorque = maxCCW; | |
result.ccw = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calculate normalized target vector to heading. | |
var globalHeading = input.faceHeading; | |
Vec2.setFromValues( | |
targetDir, | |
Math.cos( globalHeading ), | |
Math.sin( globalHeading ) | |
); | |
// Calculate angle between forward vector and target vector. | |
Mat2.multVec2( xf.rotation, LOCAL_FORWARD, forward ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MLTS.prototype.calculateThrusterValues = function() { | |
this.maxForward = 0; | |
this.maxBackward = 0; | |
this.maxRight = 0; | |
this.maxLeft = 0; | |
this.maxCCW = 0; | |
this.maxCW = 0; | |
this.model.thrusters.forEach(function( thruster ) { | |
if ( thruster.isAttached ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a JS component interface. | |
// It acts as the window to the physics layer. It also emits collision events | |
// that have been processed / generated by the CollisionEventDispatcher. | |
function Physics () { | |
this.physicsId = null; | |
// would store serializable physics properties like: | |
// linear velocity | |
// angular velocity | |
// anything else needed for backing up physics state | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MIN_LAG=25 | |
MAX_LAG=50 | |
(( LAG_RANGE = MAX_LAG - MIN_LAG )) | |
TIME=600 # total test time (in seconds) | |
INTERVAL=0.1 # time in between changes in latency (in seconds) | |
STEPS=6000 # TIME / INTERVAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo ipfw add 100 pipe 1 ip from 127.0.0.1 to 127.0.0.1 in | |
$ sudo ipfw add 100 allow ip from 127.0.0.1 to 127.0.0.1 out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo ipfw pipe 1 config delay 100ms | |
$ sudo ipfw add 100 pipe 1 ip from 127.0.0.1 to 127.0.0.1 |