summaryrefslogtreecommitdiffstats
path: root/src/entities/Physical.cpp
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-07-07 11:13:12 +0200
committeraap <aap@papnet.eu>2019-07-07 11:13:12 +0200
commit219a65b81a1141d6475fc48bdc6251bd20e44a70 (patch)
tree46cd85dd7b14ab85d23b0b39ffda41e08c1416a7 /src/entities/Physical.cpp
parentmade code use TimeStepIn(Milli)Seconds; purged unnecessary inlines (diff)
downloadre3-219a65b81a1141d6475fc48bdc6251bd20e44a70.tar
re3-219a65b81a1141d6475fc48bdc6251bd20e44a70.tar.gz
re3-219a65b81a1141d6475fc48bdc6251bd20e44a70.tar.bz2
re3-219a65b81a1141d6475fc48bdc6251bd20e44a70.tar.lz
re3-219a65b81a1141d6475fc48bdc6251bd20e44a70.tar.xz
re3-219a65b81a1141d6475fc48bdc6251bd20e44a70.tar.zst
re3-219a65b81a1141d6475fc48bdc6251bd20e44a70.zip
Diffstat (limited to '')
-rw-r--r--src/entities/Physical.cpp55
1 files changed, 48 insertions, 7 deletions
diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp
index b7ca1904..600e5dca 100644
--- a/src/entities/Physical.cpp
+++ b/src/entities/Physical.cpp
@@ -304,6 +304,22 @@ CPhysical::RemoveRefsToEntity(CEntity *ent)
}
}
+void
+CPhysical::PlacePhysicalRelativeToOtherPhysical(CPhysical *other, CPhysical *phys, CVector localPos)
+{
+ CVector worldPos = other->GetMatrix() * localPos;
+ float step = 0.9f * CTimer::GetTimeStep();
+ CVector pos = other->m_vecMoveSpeed*step + worldPos;
+
+ CWorld::Remove(phys);
+ phys->GetMatrix() = other->GetMatrix();
+ phys->GetPosition() = pos;
+ phys->m_vecMoveSpeed = other->m_vecMoveSpeed;
+ phys->GetMatrix().UpdateRW();
+ phys->UpdateRwFrame();
+ CWorld::Add(phys);
+}
+
int32
CPhysical::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints)
{
@@ -434,15 +450,38 @@ CPhysical::ApplyFrictionTurnForce(float jx, float jy, float jz, float px, float
m_vecTurnFriction += turnimpulse*(1.0f/m_fTurnMass);
}
-void
-CPhysical::ApplySpringCollision(float f1, CVector &v, CVector &p, float f2, float f3)
+bool
+CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector &point, float springRatio, float bias)
{
- if(1.0f - f2 <= 0.0f)
- return;
+ float compression = 1.0f - springRatio;
+ if(compression > 0.0f){
+ float step = min(CTimer::GetTimeStep(), 3.0f);
+ float impulse = -0.008f*m_fMass*step * springConst * compression * bias*2.0f;
+ ApplyMoveForce(springDir*impulse);
+ ApplyTurnForce(springDir*impulse, point);
+ }
+ return true;
+}
+
+// What exactly is speed?
+bool
+CPhysical::ApplySpringDampening(float damping, CVector &springDir, CVector &point, CVector &speed)
+{
+ float speedA = DotProduct(speed, springDir);
+ float speedB = DotProduct(GetSpeed(point), springDir);
float step = min(CTimer::GetTimeStep(), 3.0f);
- float strength = -0.008f*m_fMass*2.0f*step * f1 * (1.0f-f2) * f3;
- ApplyMoveForce(v*strength);
- ApplyTurnForce(v*strength, p);
+ float impulse = -damping * (speedA + speedB)/2.0f * m_fMass * step * 0.53f;
+
+ // what is this?
+ float a = m_fTurnMass / ((point.MagnitudeSqr() + 1.0f) * 2.0f * m_fMass);
+ a = min(a, 1.0f);
+ float b = fabs(impulse / (speedB * m_fMass));
+ if(a < b)
+ impulse *= a/b;
+
+ ApplyMoveForce(springDir*impulse);
+ ApplyTurnForce(springDir*impulse, point);
+ return true;
}
void
@@ -1909,6 +1948,7 @@ STARTPATCHES
InjectHook(0x4970C0, &CPhysical::AddCollisionRecord_Treadable, PATCH_JUMP);
InjectHook(0x497240, &CPhysical::GetHasCollidedWith, PATCH_JUMP);
InjectHook(0x49F820, &CPhysical::RemoveRefsToEntity, PATCH_JUMP);
+ InjectHook(0x49F890, &CPhysical::PlacePhysicalRelativeToOtherPhysical, PATCH_JUMP);
#define F3 float, float, float
InjectHook(0x495B10, &CPhysical::ApplyMoveSpeed, PATCH_JUMP);
@@ -1918,6 +1958,7 @@ STARTPATCHES
InjectHook(0x495D90, (void (CPhysical::*)(F3))&CPhysical::ApplyFrictionMoveForce, PATCH_JUMP);
InjectHook(0x495E10, (void (CPhysical::*)(F3, F3))&CPhysical::ApplyFrictionTurnForce, PATCH_JUMP);
InjectHook(0x499890, &CPhysical::ApplySpringCollision, PATCH_JUMP);
+ InjectHook(0x499990, &CPhysical::ApplySpringDampening, PATCH_JUMP);
InjectHook(0x495B50, &CPhysical::ApplyGravity, PATCH_JUMP);
InjectHook(0x495B80, (void (CPhysical::*)(void))&CPhysical::ApplyFriction, PATCH_JUMP);
InjectHook(0x495C20, &CPhysical::ApplyAirResistance, PATCH_JUMP);