mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-26 12:41:40 +00:00
move DTS collision to use CollisionEntity
This commit is contained in:
parent
69199b9da7
commit
964aa9aefb
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) {
|
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) {
|
for (primitive in dtsMesh.primitives) {
|
||||||
var k = 0;
|
var k = 0;
|
||||||
|
|
||||||
var chull = new CollisionHull(cast this);
|
// var chull = new CollisionEntity(cast this); // new CollisionHull(cast this);
|
||||||
chull.userData = node;
|
// chull.userData = node;
|
||||||
var hs = new CollisionSurface();
|
var hs = new CollisionSurface();
|
||||||
hs.points = [];
|
hs.points = [];
|
||||||
hs.normals = [];
|
hs.normals = [];
|
||||||
hs.indices = [];
|
hs.indices = [];
|
||||||
hs.transformKeys = [];
|
hs.transformKeys = [];
|
||||||
|
hs.edgeConcavities = [];
|
||||||
|
hs.edgeData = [];
|
||||||
|
|
||||||
var material = this.dts.matNames[primitive.matIndex & TSDrawPrimitive.MaterialMask];
|
var material = this.dts.matNames[primitive.matIndex & TSDrawPrimitive.MaterialMask];
|
||||||
if (dtsMaterials.exists(material) && !this.isTSStatic) {
|
if (dtsMaterials.exists(material) && !this.isTSStatic) {
|
||||||
|
|
@ -581,11 +585,22 @@ class DtsObject extends GameObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
hs.generateBoundingBox();
|
hs.generateBoundingBox();
|
||||||
chull.addSurface(hs);
|
ent.addSurface(hs);
|
||||||
chull.generateBoundingBox();
|
// chull.generateBoundingBox();
|
||||||
chull.finalize();
|
// chull.finalize();
|
||||||
hulls.push(chull);
|
// 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;
|
return hulls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1029,30 +1029,6 @@ class Marble extends GameObject {
|
||||||
Math.max(Math.max(sphereRadius.x, sphereRadius.y), sphereRadius.z) * 2);
|
Math.max(Math.max(sphereRadius.x, sphereRadius.y), sphereRadius.z) * 2);
|
||||||
|
|
||||||
var currentFinalPos = position.add(relVel.multiply(finalT)); // localpos.add(relLocalVel.multiply(finalT));
|
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);
|
var surfaces = obj.bvh == null ? obj.octree.boundingSearch(boundThing).map(x -> cast x) : obj.bvh.boundingSearch(boundThing);
|
||||||
|
|
||||||
for (surf in surfaces) {
|
for (surf in surfaces) {
|
||||||
|
|
@ -1311,7 +1287,6 @@ class Marble extends GameObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// if (!iterationFound)
|
// if (!iterationFound)
|
||||||
// break;
|
// break;
|
||||||
|
|
|
||||||
|
|
@ -1447,7 +1447,7 @@ class MarbleWorld extends Scheduler {
|
||||||
var found = false;
|
var found = false;
|
||||||
for (collider in endpadBB) {
|
for (collider in endpadBB) {
|
||||||
if (collider.go == this.endPad) {
|
if (collider.go == this.endPad) {
|
||||||
var chull = cast(collider, collision.CollisionHull);
|
var chull = cast(collider, collision.CollisionEntity);
|
||||||
var chullinvT = @:privateAccess chull.invTransform.clone();
|
var chullinvT = @:privateAccess chull.invTransform.clone();
|
||||||
chullinvT.clone();
|
chullinvT.clone();
|
||||||
chullinvT.transpose();
|
chullinvT.transpose();
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
||||||
var oldPos = this.transform.getPosition();
|
var oldPos = this.transform.getPosition();
|
||||||
var newPos = transform.getPosition();
|
var newPos = transform.getPosition();
|
||||||
this.transform.setPosition(newPos);
|
this.transform.setPosition(newPos);
|
||||||
this.invTransform.setPosition(newPos.multiply(-1));
|
this.invTransform = this.transform.getInverse();
|
||||||
if (this.boundingBox == null)
|
if (this.boundingBox == null)
|
||||||
generateBoundingBox();
|
generateBoundingBox();
|
||||||
else {
|
else {
|
||||||
|
|
@ -244,6 +244,7 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
||||||
cinfo.force = surface.force;
|
cinfo.force = surface.force;
|
||||||
cinfo.friction = surface.friction;
|
cinfo.friction = surface.friction;
|
||||||
contacts.push(cinfo);
|
contacts.push(cinfo);
|
||||||
|
this.go.onMarbleContact(timeState, cinfo);
|
||||||
// surfaceBestContact = cinfo;
|
// surfaceBestContact = cinfo;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue