1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-11-05 23:25:55 +00:00
re3/src/vehicles/Door.cpp

171 lines
2.9 KiB
C++
Raw Normal View History

2019-07-07 16:36:55 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
2019-07-07 16:36:55 +00:00
#include "Vehicle.h"
#include "Door.h"
CDoor::CDoor(void)
{
memset(this, 0, sizeof(*this));
}
void
CDoor::Open(float ratio)
{
float open;
m_fPrevAngle = m_fAngle;
open = RetAngleWhenOpen();
if(ratio < 1.0f){
m_fAngle = open*ratio;
if(m_fAngle == 0.0f)
m_fAngVel = 0.0f;
}else{
m_nDoorState = DOORST_OPEN;
m_fAngle = open;
}
}
void
CDoor::Process(CVehicle *vehicle)
{
static CVector vecOffset(1.0f, 0.0f, 0.0f);
CVector speed = vehicle->GetSpeed(vecOffset);
CVector vecSpeedDiff = speed - m_vecSpeed;
vecSpeedDiff = Multiply3x3(vecSpeedDiff, vehicle->GetMatrix());
// air resistance
float fSpeedDiff = 0.0f; // uninitialized in game
switch(m_nAxis){
case 0: // x-axis
if(m_nDirn)
fSpeedDiff = vecSpeedDiff.y + vecSpeedDiff.z;
else
fSpeedDiff = -(vecSpeedDiff.y + vecSpeedDiff.z);
break;
// we don't support y axis apparently?
case 2: // z-axis
if(m_nDirn)
2020-02-22 22:42:10 +00:00
fSpeedDiff = -(vecSpeedDiff.y + vecSpeedDiff.x);
2019-07-07 16:36:55 +00:00
else
2020-02-22 22:42:10 +00:00
fSpeedDiff = vecSpeedDiff.y - vecSpeedDiff.x;
2019-07-07 16:36:55 +00:00
break;
}
fSpeedDiff = clamp(fSpeedDiff, -0.2f, 0.2f);
2019-07-10 15:18:26 +00:00
if(Abs(fSpeedDiff) > 0.002f)
2019-07-07 16:36:55 +00:00
m_fAngVel += fSpeedDiff;
m_fAngVel *= 0.945f;
m_fAngVel = clamp(m_fAngVel, -0.3f, 0.3f);
m_fAngle += m_fAngVel;
m_nDoorState = DOORST_SWINGING;
if(m_fAngle > m_fMaxAngle){
m_fAngle = m_fMaxAngle;
m_fAngVel *= -0.8f;
m_nDoorState = DOORST_OPEN;
}
if(m_fAngle < m_fMinAngle){
m_fAngle = m_fMinAngle;
m_fAngVel *= -0.8f;
m_nDoorState = DOORST_CLOSED;
}
m_vecSpeed = speed;
}
float
CDoor::RetAngleWhenClosed(void)
{
2019-07-10 15:18:26 +00:00
if(Abs(m_fMaxAngle) < Abs(m_fMinAngle))
2019-07-07 16:36:55 +00:00
return m_fMaxAngle;
else
return m_fMinAngle;
}
float
CDoor::RetAngleWhenOpen(void)
{
2019-07-10 15:18:26 +00:00
if(Abs(m_fMaxAngle) < Abs(m_fMinAngle))
2019-07-07 16:36:55 +00:00
return m_fMinAngle;
else
return m_fMaxAngle;
}
float
CDoor::GetAngleOpenRatio(void)
{
float open = RetAngleWhenOpen();
if(open == 0.0f)
return 0.0f;
return m_fAngle/open;
}
bool
CDoor::IsFullyOpen(void)
{
// why -0.5? that's around 28 deg less than fully open
2019-07-10 15:18:26 +00:00
if(Abs(m_fAngle) < Abs(RetAngleWhenOpen()) - 0.5f)
2019-07-07 16:36:55 +00:00
return false;
return true;
}
bool
CDoor::IsClosed(void)
{
return m_fAngle == RetAngleWhenClosed();
}
2019-07-29 17:18:03 +00:00
CTrainDoor::CTrainDoor(void)
{
memset(this, 0, sizeof(*this));
}
void
CTrainDoor::Open(float ratio)
{
float open;
m_fPrevPosn = m_fPosn;
open = RetTranslationWhenOpen();
if(ratio < 1.0f){
m_fPosn = open*ratio;
}else{
m_nDoorState = DOORST_OPEN;
m_fPosn = open;
}
}
float
CTrainDoor::RetTranslationWhenClosed(void)
{
if(Abs(m_fClosedPosn) < Abs(m_fOpenPosn))
return m_fClosedPosn;
else
return m_fOpenPosn;
}
float
CTrainDoor::RetTranslationWhenOpen(void)
{
if(Abs(m_fClosedPosn) < Abs(m_fOpenPosn))
return m_fOpenPosn;
else
return m_fClosedPosn;
}
bool
CTrainDoor::IsFullyOpen(void)
{
// 0.5f again...
if(Abs(m_fPosn) < Abs(RetTranslationWhenOpen()) - 0.5f)
return false;
return true;
}
bool
CTrainDoor::IsClosed(void)
{
return m_fPosn == RetTranslationWhenClosed();
}