mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
move DTS collision to use CollisionEntity
This commit is contained in:
parent
4759c5a243
commit
191e77762f
4 changed files with 237 additions and 246 deletions
|
|
@ -532,17 +532,21 @@ class DtsObject extends GameObject {
|
|||
}
|
||||
|
||||
function generateCollisionGeometry(dtsMesh:dts.Mesh, vertices:Array<Vector>, vertexNormals:Array<Vector>, node:Int) {
|
||||
var hulls:Array<CollisionEntity> = [];
|
||||
var hulls:Array<CollisionEntity> = [new CollisionEntity(cast this)];
|
||||
var ent = hulls[0];
|
||||
ent.userData = node;
|
||||
for (primitive in dtsMesh.primitives) {
|
||||
var k = 0;
|
||||
|
||||
var chull = new CollisionHull(cast this);
|
||||
chull.userData = node;
|
||||
// var chull = new CollisionEntity(cast this); // new CollisionHull(cast this);
|
||||
// chull.userData = node;
|
||||
var hs = new CollisionSurface();
|
||||
hs.points = [];
|
||||
hs.normals = [];
|
||||
hs.indices = [];
|
||||
hs.transformKeys = [];
|
||||
hs.edgeConcavities = [];
|
||||
hs.edgeData = [];
|
||||
|
||||
var material = this.dts.matNames[primitive.matIndex & TSDrawPrimitive.MaterialMask];
|
||||
if (dtsMaterials.exists(material) && !this.isTSStatic) {
|
||||
|
|
@ -581,11 +585,22 @@ class DtsObject extends GameObject {
|
|||
}
|
||||
|
||||
hs.generateBoundingBox();
|
||||
chull.addSurface(hs);
|
||||
chull.generateBoundingBox();
|
||||
chull.finalize();
|
||||
hulls.push(chull);
|
||||
ent.addSurface(hs);
|
||||
// chull.generateBoundingBox();
|
||||
// chull.finalize();
|
||||
// hulls.push(chull);
|
||||
}
|
||||
for (colliderSurface in ent.surfaces) {
|
||||
var i = 0;
|
||||
while (i < colliderSurface.indices.length) {
|
||||
var edgeData = 0;
|
||||
colliderSurface.edgeConcavities.push(false);
|
||||
colliderSurface.edgeData.push(edgeData);
|
||||
i += 3;
|
||||
}
|
||||
}
|
||||
ent.generateBoundingBox();
|
||||
ent.finalize();
|
||||
return hulls;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1029,30 +1029,6 @@ class Marble extends GameObject {
|
|||
Math.max(Math.max(sphereRadius.x, sphereRadius.y), sphereRadius.z) * 2);
|
||||
|
||||
var currentFinalPos = position.add(relVel.multiply(finalT)); // localpos.add(relLocalVel.multiply(finalT));
|
||||
|
||||
if (obj.go is DtsObject) {
|
||||
var chull = cast(obj, CollisionHull);
|
||||
var rayisecs = chull.rayCast(position, velocity);
|
||||
if (rayisecs.length != 0) {
|
||||
var raymax = rayisecs[0];
|
||||
var mindist = raymax.point.distanceSq(position);
|
||||
if (rayisecs.length > 1) {
|
||||
for (i in 0...rayisecs.length) {
|
||||
var dd = rayisecs[i].point.distanceSq(position);
|
||||
if (dd < mindist) {
|
||||
mindist = dd;
|
||||
raymax = rayisecs[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
var collidePoint = raymax.point;
|
||||
var collideT = (collidePoint.sub(velocity.normalized().multiply(radius)).sub(position).length()) / velocity.length();
|
||||
if (collideT < finalT && collideT > 0.0001) {
|
||||
finalT = collideT;
|
||||
currentFinalPos = position.add(relVel.multiply(finalT));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var surfaces = obj.bvh == null ? obj.octree.boundingSearch(boundThing).map(x -> cast x) : obj.bvh.boundingSearch(boundThing);
|
||||
|
||||
for (surf in surfaces) {
|
||||
|
|
@ -1311,7 +1287,6 @@ class Marble extends GameObject {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (!iterationFound)
|
||||
// break;
|
||||
|
|
|
|||
|
|
@ -1448,7 +1448,7 @@ class MarbleWorld extends Scheduler {
|
|||
var found = false;
|
||||
for (collider in endpadBB) {
|
||||
if (collider.go == this.endPad) {
|
||||
var chull = cast(collider, collision.CollisionHull);
|
||||
var chull = cast(collider, collision.CollisionEntity);
|
||||
var chullinvT = @:privateAccess chull.invTransform.clone();
|
||||
chullinvT.clone();
|
||||
chullinvT.transpose();
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
|||
var oldPos = this.transform.getPosition();
|
||||
var newPos = transform.getPosition();
|
||||
this.transform.setPosition(newPos);
|
||||
this.invTransform.setPosition(newPos.multiply(-1));
|
||||
this.invTransform = this.transform.getInverse();
|
||||
if (this.boundingBox == null)
|
||||
generateBoundingBox();
|
||||
else {
|
||||
|
|
@ -244,6 +244,7 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
|||
cinfo.force = surface.force;
|
||||
cinfo.friction = surface.friction;
|
||||
contacts.push(cinfo);
|
||||
this.go.onMarbleContact(timeState, cinfo);
|
||||
// surfaceBestContact = cinfo;
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue