1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-11-13 06:49:16 +00:00
re3/src/entities/Physical.h

178 lines
5.9 KiB
C
Raw Normal View History

2019-05-15 14:52:37 +00:00
#pragma once
#include "Lists.h"
2019-05-19 19:28:10 +00:00
#include "Timer.h"
2019-05-15 14:52:37 +00:00
#include "Entity.h"
enum {
PHYSICAL_MAX_COLLISIONRECORDS = 6
};
2019-07-08 19:37:47 +00:00
#define GRAVITY (0.008f)
class CTreadable;
2019-05-15 14:52:37 +00:00
class CPhysical : public CEntity
{
public:
// The not properly indented fields haven't been checked properly yet
2019-06-29 09:09:33 +00:00
int32 m_audioEntityId;
2020-05-22 12:27:16 +00:00
float m_phys_unused1;
2019-05-15 14:52:37 +00:00
uint32 m_nLastTimeCollided;
CVector m_vecMoveSpeed; // velocity
CVector m_vecTurnSpeed; // angular velocity
CVector m_vecMoveFriction;
CVector m_vecTurnFriction;
CVector m_vecMoveSpeedAvg;
CVector m_vecTurnSpeedAvg;
float m_fMass;
float m_fTurnMass; // moment of inertia
2020-04-12 22:02:11 +00:00
float m_fForceMultiplier;
2019-05-15 14:52:37 +00:00
float m_fAirResistance;
float m_fElasticity;
2019-06-19 16:35:51 +00:00
float m_fBuoyancy;
2019-05-15 14:52:37 +00:00
CVector m_vecCentreOfMass;
CEntryInfoList m_entryInfoList;
CPtrNode *m_movingListNode;
2020-05-22 12:27:16 +00:00
int8 m_phys_unused2;
2019-05-15 14:52:37 +00:00
uint8 m_nStaticFrames;
uint8 m_nCollisionRecords;
CEntity *m_aCollisionRecords[PHYSICAL_MAX_COLLISIONRECORDS];
float m_fDistanceTravelled;
// damaged piece
2020-05-22 12:27:16 +00:00
float m_fDamageImpulse;
2019-05-19 19:28:10 +00:00
CEntity *m_pDamageEntity;
CVector m_vecDamageNormal;
int16 m_nDamagePieceType;
2019-05-15 14:52:37 +00:00
2019-06-02 17:33:41 +00:00
uint8 bIsHeavy : 1;
2019-05-15 14:52:37 +00:00
uint8 bAffectedByGravity : 1;
uint8 bInfiniteMass : 1;
2020-05-22 12:27:16 +00:00
uint8 m_phy_flagA08 : 1;
2019-06-02 17:33:41 +00:00
uint8 bIsInWater : 1;
uint8 m_phy_flagA20 : 1; // unused
2019-07-29 17:18:03 +00:00
uint8 bHitByTrain : 1;
2020-04-30 15:58:15 +00:00
uint8 bSkipLineCol : 1;
2019-05-15 14:52:37 +00:00
2020-05-22 12:27:16 +00:00
uint8 bIsFrozen : 1;
uint8 bDontLoadCollision : 1;
uint8 m_bIsVehicleBeingShifted : 1; // wrong name - also used on but never set for peds
uint8 bJustCheckCollision : 1; // just see if there is a collision
2019-07-09 07:57:44 +00:00
uint8 m_nSurfaceTouched;
2019-10-03 01:02:02 +00:00
int8 m_nZoneLevel;
2019-05-15 14:52:37 +00:00
CPhysical(void);
~CPhysical(void);
2019-05-15 14:52:37 +00:00
// from CEntity
void Add(void);
void Remove(void);
CRect GetBoundRect(void);
void ProcessControl(void);
void ProcessShift(void);
void ProcessCollision(void);
2019-07-09 07:57:44 +00:00
virtual int32 ProcessEntityCollision(CEntity *ent, CColPoint *colpoints);
2019-05-15 14:52:37 +00:00
void RemoveAndAdd(void);
void AddToMovingList(void);
void RemoveFromMovingList(void);
2019-05-18 10:39:39 +00:00
void SetDamagedPieceRecord(uint16 piece, float impulse, CEntity *entity, CVector dir);
void AddCollisionRecord(CEntity *ent);
void AddCollisionRecord_Treadable(CEntity *ent);
bool GetHasCollidedWith(CEntity *ent);
void RemoveRefsToEntity(CEntity *ent);
2019-07-07 09:13:12 +00:00
static void PlacePhysicalRelativeToOtherPhysical(CPhysical *other, CPhysical *phys, CVector localPos);
2019-05-15 14:52:37 +00:00
// get speed of point p relative to entity center
CVector GetSpeed(const CVector &r);
CVector GetSpeed(void) { return GetSpeed(CVector(0.0f, 0.0f, 0.0f)); }
float GetMass(const CVector &pos, const CVector &dir) {
return 1.0f / (CrossProduct(pos, dir).MagnitudeSqr()/m_fTurnMass +
1.0f/m_fMass);
}
2020-05-22 12:27:16 +00:00
float GetMassTweak(const CVector &pos, const CVector &dir, float t) {
2019-05-15 14:52:37 +00:00
return 1.0f / (CrossProduct(pos, dir).MagnitudeSqr()/(m_fTurnMass*t) +
1.0f/(m_fMass*t));
}
void UnsetIsInSafePosition(void) {
m_vecMoveSpeed *= -1.0f;
m_vecTurnSpeed *= -1.0f;
ApplyTurnSpeed();
ApplyMoveSpeed();
m_vecMoveSpeed *= -1.0f;
m_vecTurnSpeed *= -1.0f;
bIsInSafePosition = false;
}
2019-07-07 09:13:12 +00:00
const CVector &GetMoveSpeed() { return m_vecMoveSpeed; }
2019-07-08 19:37:47 +00:00
void SetMoveSpeed(float x, float y, float z) {
m_vecMoveSpeed.x = x;
m_vecMoveSpeed.y = y;
m_vecMoveSpeed.z = z;
}
2019-08-06 21:32:19 +00:00
void SetMoveSpeed(const CVector& speed) {
m_vecMoveSpeed = speed;
}
2020-05-11 18:04:35 +00:00
void AddToMoveSpeed(float x, float y, float z) {
m_vecMoveSpeed.x += x;
m_vecMoveSpeed.y += y;
m_vecMoveSpeed.z += z;
}
void AddToMoveSpeed(const CVector& addition) {
m_vecMoveSpeed += addition;
}
void AddToMoveSpeed(const CVector2D& addition) {
m_vecMoveSpeed += CVector(addition.x, addition.y, 0.0f);
}
2019-07-07 09:13:12 +00:00
const CVector &GetTurnSpeed() { return m_vecTurnSpeed; }
2019-07-08 19:37:47 +00:00
void SetTurnSpeed(float x, float y, float z) {
m_vecTurnSpeed.x = x;
m_vecTurnSpeed.y = y;
m_vecTurnSpeed.z = z;
}
const CVector &GetCenterOfMass() { return m_vecCentreOfMass; }
void SetCenterOfMass(float x, float y, float z) {
m_vecCentreOfMass.x = x;
m_vecCentreOfMass.y = y;
m_vecCentreOfMass.z = z;
}
2019-05-15 14:52:37 +00:00
void ApplyMoveSpeed(void);
void ApplyTurnSpeed(void);
// Force actually means Impulse here
void ApplyMoveForce(float jx, float jy, float jz);
void ApplyMoveForce(const CVector &j) { ApplyMoveForce(j.x, j.y, j.z); }
2019-07-05 12:23:39 +00:00
// j(x,y,z) is direction of force, p(x,y,z) is point relative to model center where force is applied
void ApplyTurnForce(float jx, float jy, float jz, float px, float py, float pz);
// j is direction of force, p is point relative to model center where force is applied
2019-05-15 14:52:37 +00:00
void ApplyTurnForce(const CVector &j, const CVector &p) { ApplyTurnForce(j.x, j.y, j.z, p.x, p.y, p.z); }
void ApplyFrictionMoveForce(float jx, float jy, float jz);
void ApplyFrictionMoveForce(const CVector &j) { ApplyFrictionMoveForce(j.x, j.y, j.z); }
void ApplyFrictionTurnForce(float jx, float jy, float jz, float rx, float ry, float rz);
void ApplyFrictionTurnForce(const CVector &j, const CVector &p) { ApplyFrictionTurnForce(j.x, j.y, j.z, p.x, p.y, p.z); }
2019-07-07 09:13:12 +00:00
// springRatio: 1.0 fully extended, 0.0 fully compressed
bool ApplySpringCollision(float springConst, CVector &springDir, CVector &point, float springRatio, float bias);
2020-05-22 12:27:16 +00:00
bool ApplySpringCollisionAlt(float springConst, CVector &springDir, CVector &point, float springRatio, float bias, CVector &forceDir);
2019-07-07 09:13:12 +00:00
bool ApplySpringDampening(float damping, CVector &springDir, CVector &point, CVector &speed);
2019-05-15 14:52:37 +00:00
void ApplyGravity(void);
void ApplyFriction(void);
void ApplyAirResistance(void);
bool ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, float &impulseB);
2020-05-22 12:27:16 +00:00
bool ApplyCollision(CColPoint &colpoint, float &impulse);
2019-05-15 14:52:37 +00:00
bool ApplyCollisionAlt(CEntity *B, CColPoint &colpoint, float &impulse, CVector &moveSpeed, CVector &turnSpeed);
bool ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint);
bool ApplyFriction(float adhesiveLimit, CColPoint &colpoint);
bool ProcessShiftSectorList(CPtrList *ptrlists);
2019-05-18 10:39:39 +00:00
bool ProcessCollisionSectorList_SimpleCar(CPtrList *lists);
2019-05-19 19:28:10 +00:00
bool ProcessCollisionSectorList(CPtrList *lists);
bool CheckCollision(void);
bool CheckCollision_SimpleCar(void);
2019-05-15 14:52:37 +00:00
};