add *some* MP crushing thing, buggy but i guess ill leave it at itt

This commit is contained in:
RandomityGuy 2021-05-31 14:52:47 +05:30
parent 2d4065ccd8
commit 38f77c3003
2 changed files with 87 additions and 16 deletions

View file

@ -164,7 +164,7 @@ class Marble extends Object {
return {result: true, aControl: aControl, desiredOmega: desiredOmega};
}
function velocityCancel(surfaceSlide:Bool, noBounce:Bool) {
function velocityCancel(surfaceSlide:Bool, noBounce:Bool, stoppedPaths:Bool, pi:Array<PathedInterior>) {
var SurfaceDotThreshold = 0.001;
var looped = false;
var itersIn = 0;
@ -235,8 +235,18 @@ class Marble extends Object {
}
}
looped = true;
if (itersIn > 6 && noBounce) {
done = true;
if (itersIn > 6 && !stoppedPaths) {
stoppedPaths = true;
if (noBounce)
done = true;
for (contact in contacts) {
contact.velocity = new Vector();
}
for (interior in pi) {
interior.setStopped();
}
}
} while (!done);
if (this.velocity.lengthSq() < 625) {
@ -278,6 +288,8 @@ class Marble extends Object {
this.velocity = this.velocity.add(dir.multiply(soFar));
}
}
return stoppedPaths;
}
function applyContactForces(dt:Float, m:Move, isCentered:Bool, aControl:Vector, desiredOmega:Vector, A:Vector) {
@ -445,6 +457,23 @@ class Marble extends Object {
var it = 0;
var piTime = currentTime;
// if (this.controllable) {
// for (interior in pathedInteriors) {
// // interior.pushTickState();
// interior.recomputeVelocity(piTime + 0.032, 0.032);
// }
// }
if (this.controllable) {
for (interior in pathedInteriors) {
// interior.popTickState();
interior.setStopped(false);
// interior.recomputeVelocity(piTime + 0.032, 0.032);
// interior.update(piTime, timeStep);
}
}
do {
if (timeRemaining <= 0)
break;
@ -458,14 +487,15 @@ class Marble extends Object {
var isCentered:Bool = cmf.result;
var aControl = cmf.aControl;
var desiredOmega = cmf.desiredOmega;
this.velocityCancel(isCentered, false);
var stoppedPaths = false;
stoppedPaths = this.velocityCancel(isCentered, false, stoppedPaths, pathedInteriors);
var A = this.getExternalForces(m, timeStep);
var retf = this.applyContactForces(timeStep, m, isCentered, aControl, desiredOmega, A);
A = retf[0];
var a = retf[1];
this.velocity = this.velocity.add(A.multiply(timeStep));
this.omega = this.omega.add(a.multiply(timeStep));
this.velocityCancel(isCentered, true);
stoppedPaths = this.velocityCancel(isCentered, true, stoppedPaths, pathedInteriors);
this._totalTime += timeStep;
if (contacts.length != 0) {
this._contactTime += timeStep;
@ -483,6 +513,8 @@ class Marble extends Object {
piTime += timeStep;
if (this.controllable) {
for (interior in pathedInteriors) {
// interior.popTickState();
// interior.setStopped(stoppedPaths);
interior.update(piTime, timeStep);
}
}

View file

@ -28,6 +28,9 @@ class PathedInterior extends InteriorGeometry {
public var velocity:Vector;
var stopped:Bool = false;
var stopTime:Float;
var previousState:PIState;
public function new() {
@ -40,6 +43,49 @@ class PathedInterior extends InteriorGeometry {
}
public function update(currentTime:Float, dt:Float) {
// this.previousState = {
// currentTime: currentTime,
// targetTime: targetTime,
// changeTime: changeTime,
// prevPosition: prevPosition,
// currentPosition: currentPosition,
// velocity: velocity
// };
if (stopped) {
currentTime = stopTime;
popTickState();
}
var transform = this.getTransformAtTime(this.getInternalTime(currentTime));
this.updatePosition();
var position = transform.getPosition();
this.prevPosition = this.currentPosition;
this.currentPosition = position;
if (!stopped) {
this.stopTime = currentTime;
pushTickState();
}
// if (!stopped)
// this.currentTime = currentTime;
velocity = position.sub(this.prevPosition).multiply(1 / dt);
}
public function setStopped(stopped:Bool = true) {
// if (!this.stopped)
// this.stopTime = currentTime;
this.stopped = stopped;
}
public function recomputeVelocity(currentTime:Float, dt:Float) {
var transform = this.getTransformAtTime(this.getInternalTime(currentTime));
var position = transform.getPosition();
velocity = position.sub(this.currentPosition).multiply(1 / dt);
}
public function pushTickState() {
this.previousState = {
currentTime: currentTime,
targetTime: targetTime,
@ -48,25 +94,16 @@ class PathedInterior extends InteriorGeometry {
currentPosition: currentPosition,
velocity: velocity
};
var transform = this.getTransformAtTime(this.getInternalTime(currentTime));
this.updatePosition();
var position = transform.getPosition();
this.prevPosition = this.currentPosition;
this.currentPosition = position;
velocity = position.sub(this.prevPosition).multiply(1 / dt);
}
public function rollBack() {
public function popTickState() {
this.currentTime = this.previousState.currentTime;
this.targetTime = this.previousState.targetTime;
this.changeTime = this.previousState.changeTime;
this.prevPosition = this.previousState.prevPosition;
this.currentPosition = this.previousState.currentPosition;
this.velocity = this.previousState.velocity;
this.updatePosition();
// this.updatePosition();
}
function computeDuration() {
@ -169,6 +206,8 @@ class PathedInterior extends InteriorGeometry {
this.currentTime = 0;
this.targetTime = -1;
this.changeTime = 0;
this.stopTime = 0;
this.stopped = false;
// Reset the position
var transform = this.getTransformAtTime(this.getInternalTime(0));
var position = transform.getPosition();