Browse Source

fixed a wierd bug

vlod 1 year ago
parent
commit
a28996d218

+ 36 - 24
Pika/gameplay/containers/angryBirds/angryBirds.h

@@ -116,26 +116,26 @@ struct AngryBirds: public Container
 		physicsEngine.simulationphysicsSettings.gravity = glm::vec2(0, 9.81) * 100.f;
 		physicsEngine.simulationphysicsSettings.gravity = glm::vec2(0, 9.81) * 100.f;
 
 
 
 
-		//for (int i = 0; i < 10; i++)
-		//{
-		//	if (1)
-		//	{
-		//		float w = rand() % 100 + 20;
-		//		float h = rand() % 100 + 20;
-		//
-		//		auto body = physicsEngine.addBody({rand() % 800 + 100, rand() % 800 + 100},
-		//			ph2d::createBoxCollider({w, h}));
-		//		physicsEngine.bodies[body].motionState.rotation = ((rand() % 800) / 800.f) * 3.14159f;
-		//	}
-		//
-		//	for (int j = 0; j < 1; j++)
-		//	{
-		//		float r = rand() % 35 + 10;
-		//
-		//		physicsEngine.addBody({rand() % 800 + 100, rand() % 800 + 100},
-		//			ph2d::createCircleCollider({r}));
-		//	}
-		//}
+		for (int i = 0; i < 2; i++)
+		{
+			if (1)
+			{
+				float w = rand() % 100 + 20;
+				float h = rand() % 100 + 20;
+		
+				auto body = physicsEngine.addBody({rand() % 800 + 100, rand() % 800 + 100},
+					ph2d::createBoxCollider({w, h}));
+				physicsEngine.bodies[body].motionState.rotation = ((rand() % 800) / 800.f) * 3.14159f;
+			}
+		
+			for (int j = 0; j < 1; j++)
+			{
+				float r = rand() % 35 + 10;
+		
+				physicsEngine.addBody({rand() % 800 + 100, rand() % 800 + 100},
+					ph2d::createCircleCollider({r}));
+			}
+		}
 
 
 		//floor
 		//floor
 		physicsEngine.addHalfSpaceStaticObject({0, 800}, {0.0, 1});
 		physicsEngine.addHalfSpaceStaticObject({0, 800}, {0.0, 1});
@@ -181,9 +181,21 @@ struct AngryBirds: public Container
 
 
 		if (input.lMouse.pressed())
 		if (input.lMouse.pressed())
 		{
 		{
+			addBlock(0, mousePosWorld);
 			addBlock(1, mousePosWorld);
 			addBlock(1, mousePosWorld);
+			addBlock(2, mousePosWorld);
+			addBlock(3, mousePosWorld);
+			addBlock(4, mousePosWorld);
+			addBlock(5, mousePosWorld);
+			addBlock(6, mousePosWorld);
+			addBlock(7, mousePosWorld);
 		}
 		}
 
 
+		//if (input.lMouse.pressed())
+		//{
+		//	addBlock(0, mousePosWorld);
+		//}
+
 
 
 	#pragma region render
 	#pragma region render
 
 
@@ -197,10 +209,10 @@ struct AngryBirds: public Container
 			{
 			{
 				int textureIndex = itFound->second.textureType;
 				int textureIndex = itFound->second.textureType;
 
 
-				//renderer.renderRectangle(b.getAABB().asVec4(),
-				//	textures[textureIndex],
-				//	Colors_White,
-				//	{}, b.motionState.rotation, texturesAtlas[textureIndex].get(0, 0));
+				renderer.renderRectangle(b.getAABB().asVec4(),
+					textures[textureIndex],
+					Colors_White,
+					{}, glm::degrees(b.motionState.rotation), texturesAtlas[textureIndex].get(0, 0));
 
 
 			}
 			}
 
 

+ 2 - 2
Pika/resources/logs.txt

@@ -1,2 +1,2 @@
-#2024-11-22 23:05:30: Created container: AngryBirds
-#2024-11-22 23:05:33: Destroyed continer: AngryBirds #1
+#2024-11-22 23:31:33: Created container: AngryBirds
+#2024-11-22 23:32:11: Destroyed continer: AngryBirds #1

+ 1 - 1
Pika/thirdparty/ph2d/include/ph2d/ph2d.h

