mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
add ramp matrixing shit
This commit is contained in:
parent
c9355d0eba
commit
9d9849d95b
10 changed files with 68 additions and 26 deletions
BIN
marblegame.hl
BIN
marblegame.hl
Binary file not shown.
|
|
@ -1,5 +1,6 @@
|
|||
package src;
|
||||
|
||||
import h3d.col.Bounds;
|
||||
import src.TimeState;
|
||||
import shaders.Billboard;
|
||||
import collision.BoxCollisionEntity;
|
||||
|
|
@ -322,7 +323,10 @@ class DtsObject extends GameObject {
|
|||
rootObject.scaleX = -1;
|
||||
|
||||
if (this.level != null) {
|
||||
this.boundingCollider = new BoxCollisionEntity(this.level.instanceManager.getObjectBounds(cast this), cast this);
|
||||
var boundthing = new Bounds();
|
||||
boundthing.addPoint(new h3d.col.Point(this.dts.bounds.minX, this.dts.bounds.minY, this.dts.bounds.minZ));
|
||||
boundthing.addPoint(new h3d.col.Point(this.dts.bounds.maxX, this.dts.bounds.maxY, this.dts.bounds.maxZ));
|
||||
this.boundingCollider = new BoxCollisionEntity(boundthing, cast this);
|
||||
this.boundingCollider.setTransform(this.getTransform());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -178,6 +178,8 @@ class Marble extends GameObject {
|
|||
|
||||
public var startPad:StartPad;
|
||||
|
||||
public var prevPos:Vector;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
var geom = Sphere.defaultUnitSphere();
|
||||
|
|
@ -892,6 +894,7 @@ class Marble extends GameObject {
|
|||
}
|
||||
|
||||
var pos = this.getAbsPos().getPosition();
|
||||
this.prevPos = pos.clone();
|
||||
|
||||
if (mode == Start) {
|
||||
var upVec = this.level.currentUp;
|
||||
|
|
@ -934,7 +937,7 @@ class Marble extends GameObject {
|
|||
this.heldPowerup = null;
|
||||
}
|
||||
|
||||
if (this.controllable) {
|
||||
if (this.controllable && this.prevPos != null) {
|
||||
var tempTimeState = timeState.clone();
|
||||
tempState.currentAttemptTime = piTime;
|
||||
tempState.dt = timeStep;
|
||||
|
|
|
|||
|
|
@ -870,6 +870,14 @@ class MarbleWorld extends Scheduler {
|
|||
}
|
||||
|
||||
public function callCollisionHandlers(marble:Marble, timeState:TimeState) {
|
||||
var gjkCapsule = new collision.gjk.Capsule();
|
||||
gjkCapsule.p1 = marble.getAbsPos().getPosition();
|
||||
gjkCapsule.p2 = marble.prevPos;
|
||||
gjkCapsule.radius = marble._radius;
|
||||
|
||||
var spherebounds = new Bounds();
|
||||
spherebounds.addSpherePos(gjkCapsule.p1.x, gjkCapsule.p1.y, gjkCapsule.p1.z, gjkCapsule.radius);
|
||||
// spherebounds.addSpherePos(gjkCapsule.p2.x, gjkCapsule.p2.y, gjkCapsule.p2.z, gjkCapsule.radius);
|
||||
// var contacts = this.collisionWorld.radiusSearch(marble.getAbsPos().getPosition(), marble._radius);
|
||||
var contacts = marble.contactEntities;
|
||||
var newImmunity = [];
|
||||
|
|
@ -879,15 +887,6 @@ class MarbleWorld extends Scheduler {
|
|||
var contactsphere = new SphereCollisionEntity(marble);
|
||||
contactsphere.velocity = new Vector();
|
||||
|
||||
var spherebounds = new Bounds();
|
||||
var center = marble.collider.transform.getPosition();
|
||||
var radius = marble._radius;
|
||||
spherebounds.addSpherePos(center.x, center.y, center.z, radius);
|
||||
|
||||
var gjkSphere = new collision.gjk.Sphere();
|
||||
gjkSphere.position = center;
|
||||
gjkSphere.radius = radius;
|
||||
|
||||
for (contact in contacts) {
|
||||
if (contact.go != marble) {
|
||||
if (contact.go is DtsObject) {
|
||||
|
|
@ -937,7 +936,7 @@ class MarbleWorld extends Scheduler {
|
|||
|
||||
if (this.finishTime == null) {
|
||||
if (spherebounds.collide(this.endPad.finishBounds)) {
|
||||
if (collision.gjk.GJK.gjk(gjkSphere, this.endPad.finishCollider) != null) {
|
||||
if (collision.gjk.GJK.gjk(gjkCapsule, this.endPad.finishCollider) != null) {
|
||||
if (!endPad.inFinish) {
|
||||
touchFinish();
|
||||
endPad.inFinish = true;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,10 @@ class CollisionWorld {
|
|||
// var intersections = this.octree.radiusSearch(position, searchdist);
|
||||
|
||||
var box = new Bounds();
|
||||
box.addSpherePos(position.x, position.y, position.z, radius);
|
||||
box.addSpherePos(0, 0, 0, radius);
|
||||
var rotQuat = spherecollision.marble.getRotationQuat();
|
||||
box.transform(rotQuat.toMatrix());
|
||||
box.offset(position.x, position.y, position.z);
|
||||
box.addSpherePos(position.x + velocity.x * timeState.dt, position.y + velocity.y * timeState.dt, position.z + velocity.z * timeState.dt, radius);
|
||||
var intersections = this.octree.boundingSearch(box);
|
||||
|
||||
|
|
|
|||
23
src/collision/gjk/Capsule.hx
Normal file
23
src/collision/gjk/Capsule.hx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package collision.gjk;
|
||||
|
||||
import h3d.Vector;
|
||||
|
||||
@:publicFields
|
||||
class Capsule implements GJKShape {
|
||||
var p1:Vector;
|
||||
var p2:Vector;
|
||||
var radius:Float;
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function getCenter():Vector {
|
||||
return p1.add(p2).multiply(0.5);
|
||||
}
|
||||
|
||||
public function support(dir:Vector) {
|
||||
var axis = p2.sub(p1);
|
||||
var dy = dir.dot(axis);
|
||||
|
||||
return ((dy < 0) ? p1 : p2).add(dir.multiply(radius));
|
||||
}
|
||||
}
|
||||
|
|
@ -3,16 +3,14 @@ package collision.gjk;
|
|||
import h3d.Vector;
|
||||
import h3d.Matrix;
|
||||
|
||||
class ConvexHull {
|
||||
class ConvexHull implements GJKShape {
|
||||
public var vertices:Array<Vector>;
|
||||
|
||||
public var transform:Matrix;
|
||||
|
||||
public var centre(get, never):Vector;
|
||||
|
||||
var _centercache:Vector;
|
||||
|
||||
function get_centre():Vector {
|
||||
public function getCenter():Vector {
|
||||
if (_centercache != null)
|
||||
return _centercache;
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -10,16 +10,16 @@ class GJK {
|
|||
public static var maxEpaLooseEdges = 64;
|
||||
public static var maxEpaIterations = 64;
|
||||
|
||||
public static function gjk(sphere:Sphere, hull:ConvexHull) {
|
||||
var searchDir = sphere.position.sub(hull.centre);
|
||||
public static function gjk(s1:GJKShape, s2:GJKShape) {
|
||||
var searchDir = s1.getCenter().sub(s2.getCenter());
|
||||
var a = new Vector();
|
||||
var b = new Vector();
|
||||
var c = new Vector();
|
||||
var d = new Vector();
|
||||
|
||||
c = hull.support(searchDir).sub(sphere.support(searchDir.multiply(-1)));
|
||||
c = s2.support(searchDir).sub(s1.support(searchDir.multiply(-1)));
|
||||
searchDir = c.multiply(-1);
|
||||
b = hull.support(searchDir).sub(sphere.support(searchDir.multiply(-1)));
|
||||
b = s2.support(searchDir).sub(s1.support(searchDir.multiply(-1)));
|
||||
if (b.dot(searchDir) < 0)
|
||||
return null;
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ class GJK {
|
|||
var simpDim = 2;
|
||||
|
||||
for (i in 0...maxIterations) {
|
||||
a = hull.support(searchDir).sub(sphere.support(searchDir.multiply(-1)));
|
||||
a = s2.support(searchDir).sub(s1.support(searchDir.multiply(-1)));
|
||||
if (a.dot(searchDir) < 0) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -83,14 +83,14 @@ class GJK {
|
|||
b = a;
|
||||
searchDir = adb;
|
||||
} else {
|
||||
return epa(a, b, c, d, sphere, hull);
|
||||
return epa(a, b, c, d, s1, s2);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function epa(a:Vector, b:Vector, c:Vector, d:Vector, sphere:Sphere, hull:ConvexHull) {
|
||||
public static function epa(a:Vector, b:Vector, c:Vector, d:Vector, s1:GJKShape, s2:GJKShape) {
|
||||
var faces = [];
|
||||
for (i in 0...maxEpaFaces)
|
||||
faces.push([new Vector(), new Vector(), new Vector(), new Vector()]);
|
||||
|
|
@ -129,7 +129,7 @@ class GJK {
|
|||
|
||||
// search normal to face that's closest to origin
|
||||
var search_dir = faces[closestFace][3];
|
||||
var p = hull.support(search_dir).sub(sphere.support(search_dir.multiply(-1)));
|
||||
var p = s2.support(search_dir).sub(s1.support(search_dir.multiply(-1)));
|
||||
if (p.dot(search_dir) - min_dist < epaTolerance) {
|
||||
// Convergence (new point is not significantly further from origin)
|
||||
return faces[closestFace][3].multiply(p.dot(search_dir)); // dot vertex with normal to resolve collision along normal!
|
||||
|
|
|
|||
8
src/collision/gjk/GJKShape.hx
Normal file
8
src/collision/gjk/GJKShape.hx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package collision.gjk;
|
||||
|
||||
import h3d.Vector;
|
||||
|
||||
interface GJKShape {
|
||||
function getCenter():Vector;
|
||||
function support(dir:Vector):Vector;
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ package collision.gjk;
|
|||
import h3d.Vector;
|
||||
|
||||
@:publicFields
|
||||
class Sphere {
|
||||
class Sphere implements GJKShape {
|
||||
var position:Vector;
|
||||
var radius:Float;
|
||||
|
||||
|
|
@ -16,4 +16,8 @@ class Sphere {
|
|||
c = c.add(d);
|
||||
return c;
|
||||
}
|
||||
|
||||
public function getCenter() {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue