cdcEngineDXHR/cdcScene/SceneEntity.cpp

118 lines
2.5 KiB
C++
Raw Normal View History

#include "IDrawable.h"
2023-03-07 00:10:40 +00:00
#include "Scene.h"
2023-01-12 17:21:52 +00:00
#include "SceneCell.h"
#include "SceneCellGroup.h"
#include "SceneEntity.h"
namespace cdc {
2023-03-07 00:10:40 +00:00
SceneEntity::SceneEntity(Scene *scene) : scene(scene) {
// called from SceneLayer::AddInstance
2023-03-07 00:10:40 +00:00
scene->AddEntity(this);
}
2023-06-19 01:14:07 +00:00
void SceneEntity::ApplyUpdateState(UpdateState *updateState) {
// called from UpdateInstances
// without this, the object might still render in the correct position
2023-06-19 01:26:30 +00:00
// but TransformVolumeAndPivot can't move the culling volume away from origin
if (updateState->updateFlags & UpdateState::kEnabled) {
enabled = updateState->enabled;
2023-06-19 01:26:30 +00:00
// TODO
}
if (updateState->updateFlags & UpdateState::kDrawable) {
// TODO
}
if (updateState->updateFlags & UpdateState::kCellGroup) {
// TODO
}
if (updateState->updateFlags & UpdateState::kMatrix) {
// TODO
2023-06-19 01:14:07 +00:00
setMatrix(updateState->matrix);
2023-06-19 01:26:30 +00:00
}
if (updateState->updateFlags & UpdateState::kMoveState) {
// TODO
}
if (updateState->updateFlags & (UpdateState::kUpdateVolume | UpdateState::kDrawable)) {
// TODO
}
if (updateState->updateFlags & (UpdateState::kUpdateFlags | UpdateState::kDrawable)) {
// TODO
}
2023-06-19 01:14:07 +00:00
}
2023-01-12 17:21:52 +00:00
void SceneEntity::setMatrix(Matrix& newMatrix) {
matrix = newMatrix;
QueryVolumeFromDrawable();
2023-01-12 17:21:52 +00:00
// TODO
}
Matrix& SceneEntity::getMatrix() {
return matrix;
}
void SceneEntity::setDrawable(IDrawable *newDrawable) {
drawable = newDrawable;
QueryVolumeFromDrawable();
2023-01-12 17:21:52 +00:00
// TODO
}
IDrawable *SceneEntity::getDrawable() {
return drawable;
}
2023-01-12 17:26:09 +00:00
void SceneEntity::setCellGroup(ISceneCellGroup *newICellGroup) {
auto newCellGroup = static_cast<SceneCellGroup*>(newICellGroup);
if (sceneCellGroup != newCellGroup) {
// TODO
sceneCellGroup = newCellGroup;
UpdateData(true);
}
}
void SceneEntity::Release() {
// called from SceneLayer::RemoveInstance
delete this;
}
SceneEntity::~SceneEntity() {
// TODO
scene->RemoveEntity(this);
}
void SceneEntity::QueryVolumeFromDrawable() { // line 370
if (drawable) {
drawable->GetBoundingVolume(&cullingVolume);
TransformVolumeAndPivot();
// TODO
} else {
// TODO
}
}
void SceneEntity::TransformVolumeAndPivot() { // line 406
cullingVolume.Transform(matrix);
}
void SceneEntity::UpdateData(bool reInitCell) { // line 464
2023-01-12 17:26:09 +00:00
// HACK
auto cell = sceneCellGroup->cellByIndex(0);
if (reInitCell) {
auto subCell = &static_cast<SceneCell*>/*TODO*/(cell)->subCells[0];
2023-01-12 17:26:09 +00:00
bool alreadyPresent = false;
for (auto ent : subCell->entities)
if (ent == this)
alreadyPresent = true;
if (!alreadyPresent)
subCell->entities.push_back(this);
}
}
2023-01-12 17:21:52 +00:00
}