Esempio n. 1
0
void ezWorld::SetParent(ezGameObject* pObject, ezGameObject* pNewParent, ezGameObject::TransformPreservation preserve)
{
  EZ_ASSERT_DEV(pObject != pNewParent, "Object can't be its own parent!");
  EZ_ASSERT_DEV(pNewParent == nullptr || pObject->IsDynamic() || pNewParent->IsStatic(),
                "Can't attach a static object to a dynamic parent!");
  CheckForWriteAccess();

  if (GetObjectUnchecked(pObject->m_ParentIndex) == pNewParent)
    return;

  UnlinkFromParent(pObject);
  // UnlinkFromParent does not clear these as they are still needed in DeleteObjectNow to allow deletes while iterating.
  pObject->m_NextSiblingIndex = 0;
  pObject->m_PrevSiblingIndex = 0;
  if (pNewParent != nullptr)
  {
    // Ensure that the parent's global transform is up-to-date otherwise the object's local transform will be wrong afterwards.
    pNewParent->UpdateGlobalTransform();

    pObject->m_ParentIndex = pNewParent->m_InternalId.m_InstanceIndex;
    LinkToParent(pObject);
  }

  PatchHierarchyData(pObject, preserve);
}
Esempio n. 2
0
swObject::swObject(swObject* swParent, uint _flags, const char* _nameID):sigc::trackable(),
  m_parent( swParent ),
  m_nameID(_nameID),
  m_flags(_flags)
{
    m_ChildIT = m_children.end();
    if( swParent ) LinkToParent( swParent );
}
Esempio n. 3
0
swObject::swObject(swObject* swParent):sigc::trackable(),
  m_parent( swParent ),
  m_nameID("swObject"),
  m_flags(0)
{
    m_ChildIT = m_children.end();
    if( swParent ) LinkToParent( swParent );
}
Esempio n. 4
0
 Object::Object ( Object* swParent,const char* NameID ) :sigc::trackable(),
         _parent ( swParent ),
         _nameID ( NameID ),
         _eventsMask ( 0 )
 {
     _ChildIT = _children.end();
     if ( swParent ) LinkToParent ( swParent );
 }
Esempio n. 5
0
 Object::Object ( Object* swParent ) :sigc::trackable(),
         _parent ( swParent ),
         _nameID ( "Object" ),
         _eventsMask ( 0 )
 {
     _ChildIT = _children.end();
     if ( swParent ) LinkToParent ( swParent );
 }
Esempio n. 6
0
ezGameObjectHandle ezWorld::CreateObject(const ezGameObjectDesc& desc, ezGameObject*& out_pObject)
{
  CheckForWriteAccess();

  ezGameObject* pParentObject = nullptr;
  ezGameObject::TransformationData* pParentData = nullptr;
  ezUInt32 uiParentIndex = 0;
  ezUInt32 uiHierarchyLevel = 0;
  bool bDynamic = desc.m_bDynamic;

  if (TryGetObject(desc.m_hParent, pParentObject))
  {
    pParentData = pParentObject->m_pTransformationData;
    uiParentIndex = desc.m_hParent.m_InternalId.m_InstanceIndex;
    uiHierarchyLevel = pParentObject->m_uiHierarchyLevel + 1; // if there is a parent hierarchy level is parent level + 1
    EZ_ASSERT_DEV(uiHierarchyLevel < (1 << 12), "Max hierarchy level reached");
    bDynamic |= pParentObject->IsDynamic();
  }

  // get storage for the transformation data
  ezGameObject::TransformationData* pTransformationData = m_Data.CreateTransformationData(bDynamic, uiHierarchyLevel);

  // get storage for the object itself
  ezGameObject* pNewObject = m_Data.m_ObjectStorage.Create();

  // insert the new object into the id mapping table
  ezGameObjectId newId = m_Data.m_Objects.Insert(pNewObject);
  newId.m_WorldIndex = m_uiIndex;

  // fill out some data
  pNewObject->m_InternalId = newId;
  pNewObject->m_Flags = ezObjectFlags::None;
  pNewObject->m_Flags.AddOrRemove(ezObjectFlags::Dynamic, bDynamic);
  pNewObject->m_Flags.AddOrRemove(ezObjectFlags::Active, desc.m_bActive);
  pNewObject->m_sName = desc.m_sName;
  pNewObject->m_pWorld = this;
  pNewObject->m_ParentIndex = uiParentIndex;
  pNewObject->m_Tags = desc.m_Tags;
  pNewObject->m_uiTeamID = desc.m_uiTeamID;

  pNewObject->m_uiHierarchyLevel = uiHierarchyLevel;

  // fill out the transformation data
  pTransformationData->m_pObject = pNewObject;
  pTransformationData->m_pParentData = pParentData;
  pTransformationData->m_localPosition = ezSimdConversion::ToVec3(desc.m_LocalPosition);
  pTransformationData->m_localRotation = ezSimdConversion::ToQuat(desc.m_LocalRotation);
  pTransformationData->m_localScaling = ezSimdConversion::ToVec4(desc.m_LocalScaling.GetAsVec4(desc.m_LocalUniformScaling));
  pTransformationData->m_globalTransform.SetIdentity();
  pTransformationData->m_velocity.SetZero();
  pTransformationData->m_localBounds.SetInvalid();
  pTransformationData->m_localBounds.m_BoxHalfExtents.SetW(ezSimdFloat::Zero());
  pTransformationData->m_globalBounds = pTransformationData->m_localBounds;
  pTransformationData->m_hSpatialData.Invalidate();

  if (pParentData != nullptr)
  {
    pTransformationData->UpdateGlobalTransformWithParent();
  }
  else
  {
    pTransformationData->UpdateGlobalTransform();
  }

  pTransformationData->m_lastGlobalPosition = pTransformationData->m_globalTransform.m_Position;

  // link the transformation data to the game object
  pNewObject->m_pTransformationData = pTransformationData;

  // fix links
  LinkToParent(pNewObject);

  out_pObject = pNewObject;
  return ezGameObjectHandle(newId);
}