예제 #1
0
void Blast::OnTriggerStay(EDGameCore::ICollider* thisCollider, EDGameCore::ICollider* otherCollider, const EDCollision::Contact& contact)
{
	if( otherCollider->GetAttachedRigidBody() != 0 )
	{
		EDCollision::Contact contact2 = contact;
		
		Float3 delta = otherCollider->GetTransform()->GetWorldMatrix().WAxis - GetTransform()->GetWorldMatrix().WAxis;

		if( DotProduct( delta, contact.Normal ) < 0.0f )
			contact2.negate();

		float mag = delta.magnitude();

		if( mag == 0.0f )
		{
			delta = Float3(0.0f, 1.0f, 0.0f);
			mag = 1.0f;
		}
		else
			delta *= (1.0f / mag);

		delta *= 15000.0f / (mag*mag);
		delta *= (1.0f / EDGameCore::Game::GetDeltaTime());

		otherCollider->GetAttachedRigidBody()->ApplyForceAtPoint( delta, contact2.Point[0] );
	}
}
예제 #2
0
	void Physics::OnUpdate(IBehavior* invokingBehavior, IMessage* message)
	{
		Physics* pPhysics = (Physics*)invokingBehavior;

		const Aabb& objLocalAabb = pPhysics->gameObject->GetLocalAabb();
		for(unsigned int i = 0; i < 3; ++i)
		{
			if( pPhysics->localAabb.min.v[i] != objLocalAabb.min.v[i] ||
				pPhysics->localAabb.max.v[i] != objLocalAabb.max.v[i] )
			{
				pPhysics->Initialize();
				return;
			}
		}

		if( pPhysics->physicsFlags & GRAVITY )
		{
			Attribute<bool>* groundedAttrib = (Attribute<bool>*)pPhysics->GetAttribute(
				PhysicsAttributes::GROUNDED_ATTRIB);

			if( groundedAttrib->value == false )
				pPhysics->ApplyGravity();
		}

		Float3 com(0.0f, 0.0f, 0.0f);
		for(unsigned int i = 0; i < pPhysics->m_X.size(); ++i)
			com += pPhysics->m_X[i];
		
		com *= (1.0f / pPhysics->m_X.size());

		pPhysics->ApplyVerlet();
		pPhysics->ApplyConstraints();

		Float3 newcom(0.0f, 0.0f, 0.0f);
		for(unsigned int i = 0; i < pPhysics->m_X.size(); ++i)
			newcom += pPhysics->m_X[i];
		
		newcom *= (1.0f / pPhysics->m_X.size());

		Float3 delta = newcom - com;

		if( delta.magnitude() > 0.25f )
		{
			delta.normalize();
			delta *= 0.25f;
		}

		pPhysics->gameObject->TranslateGlobal( delta );
	}
예제 #3
0
void HardAttach::Update(void)
{
	static const EDGameCore::RegistrationId MSG_CLAMP = EDGameCore::Message("MSG_CLAMP").messageId;

	if( targetId != 0 )
	{
		EDGameCore::GameObject* targetObj = EDGameCore::GameObject::GetGameObjectInstance(targetId);

		if( targetObj == 0 )
		{
			targetId = 0;
			return;
		}

		Float4x4 newMat = GetTransform()->GetLocalMatrix();

		TransformPoint( newMat.WAxis, offset, targetObj->GetTransform()->GetWorldMatrix() );
		
		unsigned int clampToId = 0;
		if( clamp )
		{
			Float3 startPos = targetObj->GetTransform()->GetWorldMatrix().WAxis;
			Float3 delta = newMat.WAxis - startPos;
	
			float deltaLen = delta.magnitude();
	
			Float3 deltaN = delta * (1.0f / deltaLen);

			EDGameCore::RayHit rayHit;
			if( EDGameCore::Physics::RayCast( startPos, deltaN, deltaLen, GetGameObject()->GetLayerMask(), rayHit ) )
			{
				newMat.WAxis = rayHit.Point;
				clampToId = rayHit.collider->GetGameObject()->GetInstanceId();
			}
		}
		
		GetTransform()->SetLocalMatrix( newMat );

		if( clampToId != 0 )
			GetGameObject()->OnMessage( EDGameCore::MessageT<unsigned int>(MSG_CLAMP, clampToId) );
	}
}