Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

GMT: re-apply (and improve) d388341

  • Loading branch information...
commit df9c6e306ba432b748d85cf63facbe0c4b6719cb 1 parent 9c4fd2a
authored

Showing 1 changed file with 23 additions and 4 deletions. Show diff stats Hide diff stats

  1. 27  rts/Sim/MoveTypes/GroundMoveType.cpp
27  rts/Sim/MoveTypes/GroundMoveType.cpp
@@ -1520,8 +1520,12 @@ void CGroundMoveType::HandleUnitCollisions(
1520 1520
 
1521 1521
 		eventHandler.UnitUnitCollision(collider, collidee);
1522 1522
 
  1523
+		const float colliderRelRadius = colliderRadius / (colliderRadius + collideeRadius);
  1524
+		const float collideeRelRadius = collideeRadius / (colliderRadius + collideeRadius);
  1525
+		const float collisionRadiusSum = (colliderRadius * colliderRelRadius + collideeRadius * collideeRelRadius);
  1526
+
1523 1527
 		const float  sepDistance    = separationVector.Length() + 0.01f;
1524  
-		const float  penDistance    = std::max((colliderRadius + collideeRadius) - sepDistance, 1.0f);
  1528
+		const float  penDistance    = std::max(collisionRadiusSum - sepDistance, 1.0f);
1525 1529
 		const float  sepResponse    = std::min(SQUARE_SIZE * 2.0f, penDistance * 0.5f);
1526 1530
 
1527 1531
 		const float3 sepDirection   = (separationVector / sepDistance);
@@ -1535,12 +1539,27 @@ void CGroundMoveType::HandleUnitCollisions(
1535 1539
 			c1 = 1.0f + (1.0f - math::fabs(collider->frontdir.dot(-sepDirection))) * 5.0f,
1536 1540
 			c2 = 1.0f + (1.0f - math::fabs(collidee->frontdir.dot( sepDirection))) * 5.0f,
1537 1541
 			s1 = m1 * v1 * c1,
1538  
-			s2 = m2 * v2 * c2;
  1542
+			s2 = m2 * v2 * c2,
  1543
+ 			r1 = s1 / (s1 + s2 + 1.0f),
  1544
+ 			r2 = s2 / (s1 + s2 + 1.0f);
1539 1545
 
1540 1546
 		// far from a realistic treatment, but works
1541 1547
 		const float collisionMassSum  = s1 + s2 + 1.0f;
1542  
-		      float colliderMassScale = std::max(0.01f, std::min(0.99f, 1.0f - (s1 / collisionMassSum)));
1543  
-		      float collideeMassScale = std::max(0.01f, std::min(0.99f, 1.0f - (s2 / collisionMassSum)));
  1548
+		      float colliderMassScale = std::max(0.01f, std::min(0.99f, 1.0f - r1));
  1549
+		      float collideeMassScale = std::max(0.01f, std::min(0.99f, 1.0f - r2));
  1550
+
  1551
+		if (collider->isMoving && collidee->isMoving) {
  1552
+			#define SIGN(v) ((int(v >= 0.0f) * 2) - 1)
  1553
+			// push collider and collidee laterally in opposite directions
  1554
+			const int colliderSign = SIGN( separationVector.dot(collider->rightdir));
  1555
+			const int collideeSign = SIGN(-separationVector.dot(collidee->rightdir));
  1556
+			const float3 colliderSlideVec = collider->rightdir * colliderSign * (1.0f / penDistance);
  1557
+			const float3 collideeSlideVec = collidee->rightdir * collideeSign * (1.0f / penDistance);
  1558
+ 
  1559
+			if (pushCollider) { collider->Move3D(colliderSlideVec * r2, true); }
  1560
+			if (pushCollidee) { collidee->Move3D(collideeSlideVec * r1, true); }
  1561
+			#undef SIGN
  1562
+		}
1544 1563
 
1545 1564
 		if (!collideeMobile) {
1546 1565
 			const float3 colliderNxtPos = colliderCurPos + collider->speed;

0 notes on commit df9c6e3

Please sign in to comment.
Something went wrong with that request. Please try again.