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


C++ Float3::magnitude方法代码示例

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


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

示例1: OnTriggerStay

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] );
	}
}
开发者ID:Burnsidious,项目名称:FSGDEngine,代码行数:27,代码来源:Blast.cpp

示例2: OnUpdate

	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 );
	}
开发者ID:Burnsidious,项目名称:FSGDEngine,代码行数:49,代码来源:Physics.cpp

示例3: Update

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) );
	}
}
开发者ID:Burnsidious,项目名称:FSGDEngine,代码行数:42,代码来源:HardAttach.cpp


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