mirror of https://github.com/AxioDL/metaforce.git
CCollisionActor: Minor fixes and cleanups
This commit is contained in:
parent
f1b0c4b735
commit
0d63119cfc
|
@ -106,12 +106,12 @@ const CDamageVulnerability* CCollisionActor::GetDamageVulnerability(const zeus::
|
|||
void CCollisionActor::SetDamageVulnerability(const CDamageVulnerability& vuln) { x294_damageVuln = vuln; }
|
||||
|
||||
zeus::CVector3f CCollisionActor::GetScanObjectIndicatorPosition(const CStateManager& mgr) const {
|
||||
const CGameCamera* gameCamera = static_cast<const CGameCamera*>(mgr.GetCameraManager()->GetCurrentCamera(mgr));
|
||||
const auto* gameCamera = static_cast<const CGameCamera*>(mgr.GetCameraManager()->GetCurrentCamera(mgr));
|
||||
|
||||
float scanScale;
|
||||
if (x258_primitiveType == EPrimitiveType::Sphere)
|
||||
if (x258_primitiveType == EPrimitiveType::Sphere) {
|
||||
scanScale = GetSphereRadius();
|
||||
else {
|
||||
} else {
|
||||
const zeus::CVector3f v = GetBoxSize();
|
||||
float comp = (v.x() < v.y() ? v.y() : v.z());
|
||||
comp = (comp < v.z() ? v.x() : comp);
|
||||
|
@ -124,10 +124,12 @@ zeus::CVector3f CCollisionActor::GetScanObjectIndicatorPosition(const CStateMana
|
|||
}
|
||||
|
||||
const CCollisionPrimitive* CCollisionActor::GetCollisionPrimitive() const {
|
||||
if (x258_primitiveType == EPrimitiveType::OBBTreeGroup)
|
||||
if (x258_primitiveType == EPrimitiveType::OBBTreeGroup) {
|
||||
return x27c_obbTreeGroupPrimitive.get();
|
||||
if (x258_primitiveType == EPrimitiveType::AABox)
|
||||
}
|
||||
if (x258_primitiveType == EPrimitiveType::AABox) {
|
||||
return x280_aaboxPrimitive.get();
|
||||
}
|
||||
return x284_spherePrimitive.get();
|
||||
}
|
||||
|
||||
|
@ -158,9 +160,9 @@ std::optional<zeus::CAABox> CCollisionActor::GetTouchBounds() const {
|
|||
}
|
||||
|
||||
void CCollisionActor::OnScanStateChanged(EScanState state, CStateManager& mgr) {
|
||||
TCastToPtr<CActor> actor = mgr.ObjectById(x25c_owner);
|
||||
if (actor)
|
||||
if (const TCastToPtr<CActor> actor = mgr.ObjectById(x25c_owner)) {
|
||||
actor->OnScanStateChanged(state, mgr);
|
||||
}
|
||||
|
||||
CActor::OnScanStateChanged(state, mgr);
|
||||
}
|
||||
|
@ -173,8 +175,9 @@ void CCollisionActor::Touch(CActor& actor, CStateManager& mgr) {
|
|||
zeus::CVector3f CCollisionActor::GetOrbitPosition(const CStateManager&) const { return GetTouchBounds()->center(); }
|
||||
|
||||
void CCollisionActor::SetSphereRadius(float radius) {
|
||||
if (x258_primitiveType != EPrimitiveType::Sphere)
|
||||
if (x258_primitiveType != EPrimitiveType::Sphere) {
|
||||
return;
|
||||
}
|
||||
|
||||
x288_sphereRadius = radius;
|
||||
x284_spherePrimitive->SetSphereRadius(radius);
|
||||
|
|
|
@ -24,11 +24,73 @@ CCollisionActorManager::CCollisionActorManager(CStateManager& mgr, TUniqueId own
|
|||
modDesc.ScaleAllBounds(scale);
|
||||
const zeus::CTransform locXf = GetWRLocatorTransform(*animData, modDesc.GetPivotId(), xf, scaleXf);
|
||||
|
||||
if (modDesc.GetNextId().IsValid()) {
|
||||
if (modDesc.GetNextId().IsInvalid()) {
|
||||
// We only have the pivot id
|
||||
const TUniqueId newId = mgr.AllocateUniqueId();
|
||||
CCollisionActor* newAct;
|
||||
|
||||
if (modDesc.GetType() == CJointCollisionDescription::ECollisionType::Sphere) {
|
||||
newAct = new CCollisionActor(newId, area, x10_ownerId, active, modDesc.GetRadius(), modDesc.GetMass(),
|
||||
desc.GetName());
|
||||
} else if (modDesc.GetType() == CJointCollisionDescription::ECollisionType::OBB) {
|
||||
newAct = new CCollisionActor(newId, area, x10_ownerId, modDesc.GetBounds(), modDesc.GetPivotPoint(), active,
|
||||
modDesc.GetMass(), desc.GetName());
|
||||
} else {
|
||||
newAct = new CCollisionActor(newId, area, x10_ownerId, modDesc.GetBounds(), active, modDesc.GetMass(),
|
||||
desc.GetName());
|
||||
}
|
||||
|
||||
newAct->SetTransform(locXf);
|
||||
mgr.AddObject(newAct);
|
||||
x0_jointDescriptions.push_back(desc);
|
||||
x0_jointDescriptions.back().SetCollisionActorId(newId);
|
||||
} else { // We have another bone in to connect to!
|
||||
const zeus::CTransform locXf2 = GetWRLocatorTransform(*animData, modDesc.GetNextId(), xf, scaleXf);
|
||||
const float dist = (locXf2.origin - locXf.origin).magnitude();
|
||||
|
||||
if (modDesc.GetType() == CJointCollisionDescription::ECollisionType::OBBAutoSize) {
|
||||
if (modDesc.GetType() != CJointCollisionDescription::ECollisionType::OBBAutoSize) {
|
||||
const TUniqueId newId = mgr.AllocateUniqueId();
|
||||
auto* newAct = new CCollisionActor(newId, area, x10_ownerId, active, modDesc.GetRadius(), modDesc.GetMass(),
|
||||
desc.GetName());
|
||||
|
||||
newAct->SetTransform(locXf);
|
||||
mgr.AddObject(newAct);
|
||||
x0_jointDescriptions.push_back(CJointCollisionDescription::SphereCollision(
|
||||
modDesc.GetPivotId(), modDesc.GetRadius(), modDesc.GetName(), 0.001f));
|
||||
x0_jointDescriptions.back().SetCollisionActorId(newId);
|
||||
|
||||
const u32 numSeps = u32(dist / modDesc.GetMaxSeparation());
|
||||
if (numSeps != 0) {
|
||||
x0_jointDescriptions.reserve(x0_jointDescriptions.capacity() + numSeps);
|
||||
const float pitch = dist / float(numSeps + 1);
|
||||
for (u32 i = 0; i < numSeps; ++i) {
|
||||
const float separation = pitch * float(i + 1);
|
||||
x0_jointDescriptions.push_back(CJointCollisionDescription::SphereSubdivideCollision(
|
||||
modDesc.GetPivotId(), modDesc.GetNextId(), modDesc.GetRadius(), separation,
|
||||
CJointCollisionDescription::EOrientationType::One, modDesc.GetName(), 0.001f));
|
||||
|
||||
const TUniqueId newId2 = mgr.AllocateUniqueId();
|
||||
auto* newAct2 = new CCollisionActor(newId2, area, x10_ownerId, active, modDesc.GetRadius(),
|
||||
modDesc.GetMass(), desc.GetName());
|
||||
if (modDesc.GetOrientationType() == CJointCollisionDescription::EOrientationType::Zero) {
|
||||
newAct2->SetTransform(zeus::CTransform::Translate(locXf.origin + (separation * locXf.basis[1])));
|
||||
} else {
|
||||
const zeus::CVector3f delta = (locXf2.origin - locXf.origin).normalized();
|
||||
zeus::CVector3f upVector = locXf.basis[2];
|
||||
|
||||
if (zeus::close_enough(std::fabs(delta.dot(upVector)), 1.f)) {
|
||||
upVector = locXf.basis[1];
|
||||
}
|
||||
|
||||
const zeus::CTransform lookAt = zeus::lookAt(zeus::skZero3f, delta, upVector);
|
||||
newAct2->SetTransform(zeus::CTransform::Translate(locXf.origin + (separation * lookAt.basis[1])));
|
||||
}
|
||||
|
||||
mgr.AddObject(newAct2);
|
||||
x0_jointDescriptions.back().SetCollisionActorId(newId2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (dist <= FLT_EPSILON) {
|
||||
continue;
|
||||
}
|
||||
|
@ -55,68 +117,7 @@ CCollisionActorManager::CCollisionActorManager(CStateManager& mgr, TUniqueId own
|
|||
mgr.AddObject(newAct);
|
||||
x0_jointDescriptions.push_back(desc);
|
||||
x0_jointDescriptions.back().SetCollisionActorId(newAct->GetUniqueId());
|
||||
} else {
|
||||
const TUniqueId newId = mgr.AllocateUniqueId();
|
||||
auto* newAct = new CCollisionActor(newId, area, x10_ownerId, active, modDesc.GetRadius(), modDesc.GetMass(),
|
||||
desc.GetName());
|
||||
|
||||
newAct->SetTransform(locXf);
|
||||
mgr.AddObject(newAct);
|
||||
x0_jointDescriptions.push_back(CJointCollisionDescription::SphereCollision(
|
||||
modDesc.GetPivotId(), modDesc.GetRadius(), modDesc.GetName(), 0.001f));
|
||||
x0_jointDescriptions.back().SetCollisionActorId(newId);
|
||||
|
||||
const u32 numSeps = u32(dist / modDesc.GetMaxSeparation());
|
||||
if (numSeps != 0) {
|
||||
x0_jointDescriptions.reserve(x0_jointDescriptions.capacity() + numSeps);
|
||||
const float pitch = dist / float(numSeps + 1);
|
||||
for (u32 i = 0; i < numSeps; ++i) {
|
||||
const float separation = pitch * float(i + 1);
|
||||
x0_jointDescriptions.push_back(CJointCollisionDescription::SphereSubdivideCollision(
|
||||
modDesc.GetPivotId(), modDesc.GetNextId(), modDesc.GetRadius(), separation,
|
||||
CJointCollisionDescription::EOrientationType::One, modDesc.GetName(), 0.001f));
|
||||
|
||||
const TUniqueId newId2 = mgr.AllocateUniqueId();
|
||||
auto* newAct2 = new CCollisionActor(newId2, area, x10_ownerId, active, modDesc.GetRadius(),
|
||||
modDesc.GetMass(), desc.GetName());
|
||||
if (modDesc.GetOrientationType() == CJointCollisionDescription::EOrientationType::Zero) {
|
||||
newAct2->SetTransform(zeus::CTransform::Translate(locXf.origin + separation * locXf.basis[1]));
|
||||
} else {
|
||||
const zeus::CVector3f delta = (locXf2.origin - locXf.origin).normalized();
|
||||
zeus::CVector3f upVector = locXf.basis[2];
|
||||
|
||||
if (zeus::close_enough(std::fabs(delta.dot(upVector)), 1.f)) {
|
||||
upVector = locXf.basis[1];
|
||||
}
|
||||
|
||||
const zeus::CTransform lookAt = zeus::lookAt(zeus::skZero3f, delta, upVector);
|
||||
newAct2->SetTransform(zeus::CTransform::Translate(lookAt.basis[1] * separation + locXf.origin));
|
||||
}
|
||||
|
||||
mgr.AddObject(newAct2);
|
||||
x0_jointDescriptions.back().SetCollisionActorId(newId2);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const TUniqueId newId = mgr.AllocateUniqueId();
|
||||
CCollisionActor* newAct;
|
||||
|
||||
if (modDesc.GetType() == CJointCollisionDescription::ECollisionType::Sphere) {
|
||||
newAct = new CCollisionActor(newId, area, x10_ownerId, active, modDesc.GetRadius(), modDesc.GetMass(),
|
||||
desc.GetName());
|
||||
} else if (modDesc.GetType() == CJointCollisionDescription::ECollisionType::OBB) {
|
||||
newAct = new CCollisionActor(newId, area, x10_ownerId, modDesc.GetBounds(), modDesc.GetPivotPoint(), active,
|
||||
modDesc.GetMass(), desc.GetName());
|
||||
} else {
|
||||
newAct = new CCollisionActor(newId, area, x10_ownerId, modDesc.GetBounds(), active, modDesc.GetMass(),
|
||||
desc.GetName());
|
||||
}
|
||||
|
||||
newAct->SetTransform(locXf);
|
||||
mgr.AddObject(newAct);
|
||||
x0_jointDescriptions.push_back(desc);
|
||||
x0_jointDescriptions.back().SetCollisionActorId(newId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,14 +138,13 @@ void CCollisionActorManager::SetActive(CStateManager& mgr, bool active) {
|
|||
const bool curActive = act->GetActive();
|
||||
if (curActive != active) {
|
||||
act->SetActive(active);
|
||||
}
|
||||
|
||||
if (active) {
|
||||
if (!active) {
|
||||
Update(0.f, mgr, EUpdateOptions::WorldSpace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCollisionActorManager::AddMaterial(CStateManager& mgr, const CMaterialList& list) {
|
||||
for (const CJointCollisionDescription& jDesc : x0_jointDescriptions) {
|
||||
|
|
|
@ -33,13 +33,13 @@ public:
|
|||
void Update(float dt, CStateManager& mgr, EUpdateOptions opts);
|
||||
void Destroy(CStateManager& mgr);
|
||||
void SetActive(CStateManager& mgr, bool active);
|
||||
bool GetActive() const { return x12_active; }
|
||||
[[nodiscard]] bool GetActive() const { return x12_active; }
|
||||
void AddMaterial(CStateManager& mgr, const CMaterialList& list);
|
||||
void SetMovable(CStateManager& mgr, bool movable);
|
||||
|
||||
u32 GetNumCollisionActors() const { return x0_jointDescriptions.size(); }
|
||||
[[nodiscard]] u32 GetNumCollisionActors() const { return x0_jointDescriptions.size(); }
|
||||
std::optional<zeus::CVector3f> GetDeviation(const CStateManager&, CSegId);
|
||||
const CJointCollisionDescription& GetCollisionDescFromIndex(u32 i) const { return x0_jointDescriptions[i]; }
|
||||
[[nodiscard]] const CJointCollisionDescription& GetCollisionDescFromIndex(u32 i) const { return x0_jointDescriptions[i]; }
|
||||
static zeus::CTransform GetWRLocatorTransform(const CAnimData& animData, CSegId id, const zeus::CTransform& worldXf,
|
||||
const zeus::CTransform& localXf);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue