DarkflameServer/dGame/dBehaviors/ChangeOrientationBehavior.cpp

37 lines
1.5 KiB
C++
Raw Normal View History

#include "ChangeOrientationBehavior.h"
#include "BehaviorBranchContext.h"
#include "BehaviorContext.h"
#include "EntityManager.h"
2022-07-28 13:39:57 +00:00
void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
Entity* sourceEntity;
if (this->m_orientCaster) sourceEntity = EntityManager::Instance()->GetEntity(context->originator);
else sourceEntity = EntityManager::Instance()->GetEntity(branch.target);
if (!sourceEntity) return;
if (this->m_toTarget) {
Entity* destinationEntity;
if (this->m_orientCaster) destinationEntity = EntityManager::Instance()->GetEntity(branch.target);
else destinationEntity = EntityManager::Instance()->GetEntity(context->originator);
if (!destinationEntity) return;
2023-04-03 13:29:39 +00:00
sourceEntity->SetRotation(
NiQuaternion::LookAt(sourceEntity->GetPosition(), destinationEntity->GetPosition())
);
} else if (this->m_toAngle){
2023-04-03 18:10:51 +00:00
auto baseAngle = NiPoint3(0, 0, this->m_angle);
if (this->m_relative) baseAngle += sourceEntity->GetRotation().GetForwardVector();
2023-04-03 13:29:39 +00:00
sourceEntity->SetRotation(NiQuaternion::FromEulerAngles(baseAngle));
} else return;
EntityManager::Instance()->SerializeEntity(sourceEntity);
return;
}
2022-07-28 13:39:57 +00:00
void ChangeOrientationBehavior::Load() {
this->m_orientCaster = GetBoolean("orient_caster", true);
this->m_toTarget = GetBoolean("to_target", false);
this->m_toAngle = GetBoolean("to_angle", false);
this->m_angle = GetFloat("angle", 0.0f);
this->m_relative = GetBoolean("relative", false);
}