当前位置: 首页>>代码示例>>C++>>正文


C++ PhysicsObject::GetAABB方法代码示例

本文整理汇总了C++中PhysicsObject::GetAABB方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsObject::GetAABB方法的具体用法?C++ PhysicsObject::GetAABB怎么用?C++ PhysicsObject::GetAABB使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhysicsObject的用法示例。


在下文中一共展示了PhysicsObject::GetAABB方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Collision

		// Helper function for 'axis'-axis collisions at 'angle' collision angle (radians)
		// X-Axis angles are bound to (-pi/2,pi/2)
		// Y-Axis angles are bound to (0, pi)
		static void Collision(eAxis axis, double angle)
		{
			// Wrap angle around (0, 2pi)
			angle = WrapAngle(angle);

			// Assert valid collision angle
			if (axis == XAxis)
			{
				Assert::IsTrue(((angle > 3*M_PI/2) && (angle <= 2*M_PI)) ||
							   ((angle >= 0.0) && (angle < M_PI/2)));
			}
			if (axis == YAxis)
			{
				Assert::IsTrue((angle > 0) && (angle < M_PI));
			}

			// Create reference object
			PhysicsObject refObj = PhysicsObject();
			double halfwidth = refObj.GetAABB().GetWidth()/2;
			
			// Offset object A from epicenter along reflection of collision angle
			double reflAngle = angle + M_PI;
			double xOffset = (EPICENTER_OFFSET+halfwidth) * cos(reflAngle);
			double yOffset = (EPICENTER_OFFSET+halfwidth) * sin(reflAngle);
			CartPoint centerA = {EPICENTER.x + xOffset, EPICENTER.y + yOffset};
			PhysicsObject objA = PhysicsObject(centerA);

			// Offset object B from epicenter along collision axis
			CartPoint centerB;
			switch (axis)
			{
			case XAxis:
				centerB.x = EPICENTER.x + EPICENTER_OFFSET+halfwidth;
				centerB.y = EPICENTER.y;
				break;
			case YAxis:
				centerB.x = EPICENTER.x;
				centerB.y = EPICENTER.y + EPICENTER_OFFSET+halfwidth;
				break;
			case BothAxes:
				// TODO: revisit, hardcoded and probably wrong, needs reflected position calculated
				centerB.x = EPICENTER.x + (EPICENTER_OFFSET+halfwidth)/2;
				centerB.y = EPICENTER.y + (EPICENTER_OFFSET+halfwidth)/2;
				break;
			default: // AxisErr
				Assert::Fail();
				break;
			}
			PhysicsObject objB = PhysicsObject(centerB);
			
			// Set trajectories
			Trajectory trajA = Trajectory(testScene.GetGravity(), DEFAULT_VELOCITY, angle, objA.GetAABB().GetCenter(), TIME_SIM_START);
			Trajectory trajB;
			switch (axis)
			{
			case XAxis:
				trajB = Trajectory(testScene.GetGravity(), DEFAULT_VELOCITY, M_PI, objB.GetAABB().GetCenter(), TIME_SIM_START);
				break;
			case YAxis:
				trajB = Trajectory(testScene.GetGravity(), DEFAULT_VELOCITY, 3*M_PI/2, objB.GetAABB().GetCenter(), TIME_SIM_START);
				break;
			case BothAxes:
				trajB = Trajectory(testScene.GetGravity(), DEFAULT_VELOCITY, reflAngle, objB.GetAABB().GetCenter(), TIME_SIM_START);
				break;
			default: // AxisErr
				Assert::Fail();
				break;
			}
			objA.SetTrajectory(trajA);
			objB.SetTrajectory(trajB);

			// Add objects to Scene
			Assert::AreEqual(testScene.AddObject(&objA), S_OK);
			Assert::AreEqual(testScene.AddObject(&objB), S_OK);

			// Calculate distance between AABB boundaries
			double boundsDist = -1.0;
			switch (axis)
			{
			case XAxis:
				boundsDist = abs((objA.GetAABB().GetRightBound()) - (objB.GetAABB().GetLeftBound()));
				break;
			case YAxis:
				boundsDist = abs((objA.GetAABB().GetUpperBound()) - (objB.GetAABB().GetLowerBound()));
				break;
			case BothAxes:
				// TODO: properly calculate corner distance, velocity
				Assert::Fail();
				break;
			default: // AxisErr
				Assert::Fail();
				break;
			}
			
			// Calculate velocities of each object
			double startTime = 0.0;
			double velObjA = abs(objA.GetTrajectory().GetVelocity(axis, startTime));
//.........这里部分代码省略.........
开发者ID:cjm571,项目名称:egine,代码行数:101,代码来源:ZeroGravTests.cpp


注:本文中的PhysicsObject::GetAABB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。