Commits

Lars Viklund committed 5459589

Add rudimentary homebrew coldet/physics

Comments (0)

Files changed (1)

     Quaternion Orientation;
     Vec3 SpinAxis;
     float AngularVelocity;
+    AABB LocalBounds, GlobalBounds;
   };
 
   std::vector<Drop> Drops;
 
+  std::vector<AABB> Solids;
+  Solids.push_back({{0.0f, -4.0f, 0.0f}, {10.0f, 1.0f, 0.0f}});
+
   int64_t CurrentFrame = 0;
   int64_t const DropCooldown = (int64_t)(0.5f*(1000.0f/SIM_FRAME_TIME));
   int64_t const DropSlop = (int64_t)(0.1f*(1000.0f/SIM_FRAME_TIME));
         Drop.Position += Drop.Velocity * Dt.asSeconds();
         auto DeltaO = quaternionFromAxisAngle(Drop.AngularVelocity * Dt.asSeconds(), Drop.SpinAxis);
         Drop.Orientation = DeltaO * Drop.Orientation;
+        Drop.GlobalBounds = Drop.LocalBounds;
+        Drop.GlobalBounds.C = Drop.GlobalBounds.C + Vec3{Drop.Position.x, Drop.Position.y, 0.0f};
+      }
+      std::deque<size_t> DestroyDropList;
+      for (auto n = Drops.size(), i = 0u; i < n; ++i) {
+        auto& Drop = Drops[i];
+        for (auto& Solid : Solids) {
+          if (TestAABBAABB(Drop.GlobalBounds, Solid) == IntersectTestResult::Positive) {
+            DestroyDropList.push_front(i);
+          }
+        }
+      }
+      for (auto Index : DestroyDropList) {
+        Drops.erase(Drops.begin() + Index);
       }
       auto& Gifts = State.Level.GiftReps;
       while (!Gifts.empty() && Gifts.front().Position.x < -0.1f*DESIGN_WIDTH) {
         State.Level = assembleLevel(Blueprint);
       }
 
-      if (DropIntent.Active && LastDropFrame + DropCooldown <= CurrentFrame) {
-        DropIntent.Acknowledge();
+      auto DropBox = [&](sf::Vector2f Pos) {
         Drop D = {};
-        D.Position = SledPosition;
+        D.Position = Pos;
         D.Velocity = { 5.0f, 0.0f };
         D.Orientation = quaternionIdentity();
         D.SpinAxis = randomAxis(AxisRNG);
         D.AngularVelocity = 3.0f;
+        D.LocalBounds = { { 0.0f, 0.0f, 0.0f }, { 0.5f, 0.5f, 0.5f } };
         Drops.push_back(std::move(D));
+      };
+
+      if (DropIntent.Active && LastDropFrame + DropCooldown <= CurrentFrame) {
+        DropIntent.Acknowledge();
+        DropBox(SledPosition);
         LastDropFrame = CurrentFrame;
       }
 
+#define DEBUG_DROP_SPAM 1
+#if DEBUG_DROP_SPAM
+      if ((CurrentFrame % 1) == 0) {
+        static std::uniform_real<float> XDist(-DESIGN_WIDTH/2.0f, DESIGN_WIDTH/2.0f);
+        static std::uniform_real<float> YDist(-DESIGN_HEIGHT/2.0f, DESIGN_HEIGHT/2.0f);
+        auto X = XDist(AxisRNG), Y = YDist(AxisRNG);
+        DropBox(sf::Vector2f(X, Y));
+      }
+#endif
+
       SimTime += Dt;
       ++CurrentFrame;
     }