diff options
author | Sergeanur <s.anureev@yandex.ua> | 2021-05-10 01:34:21 +0200 |
---|---|---|
committer | Sergeanur <s.anureev@yandex.ua> | 2021-05-10 01:45:04 +0200 |
commit | 3dda658e4296c0b009f0670d6a9c6d2da2878569 (patch) | |
tree | 42fd6704034e4ebb218a0b23a5fe727f58822a07 | |
parent | Small Acos fix (diff) | |
download | re3-3dda658e4296c0b009f0670d6a9c6d2da2878569.tar re3-3dda658e4296c0b009f0670d6a9c6d2da2878569.tar.gz re3-3dda658e4296c0b009f0670d6a9c6d2da2878569.tar.bz2 re3-3dda658e4296c0b009f0670d6a9c6d2da2878569.tar.lz re3-3dda658e4296c0b009f0670d6a9c6d2da2878569.tar.xz re3-3dda658e4296c0b009f0670d6a9c6d2da2878569.tar.zst re3-3dda658e4296c0b009f0670d6a9c6d2da2878569.zip |
Diffstat (limited to '')
-rw-r--r-- | src/control/PathFind.cpp | 8 | ||||
-rw-r--r-- | src/control/Pickups.cpp | 18 | ||||
-rw-r--r-- | src/control/RoadBlocks.cpp | 6 | ||||
-rw-r--r-- | src/core/Camera.cpp | 4 | ||||
-rw-r--r-- | src/core/Placeable.h | 6 | ||||
-rw-r--r-- | src/core/World.cpp | 4 | ||||
-rw-r--r-- | src/entities/Entity.cpp | 22 | ||||
-rw-r--r-- | src/entities/Physical.cpp | 6 | ||||
-rw-r--r-- | src/math/Matrix.h | 16 | ||||
-rw-r--r-- | src/objects/Object.cpp | 12 | ||||
-rw-r--r-- | src/peds/Ped.cpp | 2 | ||||
-rw-r--r-- | src/vehicles/Plane.cpp | 6 |
12 files changed, 54 insertions, 56 deletions
diff --git a/src/control/PathFind.cpp b/src/control/PathFind.cpp index bf72199d..80d40b45 100644 --- a/src/control/PathFind.cpp +++ b/src/control/PathFind.cpp @@ -200,8 +200,8 @@ CPedPath::AddBlockade(CEntity *pEntity, CPedPathNode(*pathNodes)[40], CVector *p const float fBoundMaxY = boundingBox.max.y + 0.3f; const float fBoundMinY = boundingBox.min.y - 0.3f; const float fBoundMaxX = boundingBox.max.x + 0.3f; - const float fDistanceX = pPosition->x - pEntity->m_matrix.GetPosition().x; - const float fDistanceY = pPosition->y - pEntity->m_matrix.GetPosition().y; + const float fDistanceX = pPosition->x - pEntity->GetMatrix().GetPosition().x; + const float fDistanceY = pPosition->y - pEntity->GetMatrix().GetPosition().y; const float fBoundRadius = pEntity->GetBoundRadius(); CVector vecBoundCentre; pEntity->GetBoundCentre(vecBoundCentre); @@ -215,8 +215,8 @@ CPedPath::AddBlockade(CEntity *pEntity, CPedPathNode(*pathNodes)[40], CVector *p if (!pathNodes[x][y].bBlockade) { const float pointY = y * 0.7f + fDistanceY; CVector2D point(pointX, pointY); - if (fBoundMaxX > Abs(DotProduct2D(point, pEntity->m_matrix.GetRight()))) { - float fDotProduct = DotProduct2D(point, pEntity->m_matrix.GetForward()); + if (fBoundMaxX > Abs(DotProduct2D(point, pEntity->GetMatrix().GetRight()))) { + float fDotProduct = DotProduct2D(point, pEntity->GetMatrix().GetForward()); if (fBoundMaxY > fDotProduct && fBoundMinY < fDotProduct) pathNodes[x][y].bBlockade = true; } diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index 7bc88321..0428ddae 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -1008,8 +1008,7 @@ CPickups::DoPickUpEffects(CEntity *entity) entity->bDoNotRender = CTheScripts::IsPlayerOnAMission() || CDarkel::FrenzyOnGoing() || !CGame::nastyGame; if (!entity->bDoNotRender) { - float s = Sin((float)((CTimer::GetTimeInMilliseconds() + (uintptr)entity) & 0x7FF) * DEGTORAD(360.0f / 0x800)); - float modifiedSin = 0.3f * (s + 1.0f); + float modifiedSin = 0.3f * (Sin((float)((CTimer::GetTimeInMilliseconds() + (uintptr)entity) & 0x7FF) * DEGTORAD(360.0f / 0x800)) + 1.0f); #ifdef FIX_BUGS int16 colorId = 0; @@ -1149,7 +1148,20 @@ CPickups::DoPickUpEffects(CEntity *entity) if (model == MI_MINIGUN || model == MI_MINIGUN2) scale = 1.2f; - entity->GetMatrix().SetRotateZOnlyScaled((float)(CTimer::GetTimeInMilliseconds() & 0x7FF) * DEGTORAD(360.0f / 0x800), scale); + float angle = (float)(CTimer::GetTimeInMilliseconds() & 0x7FF) * DEGTORAD(360.0f / 0x800); + float c = Cos(angle) * scale; + float s = Sin(angle) * scale; + + // we know from SA they were setting each field manually like this + entity->GetMatrix().rx = c; + entity->GetMatrix().ry = s; + entity->GetMatrix().rz = 0.0f; + entity->GetMatrix().fx = -s; + entity->GetMatrix().fy = c; + entity->GetMatrix().fz = 0.0f; + entity->GetMatrix().ux = 0.0f; + entity->GetMatrix().uy = 0.0f; + entity->GetMatrix().uz = scale; if (entity->GetModelIndex() == MI_MINIGUN2) { CMatrix matrix1; diff --git a/src/control/RoadBlocks.cpp b/src/control/RoadBlocks.cpp index 4f714e80..46eee71f 100644 --- a/src/control/RoadBlocks.cpp +++ b/src/control/RoadBlocks.cpp @@ -64,7 +64,7 @@ CRoadBlocks::GenerateRoadBlockCopsForCar(CVehicle* pVehicle, int32 roadBlockType float fRadius = pVehicle->GetBoundRadius() / pPoliceColModel->boundingSphere.radius; for (int32 i = 0; i < 2; i++) { const int32 roadBlockIndex = i + 2 * roadBlockType; - CVector posForZ = pVehicle->m_matrix * (fRadius * vecRoadBlockOffets[roadBlockIndex]); + CVector posForZ = pVehicle->GetMatrix() * (fRadius * vecRoadBlockOffets[roadBlockIndex]); int32 modelInfoId = MI_COP; eCopType copType = COP_STREET; switch (pVehicle->GetModelIndex()) @@ -239,10 +239,10 @@ CRoadBlocks::CreateRoadBlockBetween2Points(CVector point1, CVector point2) pVehicle->SetStatus(STATUS_ABANDONED); // pVehicle->GetHeightAboveRoad(); // called but return value is ignored? tmp.GetPosition().z += fModelRadius - 0.6f; - pVehicle->m_matrix = tmp; + pVehicle->SetMatrix(tmp); pVehicle->PlaceOnRoadProperly(); pVehicle->SetIsStatic(false); - pVehicle->m_matrix.UpdateRW(); + pVehicle->GetMatrix().UpdateRW(); pVehicle->m_nDoorLock = CARLOCK_UNLOCKED; CCarCtrl::JoinCarWithRoadSystem(pVehicle); pVehicle->bIsLocked = false; diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index 5b3f9aa5..50ac2b5b 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -213,7 +213,7 @@ CCamera::Init(void) m_iModeToGoTo = CCam::MODE_FOLLOWPED; m_bJust_Switched = false; m_bUseTransitionBeta = false; - m_matrix.SetScale(1.0f); + GetMatrix().SetScale(1.0f); m_bTargetJustBeenOnTrain = false; m_bInitialNoNodeStaticsSet = false; m_uiLongestTimeInMill = 5000; @@ -4017,7 +4017,7 @@ CCamera::SetRwCamera(RwCamera *cam) void CCamera::CalculateDerivedValues(void) { - m_cameraMatrix = Invert(m_matrix); + m_cameraMatrix = Invert(GetMatrix()); float hfov = DEGTORAD(CDraw::GetScaledFOV()/2.0f); float c = Cos(hfov); diff --git a/src/core/Placeable.h b/src/core/Placeable.h index b0f9a15a..9c8c292a 100644 --- a/src/core/Placeable.h +++ b/src/core/Placeable.h @@ -2,12 +2,13 @@ class CPlaceable { +protected: + CMatrix m_matrix; + public: // disable allocation static void *operator new(size_t); - CMatrix m_matrix; - CPlaceable(void); const CVector &GetPosition(void) { return m_matrix.GetPosition(); } void SetPosition(float x, float y, float z) { @@ -20,6 +21,7 @@ public: CVector &GetForward(void) { return m_matrix.GetForward(); } CVector &GetUp(void) { return m_matrix.GetUp(); } CMatrix &GetMatrix(void) { return m_matrix; } + void SetMatrix(CMatrix &newMatrix) { m_matrix = newMatrix; } void SetTransform(RwMatrix *m) { m_matrix = CMatrix(m, false); } void SetHeading(float angle); void SetOrientation(float x, float y, float z){ diff --git a/src/core/World.cpp b/src/core/World.cpp index 2683a28d..1a693c5c 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -1486,7 +1486,7 @@ CWorld::CallOffChaseForAreaSectorListVehicles(CPtrList &list, float x1, float y1 CColModel *pColModel = pVehicle->GetColModel(); bool bInsideSphere = false; for(int32 i = 0; i < pColModel->numSpheres; i++) { - CVector pos = pVehicle->m_matrix * pColModel->spheres[i].center; + CVector pos = pVehicle->GetMatrix() * pColModel->spheres[i].center; float fRadius = pColModel->spheres[i].radius; if(pos.x + fRadius > x1 && pos.x - fRadius < x2 && pos.y + fRadius > y1 && pos.y - fRadius < y2) @@ -1803,7 +1803,7 @@ CWorld::RepositionOneObject(CEntity *pEntity) position.z = FindGroundZFor3DCoord(position.x, position.y, position.z + fHeight, nil) - fBoundingBoxMinZ; - pEntity->m_matrix.UpdateRW(); + pEntity->GetMatrix().UpdateRW(); pEntity->UpdateRwFrame(); } else if(IsLightThatNeedsRepositioning(modelId)) { CVector position = pEntity->GetMatrix().GetPosition(); diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index 6204b748..4653c173 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -121,9 +121,9 @@ CEntity::CreateRwObject(void) if(IsBuilding()) gBuildings++; if(RwObjectGetType(m_rwObject) == rpATOMIC) - m_matrix.AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject)), false); + GetMatrix().AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic *)m_rwObject)), false); else if(RwObjectGetType(m_rwObject) == rpCLUMP) - m_matrix.AttachRW(RwFrameGetMatrix(RpClumpGetFrame((RpClump*)m_rwObject)), false); + GetMatrix().AttachRW(RwFrameGetMatrix(RpClumpGetFrame((RpClump *)m_rwObject)), false); mi->AddRef(); } @@ -135,9 +135,9 @@ CEntity::AttachToRwObject(RwObject *obj) m_rwObject = obj; if(m_rwObject){ if(RwObjectGetType(m_rwObject) == rpATOMIC) - m_matrix.Attach(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject)), false); + GetMatrix().Attach(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic *)m_rwObject)), false); else if(RwObjectGetType(m_rwObject) == rpCLUMP) - m_matrix.Attach(RwFrameGetMatrix(RpClumpGetFrame((RpClump*)m_rwObject)), false); + GetMatrix().Attach(RwFrameGetMatrix(RpClumpGetFrame((RpClump *)m_rwObject)), false); CModelInfo::GetModelInfo(m_modelIndex)->AddRef(); } @@ -149,7 +149,7 @@ CEntity::DetachFromRwObject(void) if(m_rwObject) CModelInfo::GetModelInfo(m_modelIndex)->RemoveRef(); m_rwObject = nil; - m_matrix.Detach(); + GetMatrix().Detach(); } RpAtomic* @@ -177,7 +177,7 @@ CEntity::DeleteRwObject(void) { RwFrame *f; - m_matrix.Detach(); + GetMatrix().Detach(); if(m_rwObject){ if(RwObjectGetType(m_rwObject) == rpATOMIC){ f = RpAtomicGetFrame((RpAtomic*)m_rwObject); @@ -202,16 +202,16 @@ CEntity::GetBoundRect(void) CVector v; CColModel *col = CModelInfo::GetModelInfo(m_modelIndex)->GetColModel(); - rect.ContainPoint(m_matrix * col->boundingBox.min); - rect.ContainPoint(m_matrix * col->boundingBox.max); + rect.ContainPoint(GetMatrix() * col->boundingBox.min); + rect.ContainPoint(GetMatrix() * col->boundingBox.max); v = col->boundingBox.min; v.x = col->boundingBox.max.x; - rect.ContainPoint(m_matrix * v); + rect.ContainPoint(GetMatrix() * v); v = col->boundingBox.max; v.x = col->boundingBox.min.x; - rect.ContainPoint(m_matrix * v); + rect.ContainPoint(GetMatrix() * v); return rect; } @@ -227,7 +227,7 @@ CEntity::GetBoundCentre(void) void CEntity::GetBoundCentre(CVector &out) { - out = m_matrix * CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingSphere.center; + out = GetMatrix() * CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingSphere.center; } float diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index b897a6e2..03fbad03 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -462,7 +462,7 @@ CPhysical::ApplyMoveForce(float jx, float jy, float jz) void CPhysical::ApplyTurnForce(float jx, float jy, float jz, float px, float py, float pz) { - CVector com = Multiply3x3(m_matrix, m_vecCentreOfMass); + CVector com = Multiply3x3(GetMatrix(), m_vecCentreOfMass); CVector turnimpulse = CrossProduct(CVector(px, py, pz)-com, CVector(jx, jy, jz)); m_vecTurnSpeed += turnimpulse*(1.0f/m_fTurnMass); } @@ -477,7 +477,7 @@ CPhysical::ApplyFrictionMoveForce(float jx, float jy, float jz) void CPhysical::ApplyFrictionTurnForce(float jx, float jy, float jz, float px, float py, float pz) { - CVector com = Multiply3x3(m_matrix, m_vecCentreOfMass); + CVector com = Multiply3x3(GetMatrix(), m_vecCentreOfMass); CVector turnimpulse = CrossProduct(CVector(px, py, pz)-com, CVector(jx, jy, jz)); m_vecTurnFriction += turnimpulse*(1.0f/m_fTurnMass); } @@ -1023,7 +1023,7 @@ CPhysical::ApplyCollisionAlt(CEntity *B, CColPoint &colpoint, float &impulse, CV moveSpeed += vImpulse * (1.0f/m_fMass); // ApplyTurnForce - CVector com = Multiply3x3(m_matrix, m_vecCentreOfMass); + CVector com = Multiply3x3(GetMatrix(), m_vecCentreOfMass); CVector turnimpulse = CrossProduct(pointpos-com, vImpulse); turnSpeed += turnimpulse*(1.0f/m_fTurnMass); diff --git a/src/math/Matrix.h b/src/math/Matrix.h index 6da4c767..0adcf32c 100644 --- a/src/math/Matrix.h +++ b/src/math/Matrix.h @@ -92,22 +92,6 @@ public: void SetRotateXOnly(float angle); void SetRotateYOnly(float angle); void SetRotateZOnly(float angle); - void SetRotateZOnlyScaled(float angle, float scale) { - float c = Cos(angle); - float s = Sin(angle); - - rx = c * scale; - ry = s * scale; - rz = 0.0f; - - fx = -s * scale; - fy = c * scale; - fz = 0.0f; - - ux = 0.0f; - uy = 0.0f; - uz = scale; - } void SetRotateX(float angle); void SetRotateY(float angle); void SetRotateZ(float angle); diff --git a/src/objects/Object.cpp b/src/objects/Object.cpp index 0605f54f..0721725d 100644 --- a/src/objects/Object.cpp +++ b/src/objects/Object.cpp @@ -77,7 +77,7 @@ CObject::CObject(CDummyObject *dummy) if (dummy->m_rwObject) AttachToRwObject(dummy->m_rwObject); else - GetMatrix() = dummy->GetMatrix(); + SetMatrix(dummy->GetMatrix()); m_objectMatrix = dummy->GetMatrix(); dummy->DetachFromRwObject(); @@ -190,8 +190,8 @@ void CObject::Teleport(CVector vecPos) { CWorld::Remove(this); - m_matrix.GetPosition() = vecPos; - m_matrix.UpdateRW(); + GetMatrix().GetPosition() = vecPos; + GetMatrix().UpdateRW(); UpdateRwFrame(); CWorld::Add(this); } @@ -356,7 +356,7 @@ CObject::ObjectDamage(float amount) } #endif if ((amount * m_fCollisionDamageMultiplier > 150.0f || bBodyCastDamageEffect) && m_nCollisionDamageEffect) { - const CVector &vecPos = m_matrix.GetPosition(); + const CVector& vecPos = GetMatrix().GetPosition(); const float fDirectionZ = 0.0002f * amount; switch (m_nCollisionDamageEffect) { case DAMAGE_EFFECT_CHANGE_MODEL: @@ -653,7 +653,7 @@ CObject::ObjectDamage(float amount) CParticle::AddParticle(PARTICLE_CAR_DEBRIS, particlePos, particleDir, nil, fSize, particleColor, nRotationSpeed, 0, nCurFrame, 0); if ((i % 7) == 0) { static RwRGBA secondaryColor = { 0x9A, 0x99, 0x99, 0x3E }; - CParticle::AddParticle(PARTICLE_DEBRIS, particlePos, particleDir, nil, 0.3, secondaryColor, nRotationSpeed, 0, 0, 0); + CParticle::AddParticle(PARTICLE_DEBRIS, particlePos, particleDir, nil, 0.3f, secondaryColor, nRotationSpeed); } } PlayOneShotScriptObject(SCRIPT_SOUND_BOX_DESTROYED_2, vecPos); @@ -746,7 +746,7 @@ CObject::Init(void) m_pCollidingEntity = nil; CColPoint point; CEntity *outEntity = nil; - const CVector &vecPos = m_matrix.GetPosition(); + const CVector& vecPos = GetMatrix().GetPosition(); if (CWorld::ProcessVerticalLine(vecPos, vecPos.z - 10.0f, point, outEntity, true, false, false, false, false, false, nil)) m_pCurSurface = outEntity; else diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index ba09e8a4..342cba2d 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -7761,7 +7761,7 @@ CPed::SetPedPositionInCar(void) } else { m_fRotationCur = m_pMyVehicle->GetForward().Heading(); } - GetMatrix() = newMat; + SetMatrix(newMat); } void diff --git a/src/vehicles/Plane.cpp b/src/vehicles/Plane.cpp index 48f7b8c0..0b40ca7e 100644 --- a/src/vehicles/Plane.cpp +++ b/src/vehicles/Plane.cpp @@ -123,7 +123,7 @@ void CPlane::DeleteRwObject(void) { if(m_rwObject && RwObjectGetType(m_rwObject) == rpATOMIC){ - m_matrix.Detach(); + GetMatrix().Detach(); if(RwObjectGetType(m_rwObject) == rpATOMIC){ // useless check RwFrame *f = RpAtomicGetFrame((RpAtomic*)m_rwObject); RpAtomicDestroy((RpAtomic*)m_rwObject); @@ -567,13 +567,13 @@ CPlane::ProcessControl(void) m_rwObject = CModelInfo::GetModelInfo(mi->m_planeLodId)->CreateInstance(); POP_MEMID(); if(m_rwObject) - m_matrix.AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject))); + GetMatrix().AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject))); } } }else if(CStreaming::HasModelLoaded(GetModelIndex())){ if(m_rwObject && RwObjectGetType(m_rwObject) == rpATOMIC){ // Get rid of LOD model - m_matrix.Detach(); + GetMatrix().Detach(); if(m_rwObject){ // useless check if(RwObjectGetType(m_rwObject) == rpATOMIC){ // useless check RwFrame *f = RpAtomicGetFrame((RpAtomic*)m_rwObject); |