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


C++ PhysicsContact::ChangeVelocity方法代码示例

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


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

示例1: privCheckCollisions

// Check our collisions and handle them accordingly
void Demo::privCheckCollisions(const float timeIn)
{
	PhysicsContact contact;
	contact.Reset();

	// Check bullet and ground
	if (CheckColliding(ground, bullet, contact))
	{
		// Handle collision
		contact.CalculateData(timeIn);
		contact.ChangeVelocity();
		contact.ChangePosition();
		contact.Reset();
	}

	// Check all bricks against ground
	for (int i = 0; i < NUM_BRICKS; i++)
	{ 
		if (CheckColliding(bricks[i], ground, contact))
		{
			// Handle collision
			contact.CalculateData(timeIn);
			contact.ChangeVelocity();
			contact.ChangePosition();
			contact.Reset();
		}
	}

	// Check all bricks against bullet
	for (int i = 0; i < NUM_BRICKS; i++)
	{ 
		if (CheckColliding(bullet, bricks[i], contact))
		{
			contact.CalculateData(timeIn);

			// Time to have some fun with all blocks within certain distance of this collision
			// Launch those bricks upward with random angular velocity
			for (int k = 0; k < NUM_BRICKS; k++)
			{
				// use mag squared to avoid square root
				Vect diffPos = bricks[k].position - contact.contactPoint;
				float magSquared = diffPos.magSqr();
				
				if (magSquared < 1500.0f && bricks[k].position[1] >= bricks[i].position[1])
				{
					Vect velocityChange(diffPos[0] > 0 ? 30.0f : -30.0f, 200.0f, 0.0f);
					bricks[k].velocity += velocityChange;

					static int x = 987444303;
					srand(x);
					x += 5134;

					// Random angular velocity
					Vect angVelocityChange(0.0f, 0.0f, 0.0f);
					angVelocityChange[0] = (float)(rand() % 60 - 30);
					angVelocityChange[1] = (float)(rand() % 60 - 30);
					angVelocityChange[2] = (float)(rand() % 60 - 30);

					bricks[k].angVelocity += angVelocityChange;
				}
			}

			// Slow time on this collision
			if (!this->timeSlowed)
			{
				this->slowTimer = 0.0f;
				this->timeSlowed = true;
				this->motionBlur.blurOn = true;
			}
			contact.Reset();
			bullet.active = false;
			break;
		}
	}

	// Now check all bricks with each other
	for (int i = 0; i < NUM_BRICKS; i++)
	{
		for (int j = i + 1; j < NUM_BRICKS; j++)
		{
			if (CheckColliding(bricks[i], bricks[j], contact))
			{
				// Handle collision accordingly
				contact.CalculateData(timeIn);
				contact.ChangeVelocity();
				contact.ChangePosition();
				contact.Reset();
			}
		}
	}

	return;
};
开发者ID:jtomola,项目名称:BricksDemo,代码行数:94,代码来源:Demo.cpp


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