use of ValkyrienWarfareBase.Collision.PhysPolygonCollider 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);
}
}
}
}
use of ValkyrienWarfareBase.Collision.PhysPolygonCollider in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldPhysicsCollider method handleLikelyCollision.
//Tests two block positions directly against each other, and figures out whether a collision is occuring or not
private boolean handleLikelyCollision(BlockPos inWorldPos, BlockPos inLocalPos, IBlockState inWorldState, IBlockState inLocalState) {
// System.out.println("Handling a likely collision");
AxisAlignedBB inLocalBB = new AxisAlignedBB(inLocalPos.getX(), inLocalPos.getY(), inLocalPos.getZ(), inLocalPos.getX() + 1, inLocalPos.getY() + 1, inLocalPos.getZ() + 1);
AxisAlignedBB inGlobalBB = new AxisAlignedBB(inWorldPos.getX(), inWorldPos.getY(), inWorldPos.getZ(), inWorldPos.getX() + 1, inWorldPos.getY() + 1, inWorldPos.getZ() + 1);
//This changes the box bounding box to the real bounding box, not sure if this is better or worse for this mod
// List<AxisAlignedBB> colBB = worldObj.getCollisionBoxes(inLocalBB);
// inLocalBB = colBB.get(0);
Polygon shipInWorld = new Polygon(inLocalBB, parent.coordTransform.lToWTransform);
Polygon worldPoly = new Polygon(inGlobalBB);
PhysPolygonCollider collider = new PhysPolygonCollider(shipInWorld, worldPoly, parent.coordTransform.normals);
if (!collider.seperated) {
return handleActualCollision(collider, inWorldPos, inLocalPos, inWorldState, inLocalState);
}
return false;
}
Aggregations