DYTSrouce/src/entities/ConeWaveComponent.cpp

228 lines
6.4 KiB
C++
Raw Normal View History

2025-01-04 04:12:51 +00:00
#include "entities/ConeWaveComponent.h"
#include "common/SpdLogger.h"
#include "common/RecourceHelper.h"
#include "effects/ConeWave.h"
#include "utils/StringUtils.h"
#include "utils/TimeAction.h"
#include "entities/Entity.h"
#include "workspace/WorkSpace.h"
#include "workspace/Timestep.h"
#include "workspace/LampStatus.h"
ConeWaveComponent::ConeWaveComponent(SceneComponent* parent)
: SceneComponent(parent) {
2025-02-22 15:16:54 +00:00
// coneWave_ = new ConeWave();
// coneWave_->InitGeode();
2025-01-04 04:12:51 +00:00
colorMap_[1] = osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
colorMap_[2] = osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
colorMap_[3] = osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
}
ConeWaveComponent::~ConeWaveComponent() {
2025-02-22 15:16:54 +00:00
// coneWave_->Destory();
2025-01-04 04:12:51 +00:00
}
std::string ConeWaveComponent::GetTypeName() {
return "ConeWaveComponent";
}
bool ConeWaveComponent::SetAttribute(const char* name, const char* value) {
if (0 == strcmp("color1" ,name)) {
AddColor(1, StringUtils::StringToVec4(value));
} else if (0 == strcmp("color2" ,name)) {
AddColor(2, StringUtils::StringToVec4(value));
}else if (0 == strcmp("color3" ,name)) {
AddColor(3, StringUtils::StringToVec4(value));
} else if (0 == strcmp("radius", name)) {
SetRadius(atof(value));
} else if (0 == strcmp("height", name)) {
SetHeight(atof(value));
} else if (0 == strcmp("event", name)) {
SetTimeAction(value);
} else if (0 == strcmp("levelCount", name)) {
SetLevelCount(atof(value));
2025-01-04 04:12:51 +00:00
} else if (0 == strcmp("levelHeihgt", name)) {
SetLevelHeight(atof(value));
2025-01-04 04:12:51 +00:00
}
return SceneComponent::SetAttribute(name, value);
}
bool ConeWaveComponent::SaveAttribute(tinyxml2::XMLElement* element) {
if (colorMap_.find(1) != colorMap_.end()) {
element->SetAttribute("color1", StringUtils::Vec4ToString(colorMap_[1]).c_str());
} else {
element->SetAttribute("color1", StringUtils::Vec4ToString(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)).c_str());
}
if (colorMap_.find(2) != colorMap_.end()) {
element->SetAttribute("color2", StringUtils::Vec4ToString(colorMap_[2]).c_str());
} else {
element->SetAttribute("color2", StringUtils::Vec4ToString(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)).c_str());
}
if (colorMap_.find(3) != colorMap_.end()) {
element->SetAttribute("color3", StringUtils::Vec4ToString(colorMap_[3]).c_str());
} else {
element->SetAttribute("color3", StringUtils::Vec4ToString(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)).c_str());
}
element->SetAttribute("radius", std::to_string(GetRadius()).c_str());
element->SetAttribute("height", std::to_string(GetHeight()).c_str());
element->SetAttribute("levelCount", std::to_string(GetLevelCount()).c_str());
element->SetAttribute("levelHeihgt", std::to_string(GetLevelHeight()).c_str());
element->SetAttribute("event", timeAction_ == nullptr ? "" : timeAction_->GetPath().toStdString().c_str());
return SceneComponent::SaveAttribute(element);
}
void ConeWaveComponent::Begin() {
}
void ConeWaveComponent::Update(double dt) {
UpdateEvent();
}
void ConeWaveComponent::SetHeight(float height) {
2025-02-22 15:16:54 +00:00
// coneWave_->SetHeight(height);
// if (nullptr != mt_) {
// mt_->setMatrix(osg::Matrix::translate(osg::Vec3(0.0f, 0.0f, -coneWave_->GetHeght() * 0.75f)));
// }
2025-01-04 04:12:51 +00:00
}
float ConeWaveComponent::GetHeight() const {
2025-02-22 15:16:54 +00:00
return 0;// coneWave_->GetHeght();
2025-01-04 04:12:51 +00:00
}
void ConeWaveComponent::SetRadius(float radius) {
2025-02-22 15:16:54 +00:00
// coneWave_->SetRadius(radius);
2025-01-04 04:12:51 +00:00
}
float ConeWaveComponent::GetRadius() const {
2025-02-22 15:16:54 +00:00
return 0;// return coneWave_->GetRadius();
2025-01-04 04:12:51 +00:00
}
void ConeWaveComponent::SetLevelCount(int count) {
2025-02-22 15:16:54 +00:00
// coneWave_->SetLevelCount(count);
2025-01-04 04:12:51 +00:00
}
float ConeWaveComponent::GetLevelCount() const {
2025-02-22 15:16:54 +00:00
return 0; // return coneWave_->GetLevelCount();
2025-01-04 04:12:51 +00:00
}
void ConeWaveComponent::SetLevelHeight(float height) {
2025-02-22 15:16:54 +00:00
// coneWave_->SetLevelHeight(height);
2025-01-04 04:12:51 +00:00
}
float ConeWaveComponent::GetLevelHeight() const {
2025-02-22 15:16:54 +00:00
// return coneWave_->GetLevelHeihgt();
return 0.0f;
2025-01-04 04:12:51 +00:00
}
void ConeWaveComponent::SetBaseColor(const osg::Vec4& color) {
2025-02-22 15:16:54 +00:00
// coneWave_->SetBaseColor(color);
2025-01-04 04:12:51 +00:00
}
const osg::Vec4 ConeWaveComponent::GetBaseColor() const {
2025-02-22 15:16:54 +00:00
// return coneWave_->GetBaseColor();
return osg::Vec4();
2025-01-04 04:12:51 +00:00
}
void ConeWaveComponent::SetColor1(const osg::Vec4& color) {
colorMap_[1] = color;
}
const osg::Vec4 ConeWaveComponent::GetColor1() const {
const auto color = colorMap_.find(1);
return color->second;
}
void ConeWaveComponent::SetColor2(const osg::Vec4& color) {
colorMap_[2] = color;
}
const osg::Vec4 ConeWaveComponent::GetColor2() const {
const auto color = colorMap_.find(2);
return color->second;
}
void ConeWaveComponent::SetColor3(const osg::Vec4& color) {
colorMap_[3] = color;
}
const osg::Vec4 ConeWaveComponent::GetColor3() const {
const auto color = colorMap_.find(3);
return color->second;
}
void ConeWaveComponent::SetTimeAction(const QString& path) {
if (nullptr != timeAction_) {
timeAction_->deleteLater();
}
timeAction_ = TimeAction::LoadFromFile(path);
}
void ConeWaveComponent::AddToRender() {
Initialize();
SceneComponent::AddToRender();
}
void ConeWaveComponent::Initialize() {
mt_ = new osg::MatrixTransform;
mt_->addChild(coneWave_);
2025-02-22 15:16:54 +00:00
// mt_->setMatrix(osg::Matrix::translate(osg::Vec3(0.0f, 0.0f, -coneWave_->GetHeght() * 0.75f)));
2025-01-04 04:12:51 +00:00
}
void ConeWaveComponent::UpdateEvent() {
if (nullptr == timeAction_) {
return;
}
WorkSpace* workspace = GetEntity()->GetWorkspace();
if (nullptr == workspace) {
LOG_WARN("workspace is nullptr");
return;
}
LampStatus* lampStatus = workspace->GetLampStatus();
if (nullptr == lampStatus) {
return;
}
if (currentStatus_ == lampStatus->GetCurrent()) {
return;
}
currentStatus_ = lampStatus->GetCurrent();
if (colorMap_.find(currentStatus_) == colorMap_.end()) {
coneWave_->setNodeMask(0x0);
return;
}
osg::Vec4& color = colorMap_[currentStatus_];
2025-02-22 15:16:54 +00:00
// coneWave_->SetBaseColor(color);
2025-01-04 04:12:51 +00:00
coneWave_->setNodeMask(0xff);
//Timestep* timeStep = workspace->GetTimestep();
//if (nullptr == timeStep) {
// LOG_WARN("timeStep is nullptr");
// return;
//}
//double dt = timeStep->GetCurrent();
//int value = timeAction_->GetValue(dt);
//if (-1 == value) {
// return;
//}
//
//coneWave_->setNodeMask(value == 0 ? 0x0 : 0xff);
}
void ConeWaveComponent::AddColor(int32_t status, const osg::Vec4& color) {
colorMap_[status] = color;
}