mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-02 17:57:59 +03:00
Simplify footprint code
This commit is contained in:
parent
a3d063ec74
commit
030e096420
4 changed files with 50 additions and 55 deletions
|
@ -13,7 +13,7 @@ namespace Footprints {
|
|||
|
||||
std::deque<FOOTPRINT_STRUCT> footprints = std::deque<FOOTPRINT_STRUCT>();
|
||||
|
||||
bool CheckFootOnFloor(ITEM_INFO const & item, int mesh, PHD_3DPOS& outFootprintPosition)
|
||||
bool CheckFootOnFloor(ITEM_INFO const & item, int mesh, Vector3& outFootprintPosition)
|
||||
{
|
||||
int x = item.pos.xPos;
|
||||
int y = item.pos.yPos;
|
||||
|
@ -37,10 +37,9 @@ namespace Footprints {
|
|||
GetLaraJointPosition(&pos, mesh);
|
||||
int height = GetFloorHeight(floor, pos.x, pos.y - STEP_SIZE, pos.z);
|
||||
|
||||
outFootprintPosition.xPos = pos.x;
|
||||
outFootprintPosition.zPos = pos.z;
|
||||
outFootprintPosition.yPos = height - 8;
|
||||
outFootprintPosition.yRot = item.pos.yRot + ANGLE(180);
|
||||
outFootprintPosition.x = pos.x;
|
||||
outFootprintPosition.y = height - 8;
|
||||
outFootprintPosition.z = pos.z;
|
||||
|
||||
return abs(pos.y - height) < 32;
|
||||
}
|
||||
|
@ -55,22 +54,22 @@ namespace Footprints {
|
|||
for (auto i = footprints.begin(); i != footprints.end(); i++)
|
||||
{
|
||||
FOOTPRINT_STRUCT& footprint = *i;
|
||||
footprint.life--;
|
||||
footprint.Life--;
|
||||
|
||||
if (footprint.life <= 0)
|
||||
if (footprint.Life <= 0)
|
||||
{
|
||||
numInvalidFootprints++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (footprint.life > footprint.lifeStartFading)
|
||||
if (footprint.Life > footprint.LifeStartFading)
|
||||
{
|
||||
footprint.opacity = footprint.startOpacity;
|
||||
footprint.Opacity = footprint.StartOpacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
float opacity = lerp(0, footprint.startOpacity, fmax(0, fmin(1, footprint.life / (float)footprint.lifeStartFading)));
|
||||
footprint.opacity = opacity;
|
||||
float opacity = lerp(0, footprint.StartOpacity, fmax(0, fmin(1, footprint.Life / (float)footprint.LifeStartFading)));
|
||||
footprint.Opacity = opacity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,19 +10,20 @@ namespace Footprints {
|
|||
|
||||
struct FOOTPRINT_STRUCT
|
||||
{
|
||||
PHD_3DPOS pos;
|
||||
int foot;
|
||||
int life;
|
||||
int lifeStartFading;
|
||||
byte startOpacity;
|
||||
byte opacity;
|
||||
bool active;
|
||||
Vector3 Position;
|
||||
Vector3 Rotation;
|
||||
bool RightFoot;
|
||||
int Life;
|
||||
int LifeStartFading;
|
||||
float StartOpacity;
|
||||
float Opacity;
|
||||
bool Active;
|
||||
};
|
||||
|
||||
extern std::deque<FOOTPRINT_STRUCT> footprints;
|
||||
constexpr int FOOT_HEIGHT_OFFSET = 64;
|
||||
|
||||
bool CheckFootOnFloor(ITEM_INFO const & item, int mesh, PHD_3DPOS& outFootprintPosition);
|
||||
bool CheckFootOnFloor(ITEM_INFO const & item, int mesh, Vector3& outFootprintPosition);
|
||||
void UpdateFootprints();
|
||||
|
||||
}}}
|
||||
|
|
|
@ -190,45 +190,40 @@ void AddFootprint(ITEM_INFO* item)
|
|||
if (fx != sound_effects::SFX_TR4_LARA_FEET)
|
||||
SoundEffect(fx, &item->pos, 0);
|
||||
|
||||
FOOTPRINT_STRUCT footprint;
|
||||
|
||||
auto plane = floor->FloorCollision.Planes[floor->SectorPlane(position.x, position.z)];
|
||||
|
||||
auto yRot = item->pos.yRot;
|
||||
auto c = phd_cos(yRot);
|
||||
auto s = phd_sin(yRot);
|
||||
auto xRot = FROM_RAD(plane.x * s + plane.y * c);
|
||||
auto zRot = FROM_RAD(plane.y * s - plane.x * c);
|
||||
auto c = phd_cos(item->pos.yRot + ANGLE(180));
|
||||
auto s = phd_sin(item->pos.yRot + ANGLE(180));
|
||||
auto yRot = TO_RAD(item->pos.yRot);
|
||||
auto xRot = plane.x * s + plane.y * c;
|
||||
auto zRot = plane.y * s - plane.x * c;
|
||||
|
||||
auto footprintPosition = PHD_3DPOS(position.x, position.y, position.z, xRot, yRot, zRot);
|
||||
FOOTPRINT_STRUCT footprint = {};
|
||||
auto preciseFootPosition = Vector3();
|
||||
|
||||
if (CheckFootOnFloor(*item, LM_LFOOT, footprintPosition))
|
||||
footprint.Rotation = Vector3(xRot, yRot, zRot);
|
||||
footprint.LifeStartFading = 30 * 10;
|
||||
footprint.StartOpacity = 0.25f;
|
||||
footprint.Life = 30 * 20;
|
||||
footprint.Active = true;
|
||||
|
||||
if (CheckFootOnFloor(*item, LM_LFOOT, preciseFootPosition))
|
||||
{
|
||||
if (footprints.size() >= MAX_FOOTPRINTS)
|
||||
footprints.pop_back();
|
||||
|
||||
memset(&footprint, 0, sizeof(FOOTPRINT_STRUCT));
|
||||
footprint.pos = footprintPosition;
|
||||
footprint.foot = 0;
|
||||
footprint.lifeStartFading = 30 * 10;
|
||||
footprint.startOpacity = 64;
|
||||
footprint.life = 30 * 20;
|
||||
footprint.active = true;
|
||||
footprint.Position = preciseFootPosition;
|
||||
footprint.RightFoot = false;
|
||||
footprints.push_front(footprint);
|
||||
}
|
||||
|
||||
if (CheckFootOnFloor(*item, LM_RFOOT, footprintPosition))
|
||||
if (CheckFootOnFloor(*item, LM_RFOOT, preciseFootPosition))
|
||||
{
|
||||
if (footprints.size() >= MAX_FOOTPRINTS)
|
||||
footprints.pop_back();
|
||||
|
||||
memset(&footprint, 0, sizeof(FOOTPRINT_STRUCT));
|
||||
footprint.pos = footprintPosition;
|
||||
footprint.foot = 1;
|
||||
footprint.lifeStartFading = 30*10;
|
||||
footprint.startOpacity = 64;
|
||||
footprint.life = 30 * 20;
|
||||
footprint.active = true;
|
||||
footprint.Position = preciseFootPosition;
|
||||
footprint.RightFoot = true;
|
||||
footprints.push_front(footprint);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -607,24 +607,24 @@ namespace TEN::Renderer
|
|||
for (auto i = footprints.begin(); i != footprints.end(); i++)
|
||||
{
|
||||
FOOTPRINT_STRUCT& footprint = *i;
|
||||
auto spriteIndex = Objects[ID_MISC_SPRITES].meshIndex + 1 + footprint.foot;
|
||||
auto spriteIndex = Objects[ID_MISC_SPRITES].meshIndex + 1 + (int)footprint.RightFoot;
|
||||
|
||||
if (footprint.active && g_Level.Sprites.size() > spriteIndex)
|
||||
if (footprint.Active && g_Level.Sprites.size() > spriteIndex)
|
||||
{
|
||||
Matrix rot = Matrix::CreateFromYawPitchRoll(TO_RAD(footprint.pos.yRot), TO_RAD(footprint.pos.xRot), TO_RAD(footprint.pos.zRot));
|
||||
Vector3 p1 = Vector3(-64, 0, -64);
|
||||
Vector3 p2 = Vector3(64, 0, -64);
|
||||
Vector3 p3 = Vector3(64, 0, 64);
|
||||
Vector3 p4 = Vector3(-64, 0, 64);
|
||||
Matrix rot = Matrix::CreateFromYawPitchRoll(footprint.Rotation.y, footprint.Rotation.x, footprint.Rotation.z);
|
||||
Vector3 p1 = Vector3( 64, 0, 64);
|
||||
Vector3 p2 = Vector3(-64, 0, 64);
|
||||
Vector3 p3 = Vector3(-64, 0, -64);
|
||||
Vector3 p4 = Vector3( 64, 0, -64);
|
||||
p1 = XMVector3Transform(p1, rot);
|
||||
p2 = XMVector3Transform(p2, rot);
|
||||
p3 = XMVector3Transform(p3, rot);
|
||||
p4 = XMVector3Transform(p4, rot);
|
||||
p1 += Vector3(footprint.pos.xPos, footprint.pos.yPos, footprint.pos.zPos);
|
||||
p2 += Vector3(footprint.pos.xPos, footprint.pos.yPos, footprint.pos.zPos);
|
||||
p3 += Vector3(footprint.pos.xPos, footprint.pos.yPos, footprint.pos.zPos);
|
||||
p4 += Vector3(footprint.pos.xPos, footprint.pos.yPos, footprint.pos.zPos);
|
||||
addSprite3D(&m_sprites[spriteIndex], p1, p2, p3, p4, Vector4(footprint.opacity / 255.0f, footprint.opacity / 255.0f, footprint.opacity / 255.0f, footprint.opacity / 255.0f), 0, 1, {1,1}, BLENDMODE_SUBTRACTIVE, view);
|
||||
p1 += Vector3(footprint.Position.x, footprint.Position.y, footprint.Position.z);
|
||||
p2 += Vector3(footprint.Position.x, footprint.Position.y, footprint.Position.z);
|
||||
p3 += Vector3(footprint.Position.x, footprint.Position.y, footprint.Position.z);
|
||||
p4 += Vector3(footprint.Position.x, footprint.Position.y, footprint.Position.z);
|
||||
addSprite3D(&m_sprites[spriteIndex], p1, p2, p3, p4, Vector4(footprint.Opacity), 0, 1, {1,1}, BLENDMODE_SUBTRACTIVE, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue