CPhysical fixes and cleanup

This commit is contained in:
aap 2021-08-02 20:02:35 +02:00
parent cb5586e658
commit 09748d094a
2 changed files with 26 additions and 27 deletions

View File

@ -216,9 +216,9 @@ CPhysical::RemoveAndAdd(void)
CRect CRect
CPhysical::GetBoundRect(void) CPhysical::GetBoundRect(void)
{ {
CVUVECTOR center; CVector center;
float radius; float radius;
GetBoundCentre(center); center = GetBoundCentre();
radius = GetBoundRadius(); radius = GetBoundRadius();
return CRect(center.x-radius, center.y-radius, center.x+radius, center.y+radius); return CRect(center.x-radius, center.y-radius, center.x+radius, center.y+radius);
} }
@ -1114,11 +1114,12 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
skipShift = false; skipShift = false;
if(B->IsBuilding() || if(B->IsBuilding() ||
B->IsObject() && B->bInfiniteMass) B->IsObject() && B->bInfiniteMass ||
A->IsPed() && B->IsObject() && B->GetIsStatic() && !Bobj->bHasBeenDamaged)
canshift = true; canshift = true;
else else
canshift = A->IsPed() && canshift = false;
B->IsObject() && B->GetIsStatic() && !Bobj->bHasBeenDamaged;
if(B == A || if(B == A ||
B->m_scanCode == CWorld::GetCurrentScanCode() || B->m_scanCode == CWorld::GetCurrentScanCode() ||
!B->bUsesCollision || !B->bUsesCollision ||
@ -1147,7 +1148,7 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
Aobj->m_pCollidingEntity = nil; Aobj->m_pCollidingEntity = nil;
}else if(Aobj->m_pCollidingEntity != B){ }else if(Aobj->m_pCollidingEntity != B){
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(A->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetColModel(A->GetModelIndex())->boundingBox.GetSize();
size = A->GetMatrix() * size; size = A->GetMatrix() * size;
if(size.z < B->GetPosition().z || if(size.z < B->GetPosition().z ||
(Invert(B->GetMatrix(), inv) * size).z < 0.0f){ (Invert(B->GetMatrix(), inv) * size).z < 0.0f){
@ -1165,7 +1166,7 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
Bobj->m_pCollidingEntity = nil; Bobj->m_pCollidingEntity = nil;
}else if(Bobj->m_pCollidingEntity != A){ }else if(Bobj->m_pCollidingEntity != A){
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(B->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetColModel(B->GetModelIndex())->boundingBox.GetSize();
size = B->GetMatrix() * size; size = B->GetMatrix() * size;
if(size.z < A->GetPosition().z || if(size.z < A->GetPosition().z ||
(Invert(A->GetMatrix(), inv) * size).z < 0.0f) (Invert(A->GetMatrix(), inv) * size).z < 0.0f)
@ -1177,9 +1178,10 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
else if(A->IsPed() && IsBodyPart(B->GetModelIndex())) else if(A->IsPed() && IsBodyPart(B->GetModelIndex()))
skipShift = true; skipShift = true;
else if(A->IsPed() && ((CPed*)A)->m_pCollidingEntity == B || else if(A->IsPed() && ((CPed*)A)->m_pCollidingEntity == B ||
B->IsPed() && ((CPed*)B)->m_pCollidingEntity == A || B->IsPed() && ((CPed*)B)->m_pCollidingEntity == A)
A->GetModelIndex() == MI_RCBANDIT && B->IsVehicle() || skipShift = true;
B->GetModelIndex() == MI_RCBANDIT && (A->IsPed() || A->IsVehicle())) else if(A->GetModelIndex() == MI_RCBANDIT && B->IsVehicle() ||
B->GetModelIndex() == MI_RCBANDIT && (A->IsPed() || A->IsVehicle()))
skipShift = true; skipShift = true;
if(skipShift) if(skipShift)
@ -1441,18 +1443,17 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
bool isTouching = true; bool isTouching = true;
if(B == A || if(B == A ||
B->m_scanCode == CWorld::GetCurrentScanCode() || B->m_scanCode == CWorld::GetCurrentScanCode() ||
!B->bUsesCollision || !B->bUsesCollision)
!(isTouching = B->GetIsTouching(center, radius))){ continue;
if(!isTouching){ if(!B->GetIsTouching(center, radius)){
if(A->IsObject() && Aobj->m_pCollidingEntity == B) if(A->IsObject() && Aobj->m_pCollidingEntity == B)
Aobj->m_pCollidingEntity = nil; Aobj->m_pCollidingEntity = nil;
else if(B->IsObject() && Bobj->m_pCollidingEntity == A) else if(B->IsObject() && Bobj->m_pCollidingEntity == A)
Bobj->m_pCollidingEntity = nil; Bobj->m_pCollidingEntity = nil;
else if(A->IsPed() && Aped->m_pCollidingEntity == B) else if(A->IsPed() && Aped->m_pCollidingEntity == B)
Aped->m_pCollidingEntity = nil; Aped->m_pCollidingEntity = nil;
else if(B->IsPed() && Bped->m_pCollidingEntity == A) else if(B->IsPed() && Bped->m_pCollidingEntity == A)
Bped->m_pCollidingEntity = nil; Bped->m_pCollidingEntity = nil;
}
continue; continue;
} }
@ -1484,7 +1485,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
skipCollision = true; skipCollision = true;
else{ else{
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(A->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetColModel(A->GetModelIndex())->boundingBox.GetSize();
size = A->GetMatrix() * size; size = A->GetMatrix() * size;
if(size.z < B->GetPosition().z || if(size.z < B->GetPosition().z ||
(Invert(B->GetMatrix(), inv) * size).z < 0.0f){ (Invert(B->GetMatrix(), inv) * size).z < 0.0f){
@ -1503,7 +1504,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
skipCollision = true; skipCollision = true;
else{ else{
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(B->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetColModel(B->GetModelIndex())->boundingBox.GetSize();
size = B->GetMatrix() * size; size = B->GetMatrix() * size;
if(size.z < A->GetPosition().z || if(size.z < A->GetPosition().z ||
(Invert(A->GetMatrix(), inv) * size).z < 0.0f){ (Invert(A->GetMatrix(), inv) * size).z < 0.0f){
@ -1849,7 +1850,7 @@ CPhysical::ProcessShift(void)
} }
// x is the number of units (m) we would like to step // x is the number of units (m) we would like to step
#define NUMSTEPS(x) ceil(Sqrt(distSq) * (1.0f/(x))) #define NUMSTEPS(x) Ceil(Sqrt(distSq) * (1.0f/(x)))
void void
CPhysical::ProcessCollision(void) CPhysical::ProcessCollision(void)

View File

@ -15,8 +15,6 @@ class CTreadable;
class CPhysical : public CEntity class CPhysical : public CEntity
{ {
public: public:
// The not properly indented fields haven't been checked properly yet
int32 m_audioEntityId; int32 m_audioEntityId;
float m_phys_unused1; float m_phys_unused1;
CTreadable *m_treadable[2]; // car and ped CTreadable *m_treadable[2]; // car and ped