Added .gitignore, and implemented stable stacking

This commit is contained in:
max
2026-09-03 17:50:53 +02:00
parent d8758f98dc
commit 6abf8320b0
36 changed files with 249 additions and 1047 deletions

View File

@@ -89,95 +89,146 @@ namespace PhysicsEngine
float worldHeight = 7.2f;
float wallThickness = 1.0f;
// 1. Static world borders
// 1. Static World Borders
Box floor = new Box(new Vector2(worldWidth * 0.5f, worldHeight + (wallThickness * 0.5f)), new Vector2(worldWidth + wallThickness * 2, wallThickness), 0f);
floor.BaseColor = Color.DarkGray;
floor.BaseColor = new Color(60, 60, 60);
floor.Friction = 0.9f;
world.AddBody(floor);
Box ceiling = new Box(new Vector2(worldWidth * 0.5f, -wallThickness * 0.5f), new Vector2(worldWidth + wallThickness * 2, wallThickness), 0f);
ceiling.BaseColor = Color.DarkGray;
ceiling.BaseColor = new Color(60, 60, 60);
world.AddBody(ceiling);
Box leftWall = new Box(new Vector2(-wallThickness * 0.5f, worldHeight * 0.5f), new Vector2(wallThickness, worldHeight + wallThickness * 2), 0f);
leftWall.BaseColor = Color.DarkGray;
leftWall.BaseColor = new Color(60, 60, 60);
world.AddBody(leftWall);
Box rightWall = new Box(new Vector2(worldWidth + wallThickness * 0.5f, worldHeight * 0.5f), new Vector2(wallThickness, worldHeight + wallThickness * 2), 0f);
rightWall.BaseColor = Color.DarkGray;
rightWall.BaseColor = new Color(60, 60, 60);
world.AddBody(rightWall);
// 2. Static Ramps and Platforms
Box platform = new Box(new Vector2(9.0f, 4.5f), new Vector2(3.5f, 0.3f), 0f);
platform.BaseColor = Color.Gray;
platform.Friction = 0.8f;
world.AddBody(platform);
Box ramp = new Box(new Vector2(2.0f, 3.5f), new Vector2(3.5f, 0.3f), 0f);
ramp.Rotation = 0.35f; // Slopes down toward center stack
ramp.BaseColor = Color.Gray;
ramp.Friction = 0.6f;
world.AddBody(ramp);
// =========================================================================
// TEST 1: Ultra-Tall Thin Skyscraper (X = 2.0)
// 18-box high column testing vertical constraint propagation and slop
// =========================================================================
float singleStackX = 2.0f;
float colBoxWidth = 0.5f;
float colBoxHeight = 0.35f;
int towerHeight = 18;
// 3. Main Ground Box Tower (5 boxes high)
float stackX = 5.0f;
float boxHeight = 0.6f;
float boxWidth = 0.6f;
float startY = worldHeight - (boxHeight * 0.5f); // Sits cleanly on the floor surface (Y = 7.2)
Color[] stackColors = new Color[]
{
Color.DarkGreen, Color.Green, Color.Lime, Color.DarkPurple, Color.Yellow
};
for (int i = 0; i < 5; i++)
for (int i = 0; i < towerHeight; i++)
{
float y = startY - (i * boxHeight);
Box stackBox = new Box(new Vector2(stackX, y), new Vector2(boxWidth, boxHeight), 20f);
stackBox.BaseColor = stackColors[i % stackColors.Length];
stackBox.Friction = 0.8f;
stackBox.Restitution = 0.0f;
world.AddBody(stackBox);
float y = worldHeight - (colBoxHeight * 0.5f) - (i * colBoxHeight);
Box box = new Box(new Vector2(singleStackX, y), new Vector2(colBoxWidth, colBoxHeight), 10f);
// Color gradient using integer calculations
int r = Math.Clamp(30 + i * 11, 0, 255);
int g = Math.Clamp(140 - i * 6, 0, 255);
int b = Math.Clamp(255 - i * 5, 0, 255);
box.BaseColor = new Color(r, g, b);
box.Friction = 0.85f;
box.Restitution = 0.0f;
world.AddBody(box);
}
// 4. Secondary Platform Stack (3 boxes high)
float platformStackX = 9.0f;
float platformTopY = 4.5f - 0.15f; // Top surface of platform
float platformStartY = platformTopY - (boxHeight * 0.5f);
for (int i = 0; i < 3; i++)
// =========================================================================
// TEST 2: 10-Tier Staggered Pyramid (Centered at X = 6.2)
// 55 boxes in multi-contact arrangement testing shear and load distribution
// =========================================================================
int pyramidTiers = 10;
float pBoxWidth = 0.45f;
float pBoxHeight = 0.30f;
float pyramidCenterX = 6.2f;
for (int row = 0; row < pyramidTiers; row++)
{
float y = platformStartY - (i * boxHeight);
Box pBox = new Box(new Vector2(platformStackX, y), new Vector2(0.5f, boxHeight), 12f);
pBox.BaseColor = Color.Blue;
pBox.Friction = 0.8f;
pBox.Restitution = 0.0f;
world.AddBody(pBox);
int boxesInRow = pyramidTiers - row;
float rowY = worldHeight - (pBoxHeight * 0.5f) - (row * pBoxHeight);
float startX = pyramidCenterX - ((boxesInRow - 1) * pBoxWidth * 0.5f);
for (int col = 0; col < boxesInRow; col++)
{
float x = startX + (col * pBoxWidth);
Box pBox = new Box(new Vector2(x, rowY), new Vector2(pBoxWidth - 0.01f, pBoxHeight - 0.01f), 15f);
// Heatmap color gradient (Integer args)
int r = Math.Min(255, 180 + row * 8);
int g = Math.Min(255, row * 26);
int b = 30;
pBox.BaseColor = new Color(r, g, b);
pBox.Friction = 0.9f;
pBox.Restitution = 0.0f;
world.AddBody(pBox);
}
}
// 5. Dynamic Circles for Stack Interaction
// Circle balanced on top of the main ground stack
float mainStackTopY = startY - (4 * boxHeight) - (boxHeight * 0.5f);
Circle stackCap = new Circle(new Vector2(stackX, mainStackTopY - 0.3f), 0.3f, 8f);
stackCap.BaseColor = Color.Orange;
stackCap.Friction = 0.8f;
stackCap.Restitution = 0.0f;
world.AddBody(stackCap);
// Heavy ball spawned on the ramp to roll down and strike the main stack
Circle rollingBall = new Circle(new Vector2(1.0f, 1.5f), 0.45f, 350f);
rollingBall.BaseColor = Color.Red;
rollingBall.Friction = 0.5f;
rollingBall.Restitution = 0.1f;
world.AddBody(rollingBall);
// =========================================================================
// TEST 3: Interlocked Double Tower Structure (X = 10.0 and X = 11.0)
// Parallel columns tied together by heavy cross-planks every 4 tiers
// =========================================================================
float towerAX = 10.0f;
float towerBX = 11.0f;
float tBoxWidth = 0.45f;
float tBoxHeight = 0.32f;
int towerRows = 16;
// Bouncy ball dropped over the platform stack to test stability under impact
Circle droppingBall = new Circle(new Vector2(9.0f, 0.8f), 0.35f, 10f);
droppingBall.BaseColor = Color.Gold;
droppingBall.Friction = 0.4f;
droppingBall.Restitution = 0.4f;
droppingBall.Velocity = new Vector2(0.0f, 2.0f);
world.AddBody(droppingBall);
for (int row = 0; row < towerRows; row++)
{
float y = worldHeight - (tBoxHeight * 0.5f) - (row * tBoxHeight);
int r = 50;
int g = Math.Min(255, 100 + row * 8);
int b = Math.Min(255, 180 + row * 4);
// Column A Box
Box boxA = new Box(new Vector2(towerAX, y), new Vector2(tBoxWidth, tBoxHeight), 12f);
boxA.BaseColor = new Color(r, g, b);
boxA.Friction = 0.8f;
boxA.Restitution = 0.0f;
world.AddBody(boxA);
// Column B Box
Box boxB = new Box(new Vector2(towerBX, y), new Vector2(tBoxWidth, tBoxHeight), 12f);
boxB.BaseColor = new Color(r, g, b);
boxB.Friction = 0.8f;
boxB.Restitution = 0.0f;
world.AddBody(boxB);
// Cross-plank binder every 4th level
if (row % 4 == 3)
{
float plankY = y - (tBoxHeight * 0.5f) - 0.08f;
Box plank = new Box(new Vector2((towerAX + towerBX) * 0.5f, plankY), new Vector2(1.6f, 0.16f), 30f);
plank.BaseColor = new Color(220, 160, 40);
plank.Friction = 0.95f;
plank.Restitution = 0.0f;
world.AddBody(plank);
}
}
// =========================================================================
// TEST 4: High-Mass Top Stressers
// =========================================================================
// Heavy weight on top of thin skyscraper
float capY = worldHeight - (towerHeight * colBoxHeight) - 0.4f;
Box heavyCap = new Box(new Vector2(singleStackX, capY), new Vector2(0.8f, 0.8f), 150f);
heavyCap.BaseColor = new Color(240, 40, 40);
heavyCap.Friction = 0.9f;
world.AddBody(heavyCap);
// Heavy sphere dropping onto the peak of the pyramid
Circle impactBall = new Circle(new Vector2(pyramidCenterX, 0.5f), 0.45f, 250f);
impactBall.BaseColor = new Color(255, 80, 0);
impactBall.Friction = 0.7f;
impactBall.Restitution = 0.05f;
world.AddBody(impactBall);
}
}
}