void WBCompEldAnchor::SetAnchor()
{
	EldritchWorld* const		pWorld			= GetWorld();
	ASSERT( pWorld );

	WBEntity* const				pEntity			= GetEntity();
	DEVASSERT( pEntity );

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

	const Angles				Orientation		= pTransform->GetOrientation();
	const Matrix				RotationMatrix	= Orientation.ToMatrix();
	const Vector				AnchorVector	= m_AnchorDirection * RotationMatrix;
	const Vector				StartLocation	= pTransform->GetLocation();
	const Ray					TraceRay		= Ray( StartLocation, AnchorVector );

	CollisionInfo Info;
	Info.m_CollideWorld		= true;
	Info.m_CollideEntities	= true;
	Info.m_CollidingEntity	= pEntity;
	Info.m_UserFlags		= EECF_CollideAsEntity | EECF_CollideStaticEntities;

	if( pWorld->Trace( TraceRay, Info ) )
	{
		m_AnchorPoint	= Info.m_Intersection + AnchorVector * 0.1f;
		ASSERT( pWorld->PointCheck( m_AnchorPoint, Info ) );	// Since hard-coded 0.1 might break for thin surfaces.
		m_IsAnchored	= true;
	}
}
Example #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;
  }
}