mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 13:11:42 +00:00
More CCD fixes
This commit is contained in:
parent
fba3ab55a4
commit
971a397a63
2 changed files with 51 additions and 45 deletions
29
src/Main.hx
29
src/Main.hx
|
|
@ -38,8 +38,8 @@ class Main extends hxd.App {
|
||||||
override function init() {
|
override function init() {
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
// dtsObj = new SuperSpeed();
|
dtsObj = new SuperSpeed();
|
||||||
// dtsObj.x = -3;
|
dtsObj.x = -3;
|
||||||
|
|
||||||
world = new MarbleWorld(s3d);
|
world = new MarbleWorld(s3d);
|
||||||
|
|
||||||
|
|
@ -89,23 +89,28 @@ class Main extends hxd.App {
|
||||||
|
|
||||||
// world.addPathedInterior(pi);
|
// world.addPathedInterior(pi);
|
||||||
|
|
||||||
// world.addDtsObject(dtsObj);
|
world.addDtsObject(dtsObj);
|
||||||
|
|
||||||
// var sj = new SuperJump();
|
var sj = new SuperJump();
|
||||||
// sj.x = 3;
|
sj.x = 3;
|
||||||
// world.addDtsObject(sj);
|
world.addDtsObject(sj);
|
||||||
|
|
||||||
// var sb = new SuperBounce();
|
var sj2 = new SuperJump();
|
||||||
// sb.y = 3;
|
sj2.x = 3;
|
||||||
// world.addDtsObject(sb);
|
sj2.z = 2;
|
||||||
|
world.addDtsObject(sj2);
|
||||||
|
|
||||||
|
var sb = new SuperBounce();
|
||||||
|
sb.y = 3;
|
||||||
|
world.addDtsObject(sb);
|
||||||
|
|
||||||
var sh = new ShockAbsorber();
|
var sh = new ShockAbsorber();
|
||||||
sh.y = -3;
|
sh.y = -3;
|
||||||
world.addDtsObject(sh);
|
world.addDtsObject(sh);
|
||||||
|
|
||||||
// var he = new Helicopter();
|
var he = new Helicopter();
|
||||||
// world.addDtsObject(he);
|
world.addDtsObject(he);
|
||||||
// sj.setTransform(sj.getTransform());
|
sj.setTransform(sj.getTransform());
|
||||||
|
|
||||||
// for (i in 0...10) {
|
// for (i in 0...10) {
|
||||||
// for (j in 0...10) {
|
// for (j in 0...10) {
|
||||||
|
|
|
||||||
|
|
@ -484,13 +484,13 @@ class Marble extends GameObject {
|
||||||
this._bounceNormal = normal;
|
this._bounceNormal = normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIntersectionTime(dt:Float, velocity:Vector, pathedInteriors:Array<PathedInterior>, collisionWorld:CollisionWorld) {
|
function getIntersectionTime(dt:Float, velocity:Vector) {
|
||||||
var expandedcollider = new SphereCollisionEntity(cast this);
|
var expandedcollider = new SphereCollisionEntity(cast this);
|
||||||
var position = this.getAbsPos().getPosition();
|
var position = this.getAbsPos().getPosition();
|
||||||
expandedcollider.transform = Matrix.T(position.x, position.y, position.z);
|
expandedcollider.transform = Matrix.T(position.x, position.y, position.z);
|
||||||
expandedcollider.radius = this.getAbsPos().getPosition().distance(position) + _radius;
|
expandedcollider.radius = velocity.multiply(dt).length() + _radius;
|
||||||
|
|
||||||
var foundObjs = collisionWorld.radiusSearch(position, expandedcollider.radius);
|
var foundObjs = this.level.collisionWorld.radiusSearch(position, expandedcollider.radius);
|
||||||
|
|
||||||
function toDifPoint(vec:Vector) {
|
function toDifPoint(vec:Vector) {
|
||||||
return new Point3F(vec.x, vec.y, vec.z);
|
return new Point3F(vec.x, vec.y, vec.z);
|
||||||
|
|
@ -499,47 +499,45 @@ class Marble extends GameObject {
|
||||||
var intersectT = 10e8;
|
var intersectT = 10e8;
|
||||||
|
|
||||||
for (obj in foundObjs) {
|
for (obj in foundObjs) {
|
||||||
if (obj.velocity.length() > 0) {
|
var radius = expandedcollider.radius;
|
||||||
var radius = _radius;
|
|
||||||
|
|
||||||
var invMatrix = obj.transform.clone();
|
var invMatrix = obj.transform.clone();
|
||||||
invMatrix.invert();
|
invMatrix.invert();
|
||||||
var localpos = position.clone();
|
var localpos = position.clone();
|
||||||
localpos.transform(invMatrix);
|
localpos.transform(invMatrix);
|
||||||
var surfaces = obj.octree.radiusSearch(localpos, radius * 1.1);
|
var surfaces = obj.octree.radiusSearch(localpos, radius * 1.1);
|
||||||
|
|
||||||
var tform = obj.transform.clone();
|
var tform = obj.transform.clone();
|
||||||
var velDir = obj.velocity.normalized();
|
var velDir = obj.velocity.normalized();
|
||||||
// tform.setPosition(tform.getPosition().add(velDir.multiply(_radius)));
|
// tform.setPosition(tform.getPosition().add(velDir.multiply(_radius)));
|
||||||
tform.setPosition(tform.getPosition().add(obj.velocity.multiply(dt)).sub(velDir.multiply(_radius)));
|
tform.setPosition(tform.getPosition().add(obj.velocity.multiply(dt)).sub(velDir.multiply(_radius)));
|
||||||
|
|
||||||
var contacts = [];
|
var contacts = [];
|
||||||
|
|
||||||
for (surf in surfaces) {
|
for (surf in surfaces) {
|
||||||
var surface:CollisionSurface = cast surf;
|
var surface:CollisionSurface = cast surf;
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (i < surface.indices.length) {
|
while (i < surface.indices.length) {
|
||||||
var v0 = surface.points[surface.indices[i]].transformed(tform);
|
var v0 = surface.points[surface.indices[i]].transformed(tform);
|
||||||
var v = surface.points[surface.indices[i + 1]].transformed(tform);
|
var v = surface.points[surface.indices[i + 1]].transformed(tform);
|
||||||
var v2 = surface.points[surface.indices[i + 2]].transformed(tform);
|
var v2 = surface.points[surface.indices[i + 2]].transformed(tform);
|
||||||
|
|
||||||
var polyPlane = PlaneF.ThreePoints(toDifPoint(v0), toDifPoint(v), toDifPoint(v2));
|
var polyPlane = PlaneF.ThreePoints(toDifPoint(v0), toDifPoint(v), toDifPoint(v2));
|
||||||
|
|
||||||
var surfacenormal = surface.normals[surface.indices[i]].transformed3x3(obj.transform);
|
var surfacenormal = surface.normals[surface.indices[i]].transformed3x3(obj.transform);
|
||||||
|
|
||||||
var t = (-position.dot(surfacenormal) - polyPlane.d) / velocity.dot(surfacenormal);
|
var t = (-position.dot(surfacenormal) - polyPlane.d) / velocity.dot(surfacenormal);
|
||||||
|
|
||||||
var pt = position.add(velocity.multiply(t));
|
var pt = position.add(velocity.multiply(t));
|
||||||
|
|
||||||
if (Collision.PointInTriangle(pt, v0, v, v2)) {
|
if (Collision.PointInTriangle(pt, v0, v, v2)) {
|
||||||
if (t > 0 && t < intersectT) {
|
if (t > 0 && t < intersectT) {
|
||||||
intersectT = t;
|
intersectT = t;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -596,13 +594,16 @@ class Marble extends GameObject {
|
||||||
this._contactTime += timeStep;
|
this._contactTime += timeStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
var intersectT = this.getIntersectionTime(timeStep, velocity, pathedInteriors, collisionWorld);
|
var intersectT = this.getIntersectionTime(timeStep, velocity);
|
||||||
|
|
||||||
if (intersectT < timeStep) {
|
if (intersectT < timeStep) {
|
||||||
|
intersectT *= 0.8; // We uh tick the shit to not actually at the contact time cause bruh
|
||||||
|
// intersectT /= 2;
|
||||||
var diff = timeStep - intersectT;
|
var diff = timeStep - intersectT;
|
||||||
this.velocity = this.velocity.sub(A.multiply(diff));
|
this.velocity = this.velocity.sub(A.multiply(diff));
|
||||||
this.omega = this.omega.sub(a.multiply(diff));
|
this.omega = this.omega.sub(a.multiply(diff));
|
||||||
timeStep = intersectT;
|
timeStep = intersectT;
|
||||||
|
trace("CCD");
|
||||||
}
|
}
|
||||||
|
|
||||||
piTime += timeStep;
|
piTime += timeStep;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue