Пример #1
0
void RigidBody::ApplyImpulse(Vector3 const& impulse, Vector3 const& point)
{
	if(HasInfiniteMass()) return;

	Vector3 deltaVelocity = impulse * GetInverseMass();
	SetVelocity(GetVelocity() + deltaVelocity);

	Vector3 deltaOmega = GetInverseInertialTensor() * (point-GetPosition()).crossProduct(impulse);
	SetAngularVelocity(GetAngularVelocity() + deltaOmega);
}
Пример #2
0
void RigidBody::QueueImpulse(Vector3 const& impulse, Vector3 const& p)
{
	if(HasInfiniteMass()) return;

	Vector3 deltaVelocity = impulse * GetInverseMass();
	m_queuedDeltaVelocity += deltaVelocity;

	Vector3 deltaOmega = GetInverseInertialTensor() * (p-GetPosition()).crossProduct(impulse);
	m_queuedDeltaAngularVelocity += deltaOmega;
}
Пример #3
0
	void Physics::CalculatePosition(GameObject& obj)
	{
		if (state != PHYSICS_PAUSE)
		{
			auto transformComponent = obj.has(Transform);
			auto bodyComponent = obj.has(Body);
			//accumulate the total force
			auto a = gravity + bodyComponent->GetForce()*bodyComponent->GetInverseMass();
			auto position = transformComponent->GetPosition() + bodyComponent->GetVelocity()*debugDt;
			auto velocity = bodyComponent->GetVelocity() + a*debugDt;
			velocity *= std::pow(damping, debugDt);
			transformComponent->SetPosition(position);
			//Dont set the velocity of the object
			if (state != PHYSICS_FORWARD && state != PHYSICS_REVERSE)
			{
				bodyComponent->SetVelocity(velocity);
			}
		}
		switch (state)
		{
		case PHYSICS_PLAY:
			break;
		case PHYSICS_PAUSE:
			debugDt = 0.0f;
			state = PHYSICS_PAUSE;
			break;
		case PHYSICS_FORWARD:
			debugDt = 0.0f;
			state = PHYSICS_PAUSE;
			break;
		case PHYSICS_REVERSE:
			debugDt = 0.0f;
			state = PHYSICS_PAUSE;
			break;
		}	
		auto draw = true;
		ImGui::Begin("Physics", &draw, ImVec2(350, 350), 0.5);
		ImGui::Text("Use Space to Toogle play/pause");
		ImGui::Text("Left arrow key for previous frame(when paused)");
		ImGui::Text("Right arrow key for next frame(when paused)");
		ImGui::Text("Use 1 to toogle debug draw");
		ImGui::End();
	}
Пример #4
0
void RigidBody2D::AddLinearImpulse(const Vector2& i_impulse)
{
	//TODO //CHECK CHECKCHECK CHECKCHECK CHECKCHECK CHECKCHECK CHECKCHECK CHECK
	m_linearVelocity += i_impulse * GetInverseMass();
}