mirror of https://github.com/AxioDL/metaforce.git
Initial CSteeringBehaviors imps
This commit is contained in:
parent
a7e81073ae
commit
e6082d17f5
|
@ -1,4 +1,6 @@
|
||||||
#include "CSteeringBehaviors.hpp"
|
#include "CSteeringBehaviors.hpp"
|
||||||
|
#include "World/CPhysicsActor.hpp"
|
||||||
|
#include "CStateManager.hpp"
|
||||||
|
|
||||||
namespace urde
|
namespace urde
|
||||||
{
|
{
|
||||||
|
@ -6,19 +8,35 @@ namespace urde
|
||||||
zeus::CVector3f CSteeringBehaviors::Flee(const CPhysicsActor& actor,
|
zeus::CVector3f CSteeringBehaviors::Flee(const CPhysicsActor& actor,
|
||||||
const zeus::CVector3f& v0) const
|
const zeus::CVector3f& v0) const
|
||||||
{
|
{
|
||||||
return {};
|
zeus::CVector3f actVec = actor.GetTranslation() - v0;
|
||||||
|
if (actVec.canBeNormalized())
|
||||||
|
return actVec.normalized();
|
||||||
|
|
||||||
|
return actor.GetTransform().frontVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::CVector3f CSteeringBehaviors::Seek(const CPhysicsActor& actor,
|
zeus::CVector3f CSteeringBehaviors::Seek(const CPhysicsActor& actor,
|
||||||
const zeus::CVector3f& v0) const
|
const zeus::CVector3f& v0) const
|
||||||
{
|
{
|
||||||
|
zeus::CVector3f posDiff = actor.GetTranslation() - v0;
|
||||||
|
if (posDiff.canBeNormalized())
|
||||||
|
return posDiff.normalized();
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::CVector3f CSteeringBehaviors::Arrival(const CPhysicsActor& actor,
|
zeus::CVector3f CSteeringBehaviors::Arrival(const CPhysicsActor& actor,
|
||||||
const zeus::CVector3f& v0, float f1) const
|
const zeus::CVector3f& v0, float f31) const
|
||||||
{
|
{
|
||||||
return {};
|
if (!v0.canBeNormalized())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
if (v0.magSquared() < (f31 * f31))
|
||||||
|
f31 = v0.magSquared() / (f31 * f31);
|
||||||
|
else
|
||||||
|
f31 = 1.f;
|
||||||
|
|
||||||
|
return f31 * v0.normalized();
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::CVector3f CSteeringBehaviors::Pursuit(const CPhysicsActor& actor,
|
zeus::CVector3f CSteeringBehaviors::Pursuit(const CPhysicsActor& actor,
|
||||||
|
@ -28,21 +46,54 @@ zeus::CVector3f CSteeringBehaviors::Pursuit(const CPhysicsActor& actor,
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::CVector3f CSteeringBehaviors::Separation(const CPhysicsActor& actor,
|
zeus::CVector3f CSteeringBehaviors::Separation(const CPhysicsActor& actor,
|
||||||
const zeus::CVector3f& v0, float f1) const
|
const zeus::CVector3f& pos, float separation) const
|
||||||
{
|
{
|
||||||
return {};
|
zeus::CVector3f posDiff = actor.GetTranslation() - pos;
|
||||||
|
if (posDiff.magSquared() >= separation * separation)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
if (!posDiff.canBeNormalized())
|
||||||
|
return actor.GetTransform().frontVector();
|
||||||
|
|
||||||
|
return (1.f - (posDiff.magSquared() / (separation * separation))) * posDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::CVector3f CSteeringBehaviors::Alignment(const CPhysicsActor& actor,
|
zeus::CVector3f CSteeringBehaviors::Alignment(const CPhysicsActor& actor,
|
||||||
rstl::reserved_vector<TUniqueId, 1024>& list, const CStateManager& mgr) const
|
rstl::reserved_vector<TUniqueId, 1024>& list, const CStateManager& mgr) const
|
||||||
{
|
{
|
||||||
return {};
|
zeus::CVector3f align;
|
||||||
|
|
||||||
|
if (!list.empty())
|
||||||
|
{
|
||||||
|
for (const TUniqueId& id : list)
|
||||||
|
{
|
||||||
|
if (const CActor* act = static_cast<const CActor*>(mgr.GetObjectById(id)))
|
||||||
|
align += act->GetTransform().frontVector();
|
||||||
|
}
|
||||||
|
|
||||||
|
align *= zeus::CVector3f(1.f / float(list.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
float diff = zeus::CVector3f::getAngleDiff(actor.GetTransform().frontVector(), align);
|
||||||
|
return align * ( diff / M_PIF);
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::CVector3f CSteeringBehaviors::Cohesion(const CPhysicsActor& actor,
|
zeus::CVector3f CSteeringBehaviors::Cohesion(const CPhysicsActor& actor,
|
||||||
rstl::reserved_vector<TUniqueId, 1024>& list, float f1, const CStateManager& mgr) const
|
rstl::reserved_vector<TUniqueId, 1024>& list, float f1, const CStateManager& mgr) const
|
||||||
{
|
{
|
||||||
return {};
|
zeus::CVector3f cohesion;
|
||||||
|
if (!list.empty())
|
||||||
|
{
|
||||||
|
for (const TUniqueId& id : list)
|
||||||
|
{
|
||||||
|
if (const CActor* act = static_cast<const CActor*>(mgr.GetObjectById(id)))
|
||||||
|
cohesion += act->GetTranslation();
|
||||||
|
}
|
||||||
|
|
||||||
|
cohesion *= zeus::CVector3f(1.f / float(list.size()));
|
||||||
|
return Arrival(actor, cohesion, f1);
|
||||||
|
}
|
||||||
|
return cohesion;
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::CVector3f CSteeringBehaviors::Flee2D(const CPhysicsActor& actor,
|
zeus::CVector3f CSteeringBehaviors::Flee2D(const CPhysicsActor& actor,
|
||||||
|
|
|
@ -16,7 +16,7 @@ public:
|
||||||
zeus::CVector3f Seek(const CPhysicsActor& actor, const zeus::CVector3f& v0) const;
|
zeus::CVector3f Seek(const CPhysicsActor& actor, const zeus::CVector3f& v0) const;
|
||||||
zeus::CVector3f Arrival(const CPhysicsActor& actor, const zeus::CVector3f& v0, float f1) const;
|
zeus::CVector3f Arrival(const CPhysicsActor& actor, const zeus::CVector3f& v0, float f1) const;
|
||||||
zeus::CVector3f Pursuit(const CPhysicsActor& actor, const zeus::CVector3f& v0, const zeus::CVector3f& v1) const;
|
zeus::CVector3f Pursuit(const CPhysicsActor& actor, const zeus::CVector3f& v0, const zeus::CVector3f& v1) const;
|
||||||
zeus::CVector3f Separation(const CPhysicsActor& actor, const zeus::CVector3f& v0, float f1) const;
|
zeus::CVector3f Separation(const CPhysicsActor& actor, const zeus::CVector3f& pos, float separation) const;
|
||||||
zeus::CVector3f Alignment(const CPhysicsActor& actor, rstl::reserved_vector<TUniqueId, 1024>& list,
|
zeus::CVector3f Alignment(const CPhysicsActor& actor, rstl::reserved_vector<TUniqueId, 1024>& list,
|
||||||
const CStateManager& mgr) const;
|
const CStateManager& mgr) const;
|
||||||
zeus::CVector3f Cohesion(const CPhysicsActor& actor, rstl::reserved_vector<TUniqueId, 1024>& list,
|
zeus::CVector3f Cohesion(const CPhysicsActor& actor, rstl::reserved_vector<TUniqueId, 1024>& list,
|
||||||
|
|
|
@ -57,13 +57,7 @@ void CFire::Think(float dt, CStateManager& mgr)
|
||||||
if (GetActive())
|
if (GetActive())
|
||||||
{
|
{
|
||||||
xe8_->Update(dt * x144_);
|
xe8_->Update(dt * x144_);
|
||||||
float f0;
|
x10c_damageInfo = CDamageInfo(xf0_damageInfo, dt * std::max(0.5f, particleCount));
|
||||||
if (particleCount <= 0.5f)
|
|
||||||
f0 = 0.5f;
|
|
||||||
else
|
|
||||||
f0 = particleCount;
|
|
||||||
|
|
||||||
x10c_damageInfo = CDamageInfo(xf0_damageInfo, dt * f0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool doFree = false;
|
bool doFree = false;
|
||||||
|
@ -100,21 +94,20 @@ void CFire::Touch(CActor& act, CStateManager& mgr)
|
||||||
|
|
||||||
void CFire::AddToRenderer(const zeus::CFrustum& frustum, const CStateManager& mgr) const
|
void CFire::AddToRenderer(const zeus::CFrustum& frustum, const CStateManager& mgr) const
|
||||||
{
|
{
|
||||||
printf("AddToRenderer\n");
|
bool drawParticles = true;
|
||||||
bool r31 = true;
|
|
||||||
if (!x148_27_)
|
if (!x148_27_)
|
||||||
{
|
{
|
||||||
using EPlayerVisor = CPlayerState::EPlayerVisor;
|
using EPlayerVisor = CPlayerState::EPlayerVisor;
|
||||||
CPlayerState::EPlayerVisor visor = mgr.GetPlayerState()->GetActiveVisor(mgr);
|
CPlayerState::EPlayerVisor visor = mgr.GetPlayerState()->GetActiveVisor(mgr);
|
||||||
if (visor == EPlayerVisor::Combat || visor == EPlayerVisor::Scan)
|
if (visor == EPlayerVisor::Combat || visor == EPlayerVisor::Scan)
|
||||||
r31 = x148_24_;
|
drawParticles = x148_24_;
|
||||||
else if (visor == EPlayerVisor::XRay)
|
else if (visor == EPlayerVisor::XRay)
|
||||||
r31 = x148_26_;
|
drawParticles = x148_26_;
|
||||||
else if (visor == EPlayerVisor::Thermal)
|
else if (visor == EPlayerVisor::Thermal)
|
||||||
r31 = x148_25_;
|
drawParticles = x148_25_;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r31)
|
if (drawParticles)
|
||||||
g_Renderer->AddParticleGen(*xe8_);
|
g_Renderer->AddParticleGen(*xe8_);
|
||||||
CActor::AddToRenderer(frustum, mgr);
|
CActor::AddToRenderer(frustum, mgr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,6 +130,7 @@ set(WORLD_SOURCES
|
||||||
CHUDBillboardEffect.hpp CHUDBillboardEffect.cpp
|
CHUDBillboardEffect.hpp CHUDBillboardEffect.cpp
|
||||||
CExplosion.hpp CExplosion.cpp
|
CExplosion.hpp CExplosion.cpp
|
||||||
CIceImpact.hpp CIceImpact.cpp
|
CIceImpact.hpp CIceImpact.cpp
|
||||||
|
CFire.hpp CFire.cpp
|
||||||
CEntityInfo.hpp)
|
CEntityInfo.hpp)
|
||||||
|
|
||||||
runtime_add_list(World WORLD_SOURCES)
|
runtime_add_list(World WORLD_SOURCES)
|
||||||
|
|
Loading…
Reference in New Issue