2024-05-10 14:22:26 +00:00
|
|
|
// Darkflame Universe
|
|
|
|
// Copyright 2024
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#include "RigidbodyPhantomPhysicsComponent.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
|
2024-05-10 14:22:26 +00:00
|
|
|
#include "dpEntity.h"
|
|
|
|
#include "CDComponentsRegistryTable.h"
|
|
|
|
#include "CDPhysicsComponentTable.h"
|
|
|
|
#include "dpWorld.h"
|
|
|
|
#include "dpShapeBox.h"
|
|
|
|
#include "dpShapeSphere.h"
|
|
|
|
#include"EntityInfo.h"
|
|
|
|
|
2024-12-16 05:44:57 +00:00
|
|
|
RigidbodyPhantomPhysicsComponent::RigidbodyPhantomPhysicsComponent(Entity* parent, int32_t componentId) : PhysicsComponent(parent, componentId) {
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Position = m_Parent->GetDefaultPosition();
|
|
|
|
m_Rotation = m_Parent->GetDefaultRotation();
|
2024-05-10 14:22:26 +00:00
|
|
|
m_Scale = m_Parent->GetDefaultScale();
|
|
|
|
|
|
|
|
if (m_Parent->GetVar<bool>(u"create_physics")) {
|
|
|
|
m_dpEntity = CreatePhysicsLnv(m_Scale, ComponentType);
|
|
|
|
if (!m_dpEntity) {
|
|
|
|
m_dpEntity = CreatePhysicsEntity(ComponentType);
|
|
|
|
if (!m_dpEntity) return;
|
|
|
|
m_dpEntity->SetScale(m_Scale);
|
|
|
|
m_dpEntity->SetRotation(m_Rotation);
|
|
|
|
m_dpEntity->SetPosition(m_Position);
|
|
|
|
dpWorld::AddEntity(m_dpEntity);
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void RigidbodyPhantomPhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
2023-10-09 20:19:38 +00:00
|
|
|
PhysicsComponent::Serialize(outBitStream, bIsInitialUpdate);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2024-05-10 14:22:26 +00:00
|
|
|
|
|
|
|
void RigidbodyPhantomPhysicsComponent::Update(const float deltaTime) {
|
|
|
|
if (!m_dpEntity) return;
|
|
|
|
|
|
|
|
//Process enter events
|
|
|
|
for (const auto id : m_dpEntity->GetNewObjects()) {
|
|
|
|
m_Parent->OnCollisionPhantom(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Process exit events
|
|
|
|
for (const auto id : m_dpEntity->GetRemovedObjects()) {
|
|
|
|
m_Parent->OnCollisionLeavePhantom(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RigidbodyPhantomPhysicsComponent::SpawnVertices() const {
|
|
|
|
if (!m_dpEntity) {
|
|
|
|
LOG("No dpEntity to spawn vertices for %llu:%i", m_Parent->GetObjectID(), m_Parent->GetLOT());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PhysicsComponent::SpawnVertices(m_dpEntity);
|
|
|
|
}
|