use of ValkyrienWarfareBase.Physics.PhysicsCalculationsOrbital in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipPhysicsCollider method doShipCollision.
public void doShipCollision(PhysicsObject toCollideWith) {
//Don't process collision if either of them are phased
if (toCollideWith.physicsProcessor instanceof PhysicsCalculationsOrbital) {
if (((PhysicsCalculationsOrbital) toCollideWith.physicsProcessor).isOrbitalPhased) {
return;
}
}
if (parent.physicsProcessor instanceof PhysicsCalculationsOrbital) {
if (((PhysicsCalculationsOrbital) parent.physicsProcessor).isOrbitalPhased) {
return;
}
}
AxisAlignedBB firstBB = parent.collisionBB;
AxisAlignedBB secondBB = toCollideWith.collisionBB;
AxisAlignedBB betweenBB = BigBastardMath.getBetweenAABB(firstBB, secondBB);
Polygon betweenBBPoly = new Polygon(betweenBB, toCollideWith.coordTransform.wToLTransform);
List<AxisAlignedBB> bbsInFirst = parent.worldObj.getCollisionBoxes(betweenBBPoly.getEnclosedAABB());
if (bbsInFirst.isEmpty()) {
return;
}
Vector[] axes = parent.coordTransform.getSeperatingAxisWithShip(toCollideWith);
// RandomIterator.getRandomIteratorForList(bbsInFirst);
Iterator<AxisAlignedBB> firstRandIter = bbsInFirst.iterator();
while (firstRandIter.hasNext()) {
AxisAlignedBB fromIter = firstRandIter.next();
Polygon firstInWorld = new Polygon(fromIter, toCollideWith.coordTransform.lToWTransform);
AxisAlignedBB inWorldAABB = firstInWorld.getEnclosedAABB();
Polygon inShip2Poly = new Polygon(inWorldAABB, parent.coordTransform.wToLTransform);
// This is correct
List<AxisAlignedBB> bbsInSecond = parent.worldObj.getCollisionBoxes(inShip2Poly.getEnclosedAABB());
// RandomIterator.getRandomIteratorForList(bbsInSecond);
Iterator<AxisAlignedBB> secondRandIter = bbsInSecond.iterator();
while (secondRandIter.hasNext()) {
// System.out.println("test");
Polygon secondInWorld = new Polygon(secondRandIter.next(), parent.coordTransform.lToWTransform);
// Both of these are in WORLD coordinates
Vector firstCenter = firstInWorld.getCenter();
Vector secondCenter = secondInWorld.getCenter();
Vector inBodyFirst = new Vector(firstCenter.X - parent.wrapper.posX, firstCenter.Y - parent.wrapper.posY, firstCenter.Z - parent.wrapper.posZ);
Vector inBodySecond = new Vector(secondCenter.X - toCollideWith.wrapper.posX, secondCenter.Y - toCollideWith.wrapper.posY, secondCenter.Z - toCollideWith.wrapper.posZ);
Vector velAtFirst = parent.physicsProcessor.getVelocityAtPoint(inBodyFirst);
Vector velAtSecond = toCollideWith.physicsProcessor.getVelocityAtPoint(inBodySecond);
velAtFirst.subtract(velAtSecond);
PhysPolygonCollider polyCol = new PhysPolygonCollider(firstInWorld, secondInWorld, axes);
if (!polyCol.seperated) {
Vector speedAtPoint = velAtFirst;
double xDot = Math.abs(speedAtPoint.X);
double yDot = Math.abs(speedAtPoint.Y);
double zDot = Math.abs(speedAtPoint.Z);
PhysCollisionObject polyColObj = null;
if (yDot > xDot && yDot > zDot) {
// Y speed is greatest
if (xDot > zDot) {
polyColObj = polyCol.collisions[2];
} else {
polyColObj = polyCol.collisions[0];
}
} else {
if (xDot > zDot) {
// X speed is greatest
polyColObj = polyCol.collisions[1];
} else {
// Z speed is greatest
polyColObj = polyCol.collisions[1];
}
}
// PhysCollisionObject polyColObj = polyCol.collisions[1];
if (polyColObj.penetrationDistance > axisTolerance || polyColObj.penetrationDistance < -axisTolerance) {
polyColObj = polyCol.collisions[polyCol.minDistanceIndex];
}
// PhysCollisionObject physCol = new PhysCollisionObject(firstInWorld,secondInWorld,polyColObj.axis);
processCollisionAtPoint(toCollideWith, polyColObj);
if (Math.abs(polyColObj.movMaxFixMin) > Math.abs(polyColObj.movMinFixMax)) {
for (Vector v : polyColObj.movable.vertices) {
if (v.dot(polyColObj.axis) == polyColObj.playerMinMax[1]) {
polyColObj.firstContactPoint = v;
}
}
} else {
for (Vector v : polyColObj.movable.vertices) {
if (v.dot(polyColObj.axis) == polyColObj.playerMinMax[0]) {
polyColObj.firstContactPoint = v;
}
}
}
// physCol.firstContactPoint = physCol.getSecondContactPoint();
processCollisionAtPoint(toCollideWith, polyColObj);
}
}
}
}
Aggregations