void CMinotaurSpawn::AddColliders() { for (size_t currMesh = 0; currMesh < meshes.size(); currMesh++) { CMesh* mesh = meshes[currMesh]; XMFLOAT3 posOffset = XMFLOAT3(meshLocalMatricies[currMesh]._41, meshLocalMatricies[currMesh]._42, meshLocalMatricies[currMesh]._43); int startIndex = 0; if (mesh->IsPlane()) { int index = 0; for (index = 0; index < (int)mesh->GetAABBs().size(); index++) { CMesh::TAABB aabb = mesh->GetAABBs()[index]; aabb.center.x += posOffset.x; aabb.center.y += posOffset.y; aabb.center.z += posOffset.z; AddCollider(new CCollider(false, new CAABB(aabb.center, aabb.extents))); } index = 0; if (m_pvColliders[0]->GetType() == Bounds::Plane) index = 1; for (index; index < mesh->GetPlanes().size(); index++) { CMesh::TPlane plane = mesh->GetPlanes()[index]; plane.center.x += posOffset.x; plane.center.y += posOffset.y; plane.center.z += posOffset.z; AddCollider(new CCollider(false, new CPlane(plane.distance, plane.normal, plane.center, plane.extents))); } } else { int index = 0; if (m_pvColliders[0]->GetType() == Bounds::AABB) index = 1; for (index; index < mesh->GetAABBs().size(); index++) { CMesh::TAABB aabb = mesh->GetAABBs()[index]; aabb.center.x += posOffset.x; aabb.center.y += posOffset.y; aabb.center.z += posOffset.z; AddCollider(new CCollider(false, new CAABB(aabb.center, aabb.extents))); } for (index = 0; index < mesh->GetPlanes().size(); index++) { CMesh::TPlane plane = mesh->GetPlanes()[index]; plane.center.x += posOffset.x; plane.center.y += posOffset.y; plane.center.z += posOffset.z; AddCollider(new CCollider(false, new CPlane(plane.distance, plane.normal, plane.center, plane.extents))); } } } }
bool CMinotaurSpawn::LoadFromXML(const char* prefabName, CObjectManager* objManager) { TiXmlDocument doc; string path = "../Game/Assets/Scripts/Prefabs/"; path += prefabName; path += ".xml"; if (doc.LoadFile(path.c_str(), TiXmlEncoding::TIXML_ENCODING_UTF8)) { CAssetManager* pAssetManager = CAssetManager::GetInstance(); TiXmlElement * root = doc.RootElement(); TiXmlElement * ContentList = root->FirstChildElement("Meshes"); if (ContentList) { TiXmlElement * Mesh = ContentList->FirstChildElement("Mesh"); while (Mesh != nullptr) { double pos[4] = { 0.0 }; XMFLOAT3 position; const char* name = Mesh->Attribute("name"); const char* diffuse = Mesh->Attribute("diffuse"); const char* normal = Mesh->Attribute("normalMap"); Mesh->Attribute("transX", &pos[0]); Mesh->Attribute("transY", &pos[1]); Mesh->Attribute("transZ", &pos[2]); if (diffuse) diffuseTextures.push_back(diffuse); if (normal) normalMaps.push_back(normal); CMesh* mesh = pAssetManager->GetPrefabMesh(name); if (pos[3] == 90.0f) { for (size_t i = 0; i < mesh->GetPlanes().size(); i++) std::swap(mesh->GetPlanes()[i].extents.x, mesh->GetPlanes()[i].extents.z); for (size_t i = 0; i < mesh->GetAABBs().size(); i++) std::swap(mesh->GetAABBs()[i].extents.x, mesh->GetAABBs()[i].extents.z); } XMFLOAT4X4 local = {}; XMStoreFloat4x4(&local, XMMatrixTranslation(pos[0], pos[1], pos[2])); meshLocalMatricies.push_back(local); meshes.push_back(mesh); Mesh = Mesh->NextSiblingElement(); } } ContentList = root->FirstChildElement("Objects"); if (ContentList && objManager) { TiXmlElement * Object = ContentList->FirstChildElement("Object"); while (Object != nullptr) { int _type = 0; double data[4]; XMFLOAT3 position; Object->Attribute("type", &_type); Object->Attribute("transX", &data[0]); Object->Attribute("transY", &data[1]); Object->Attribute("transZ", &data[2]); position = XMFLOAT3(float(data[0]), float(data[1]), float(data[2])); int orientation = 0; Object->Attribute("dir", &orientation); m_vObjects.push_back(new CItemCrate((IChest::EDirection)orientation, position, m_pDayNight)); Object = Object->NextSiblingElement(); } } } return true; }
void CPrefabObject::AddColliders() { for (size_t currMesh = 0; currMesh < meshes.size(); currMesh++) { CMesh* mesh = meshes[currMesh]; int startIndex = 0; if (mesh->IsPlane() ) { int index = 0; for (index = 0; index < (int)mesh->GetAABBs().size(); index++) { CMesh::TAABB aabb = mesh->GetAABBs()[index]; if (m_szTag == "SafeHaven" && (aabb.extents.x == 500.0f && aabb.extents.y == 300.0f && aabb.extents.z == 500.0f)) AddCollider(new CCollider(false, new CAABB(aabb.center, aabb.extents), true, false)); else AddCollider(new CCollider(false, new CAABB(aabb.center, aabb.extents))); } index = 0; if (m_pvColliders[0]->GetType() == Bounds::Plane) index = 1; for (index; index < mesh->GetPlanes().size(); index++) { CMesh::TPlane plane = mesh->GetPlanes()[index]; AddCollider(new CCollider(false, new CPlane(plane.distance, plane.normal, plane.center, plane.extents))); } } else { int index = 0; if (m_pvColliders[0]->GetType() == Bounds::AABB) index = 1; for (index; index < mesh->GetAABBs().size(); index++) { CMesh::TAABB aabb = mesh->GetAABBs()[index]; if (m_szTag == "SafeHaven" && (aabb.extents.x == 500.0f && aabb.extents.y == 300.0f && aabb.extents.z == 500.0f)) AddCollider(new CCollider(false, new CAABB(aabb.center, aabb.extents), true, false)); else AddCollider(new CCollider(false, new CAABB(aabb.center, aabb.extents))); } for (index = 0; index < mesh->GetPlanes().size(); index++) { CMesh::TPlane plane = mesh->GetPlanes()[index]; if (m_szTag == "SmallPit") { if (plane.center.y < 0.0f) AddCollider(new CCollider(false, new CPlane(plane.distance, plane.normal, plane.center, plane.extents))); else AddCollider(new CCollider(false, new CPlane(plane.distance, plane.normal, plane.center, plane.extents),true, false)); } else AddCollider(new CCollider(false, new CPlane(plane.distance, plane.normal, plane.center, plane.extents))); } } } }