예제 #1
0
void WBCompEldMesh::GetAnimationVelocity(Vector& OutVelocity,
                                         Angles& OutRotationalVelocity) {
  ASSERT(m_Mesh);

  WBCompEldTransform* pTransform =
      GetEntity()->GetTransformComponent<WBCompEldTransform>();
  DEVASSERT(pTransform);

  m_Mesh->GetAnimationVelocity(OutVelocity, OutRotationalVelocity);
  OutVelocity = OutVelocity.RotateBy(pTransform->GetOrientation());
}
예제 #2
0
bool WBCompEldMesh::UpdateMeshTransform() {
  ASSERT(m_Mesh);

  WBCompEldTransform* pTransform =
      GetEntity()->GetTransformComponent<WBCompEldTransform>();
  DEVASSERT(pTransform);  // Makes no sense to have a mesh and no transform

  const Vector EntityLocation = pTransform->GetLocation();
  const Vector CurrentLocation = EntityLocation + m_Offset;
  m_Mesh->m_Location = CurrentLocation;

  const Angles EntityOrientation = pTransform->GetOrientation();
  m_Mesh->m_Rotation = EntityOrientation;

  // Optimization, avoid the matrix and AABB calcs if nothing has changed
  if (m_OldTransform_Location != m_Mesh->m_Location ||
      m_OldTransform_Rotation != m_Mesh->m_Rotation ||
      m_OldTransform_Scale != m_Mesh->m_Scale || m_ForceUpdateTransform) {
    m_OldTransform_Location = m_Mesh->m_Location;
    m_OldTransform_Rotation = m_Mesh->m_Rotation;
    m_OldTransform_Scale = m_Mesh->m_Scale;
    m_ForceUpdateTransform = false;

    // Seems like maybe this AABB stuff should be done routinely in the Mesh. :/
    const Matrix ScaleMatrix = Matrix::CreateScale(m_Mesh->m_Scale);
    const Matrix RotationMatrix = EntityOrientation.ToMatrix();
    const Matrix TranslationMatrix = Matrix::CreateTranslation(CurrentLocation);
    const Matrix AABBTransform =
        ScaleMatrix * RotationMatrix * TranslationMatrix;
    m_Mesh->m_AABB = m_MeshOriginalAABB.GetTransformedBound(AABBTransform);

    return true;
  } else {
    return false;
  }
}