@@ -330,7 +330,7 @@ namespace ph2d
 
 
 	bool BodyvsBody(Body &A, Body &B, float &penetration,
 	bool BodyvsBody(Body &A, Body &B, float &penetration,
 		glm::vec2 &normal, glm::vec2 &contactPoint, 
 		glm::vec2 &normal, glm::vec2 &contactPoint, 
-		glm::vec2 &tangentA, glm::vec2 &tangentB);
+		glm::vec2 &tangentA, glm::vec2 &tangentB, bool *reverseOrder = 0);
 
 
 	struct ManifoldIntersection
 	struct ManifoldIntersection
 	{
 	{

+ 29 - 9
Pika/thirdparty/ph2d/src/ph2d.cpp

@@ -976,10 +976,11 @@ namespace ph2d
 	}
 	}
 
 
 	bool BodyvsBody(Body &A, Body &B, float &penetration,
 	bool BodyvsBody(Body &A, Body &B, float &penetration,
-		glm::vec2 &normal, glm::vec2 &contactPoint, glm::vec2 &tangentA, glm::vec2 &tangentB)
+		glm::vec2 &normal, glm::vec2 &contactPoint, glm::vec2 &tangentA, glm::vec2 &tangentB, bool *reverseOrder)
 	{
 	{
 		tangentA = {};
 		tangentA = {};
 		tangentB = {};
 		tangentB = {};
+		if (reverseOrder) { *reverseOrder = false; }
 
 
 		if (A.collider.type == ph2d::ColliderCircle &&
 		if (A.collider.type == ph2d::ColliderCircle &&
 			B.collider.type == ph2d::ColliderCircle
 			B.collider.type == ph2d::ColliderCircle
@@ -1056,6 +1057,8 @@ namespace ph2d
 			LineEquation lineEquation;
 			LineEquation lineEquation;
 			lineEquation.createFromRotationAndPoint(B.motionState.rotation,
 			lineEquation.createFromRotationAndPoint(B.motionState.rotation,
 				B.motionState.pos);
 				B.motionState.pos);
+			
+			if (reverseOrder) { *reverseOrder = true; }
 
 
 			return ph2d::HalfSpaceVSCircle(
 			return ph2d::HalfSpaceVSCircle(
 				lineEquation, abox, penetration, normal, contactPoint);
 				lineEquation, abox, penetration, normal, contactPoint);
@@ -1086,6 +1089,7 @@ namespace ph2d
 			lineEquation.createFromRotationAndPoint(B.motionState.rotation,
 			lineEquation.createFromRotationAndPoint(B.motionState.rotation,
 				B.motionState.pos);
 				B.motionState.pos);
 
 
+			if (reverseOrder) { *reverseOrder = true; }
 			return ph2d::HalfSpaceVsOBB(
 			return ph2d::HalfSpaceVsOBB(
 				lineEquation, abox, A.motionState.rotation, penetration, normal, contactPoint,
 				lineEquation, abox, A.motionState.rotation, penetration, normal, contactPoint,
 			tangentB, tangentA);
 			tangentB, tangentA);
@@ -1736,20 +1740,36 @@ void ph2d::PhysicsEngine::runSimulation(float deltaTime)
 					glm::vec2 tangentA = {};
 					glm::vec2 tangentA = {};
 					glm::vec2 tangentB = {};
 					glm::vec2 tangentB = {};
 
 
+					bool reverseOrder = 0;
+
 					if (BodyvsBody(A, B, penetration, normal, contactPoint, 
 					if (BodyvsBody(A, B, penetration, normal, contactPoint, 
-						tangentA, tangentB))
+						tangentA, tangentB, &reverseOrder))
 					{
 					{
 						ManifoldIntersection intersection = {};
 						ManifoldIntersection intersection = {};
 
 
-						intersection.A = it1.first;
-						intersection.B = it2.first;
-						intersection.tangentA = tangentA;
-						intersection.tangentB = tangentB;
+						if (reverseOrder)
+						{
+							intersection.A = it2.first;
+							intersection.B = it1.first;
+							intersection.tangentA = tangentB;
+							intersection.tangentB = tangentA;
+							intersection.massA = B.motionState.mass;
+							intersection.massB = A.motionState.mass;
+							intersection.normal = -normal;
+						}
+						else
+						{
+							intersection.A = it1.first;
+							intersection.B = it2.first;
+							intersection.tangentA = tangentA;
+							intersection.tangentB = tangentB;
+							intersection.massA = A.motionState.mass;
+							intersection.massB = B.motionState.mass;
+							intersection.normal = normal;
+						}
+
 						intersection.contactPoint = contactPoint;
 						intersection.contactPoint = contactPoint;
-						intersection.normal = normal;
 						intersection.penetration = penetration;
 						intersection.penetration = penetration;
-						intersection.massA = A.motionState.mass;
-						intersection.massB = B.motionState.mass;
 
 
 						intersections.push_back(intersection);
 						intersections.push_back(intersection);
 					}
 					}