本文整理汇总了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] );
}
}
示例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 );
}
示例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) );
}
}