Core/Node: Refactor interface

- Removed overloads taking multiple scalars
- Removed CoordSys parameter (functions exists in two sets, local and global)
This commit is contained in:
SirLynix
2024-02-18 22:16:54 +01:00
committed by Jérôme Leclercq
parent 194dba5002
commit 63c526cecc
23 changed files with 444 additions and 462 deletions

View File

@@ -104,7 +104,7 @@ int main(int argc, char* argv[])
Nz::RigidBody2DComponent::StaticSettings groundSettings;
groundSettings.geom = std::make_shared<Nz::BoxCollider2D>(tilemap->GetSize());
groundEntity.emplace<Nz::NodeComponent>().SetPosition(windowSize.x * 0.5f, -windowSize.y * 0.2f);
groundEntity.emplace<Nz::NodeComponent>().SetPosition({ windowSize.x * 0.5f, -windowSize.y * 0.2f });
groundEntity.emplace<Nz::GraphicsComponent>().AttachRenderable(tilemap, 1);
auto& rigidBody = groundEntity.emplace<Nz::RigidBody2DComponent>(groundSettings);
rigidBody.SetFriction(0.9f);

View File

@@ -127,7 +127,7 @@ int main(int argc, char* argv[])
entityGfx.AttachRenderable(sprite, 1);
auto& entityNode = textEntity.emplace<Nz::NodeComponent>();
entityNode.SetPosition(0.f, 5.f, 0.f);
entityNode.SetPosition({ 0.f, 5.f, 0.f });
}
entt::handle playerEntity = world.CreateEntity();
@@ -279,7 +279,7 @@ int main(int argc, char* argv[])
if (entity == playerEntity)
continue;
Nz::Vector3f spaceshipPos = node.GetPosition(Nz::CoordSys::Global);
Nz::Vector3f spaceshipPos = node.GetGlobalPosition();
if (spaceshipPos.GetSquaredLength() > Nz::IntegralPow(20.f, 2))
world.GetRegistry().destroy(entity);
}

View File

@@ -138,7 +138,7 @@ int main(int argc, char* argv[])
ballGfx.AttachRenderable(std::move(sphereModel));
auto& ballNode = ballEntity.emplace<Nz::NodeComponent>();
ballNode.SetPosition(positionRandom(rd), positionRandom(rd), positionRandom(rd));
ballNode.SetPosition({ positionRandom(rd), positionRandom(rd), positionRandom(rd) });
ballNode.SetScale(radius);
Nz::RigidBody3D::DynamicSettings settings;
@@ -173,8 +173,8 @@ int main(int argc, char* argv[])
boxEntity.emplace<Nz::GraphicsComponent>(std::move(sphereModel));
auto& ballNode = boxEntity.emplace<Nz::NodeComponent>();
ballNode.SetPosition(xRandom(rd), yRandom(rd), zRandom(rd));
ballNode.SetScale(width, height, depth);
ballNode.SetPosition({ xRandom(rd), yRandom(rd), zRandom(rd) });
ballNode.SetScale({ width, height, depth });
std::shared_ptr<Nz::BoxCollider3D> boxCollider = std::make_shared<Nz::BoxCollider3D>(Nz::Vector3f(width, height, depth));
@@ -246,7 +246,7 @@ int main(int argc, char* argv[])
shipEntity.emplace<Nz::GraphicsComponent>(model);
auto& shipNode = shipEntity.emplace<Nz::NodeComponent>();
shipNode.SetPosition(xRandom(rd), yRandom(rd), zRandom(rd));
shipNode.SetPosition({ xRandom(rd), yRandom(rd), zRandom(rd) });
Nz::RigidBody3D::DynamicSettings settings;
settings.geom = shipCollider;

View File

@@ -58,7 +58,7 @@ int main(int argc, char* argv[])
entt::handle playerCamera = world.CreateEntity();
{
auto& playerNode = playerEntity.emplace<Nz::NodeComponent>();
playerNode.SetPosition(0.f, 1.8f, 1.f);
playerNode.SetPosition({ 0.f, 1.8f, 1.f });
auto playerCollider = std::make_shared<Nz::BoxCollider3D>(Nz::Vector3f(0.2f, 1.8f, 0.2f));
@@ -286,7 +286,7 @@ int main(int argc, char* argv[])
auto [sin, cos] = rotation.GetSinCos();
auto& lightNode = lightEntity3.get<Nz::NodeComponent>();
lightNode.SetPosition(sin * radius, 1.5f, cos * radius);
lightNode.SetPosition({ sin * radius, 1.5f, cos * radius });
});
auto& cameraLight = lightEntity3.emplace<Nz::LightComponent>();
@@ -560,19 +560,19 @@ int main(int argc, char* argv[])
auto& cameraNode = playerCamera.get<Nz::NodeComponent>();
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Space))
cameraNode.Move(Nz::Vector3f::Up() * cameraSpeed * updateTime, Nz::CoordSys::Global);
cameraNode.MoveGlobal(Nz::Vector3f::Up() * cameraSpeed * updateTime);
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Z))
cameraNode.Move(Nz::Vector3f::Forward() * cameraSpeed * updateTime, Nz::CoordSys::Local);
cameraNode.Move(Nz::Vector3f::Forward() * cameraSpeed * updateTime);
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::S))
cameraNode.Move(Nz::Vector3f::Backward() * cameraSpeed * updateTime, Nz::CoordSys::Local);
cameraNode.Move(Nz::Vector3f::Backward() * cameraSpeed * updateTime);
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Q))
cameraNode.Move(Nz::Vector3f::Left() * cameraSpeed * updateTime, Nz::CoordSys::Local);
cameraNode.Move(Nz::Vector3f::Left() * cameraSpeed * updateTime);
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::D))
cameraNode.Move(Nz::Vector3f::Right() * cameraSpeed * updateTime, Nz::CoordSys::Local);
cameraNode.Move(Nz::Vector3f::Right() * cameraSpeed * updateTime);
if (!paused)
{
@@ -602,7 +602,7 @@ int main(int argc, char* argv[])
if (entity == playerEntity)
continue;
Nz::Vector3f spaceshipPos = node.GetPosition(Nz::CoordSys::Global);
Nz::Vector3f spaceshipPos = node.GetGlobalPosition();
if (spaceshipPos.GetSquaredLength() > Nz::IntegralPow(20.f, 2))
registry.destroy(entity);
}
@@ -645,8 +645,8 @@ int main(int argc, char* argv[])
Nz::DebugDrawer& debugDrawer = renderSystem.GetFramePipeline().GetDebugDrawer();
auto& lightNode = lightEntity3.get<Nz::NodeComponent>();
//debugDrawer.DrawLine(lightNode.GetPosition(Nz::CoordSys::Global), lightNode.GetForward() * 10.f, Nz::Color::Blue());
Nz::Vector3f pos = lightNode.GetPosition(Nz::CoordSys::Global);
//debugDrawer.DrawLine(lightNode.GetGlobalPosition(), lightNode.GetForward() * 10.f, Nz::Color::Blue());
Nz::Vector3f pos = lightNode.GetGlobalPosition();
debugDrawer.DrawPoint(pos, Nz::Color::Blue());
/*debugDrawer.DrawBox(floorBox, Nz::Color::Red);
Nz::Boxf intersection;

View File

@@ -48,7 +48,7 @@ int main(int argc, char* argv[])
Nz::Boxf textBox = textSprite->GetAABB();
Nz::Vector2ui windowSize = mainWindow.GetSize();
nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2);
nodeComponent.SetPosition({ windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2 });
}
return app.Run();

View File

@@ -53,7 +53,7 @@ int main(int argc, char* argv[])
Nz::Boxf textBox = textSprite->GetAABB();
Nz::Vector2ui windowSize = mainWindow.GetSize();
nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2);
nodeComponent.SetPosition({ windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2 });
}
eventHandler.OnKeyPressed.Connect([&](const Nz::WindowEventHandler*, const Nz::WindowEvent::KeyEvent& e)
@@ -65,7 +65,7 @@ int main(int argc, char* argv[])
Nz::Vector2ui windowSize = mainWindow.GetSize();
auto& nodeComponent = textEntity.get<Nz::NodeComponent>();
nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2);
nodeComponent.SetPosition({ windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2 });
// Profitons-en aussi pour nous donner un moyen de quitter le programme
if (e.virtualKey == Nz::Keyboard::VKey::Escape)

View File

@@ -38,13 +38,13 @@ int main(int argc, char* argv[])
canvas2D.Resize(Nz::Vector2f(mainWindow.GetSize()));
Nz::LabelWidget* labelWidget = canvas2D.Add<Nz::LabelWidget>();
labelWidget->SetPosition(0.f, 200.f, 0.f);
labelWidget->SetPosition({ 0.f, 200.f });
labelWidget->UpdateText(Nz::SimpleTextDrawer::Draw("Je suis un LabelWidget !", 72));
unsigned int clickCount = 0;
Nz::ButtonWidget* buttonWidget = canvas2D.Add<Nz::ButtonWidget>();
buttonWidget->SetPosition(200.f, 400.f);
buttonWidget->SetPosition({ 200.f, 400.f });
buttonWidget->UpdateText(Nz::SimpleTextDrawer::Draw("Press me senpai", 72));
buttonWidget->Resize(buttonWidget->GetPreferredSize());
@@ -55,15 +55,15 @@ int main(int argc, char* argv[])
materialInstance->SetTextureProperty("BaseColorMap", fs.Load<Nz::Texture>("assets/lynix.jpg"));
Nz::ImageWidget* imageWidget = canvas2D.Add<Nz::ImageWidget>(materialInstance);
imageWidget->SetPosition(1200.f, 200.f);
imageWidget->SetPosition({ 1200.f, 200.f });
imageWidget->Resize(imageWidget->GetPreferredSize() / 4.f);
Nz::ImageButtonWidget* imageButtonWidget = canvas2D.Add<Nz::ImageButtonWidget>(materialInstance);
imageButtonWidget->SetPosition(1400, 500.f);
imageButtonWidget->SetPosition({ 1400, 500.f });
imageButtonWidget->Resize(imageButtonWidget->GetPreferredSize() / 4.f);
Nz::TextAreaWidget* textAreaWidget = canvas2D.Add<Nz::TextAreaWidget>();
textAreaWidget->SetPosition(800.f, 500.f);
textAreaWidget->SetPosition({ 800.f, 500.f });
textAreaWidget->SetText("Je suis un TextAreaWidget !");
textAreaWidget->Resize(Nz::Vector2f(400.f, textAreaWidget->GetPreferredHeight() * 5.f));
textAreaWidget->SetBackgroundColor(Nz::Color::White());
@@ -72,7 +72,7 @@ int main(int argc, char* argv[])
Nz::CheckboxWidget* checkboxWidget = canvas2D.Add<Nz::CheckboxWidget>();
//checkboxWidget->EnableTristate(true);
checkboxWidget->SetPosition(800.f, 800.f);
checkboxWidget->SetPosition({ 800.f, 800.f });
checkboxWidget->Resize({ 256.f, 256 });
checkboxWidget->SetState(true);
@@ -84,12 +84,12 @@ int main(int argc, char* argv[])
longTextArea->SetText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum");
Nz::ScrollAreaWidget* scrollBarWidget = canvas2D.Add<Nz::ScrollAreaWidget>(longTextArea);
scrollBarWidget->SetPosition(1400.f, 800.f);
scrollBarWidget->SetPosition({ 1400.f, 800.f });
scrollBarWidget->Resize({ 512.f, 256.f });
Nz::RichTextAreaWidget* textAreaWidget2 = canvas2D.Add<Nz::RichTextAreaWidget>();
textAreaWidget2->EnableMultiline(true);
textAreaWidget2->SetPosition(1000.f, 200.f);
textAreaWidget2->SetPosition({ 1000.f, 200.f });
textAreaWidget2->SetBackgroundColor(Nz::Color::White());
textAreaWidget2->SetTextColor(Nz::Color::Black());
@@ -98,7 +98,7 @@ int main(int argc, char* argv[])
textAreaWidget2->Resize(Nz::Vector2f(500.f, textAreaWidget2->GetPreferredHeight()));
Nz::ProgressBarWidget* progressBarWidget = canvas2D.Add<Nz::ProgressBarWidget>();
progressBarWidget->SetPosition(200.f, 600.f);
progressBarWidget->SetPosition({ 200.f, 600.f });
progressBarWidget->Resize({ 512.f, 64.f });
buttonWidget->OnButtonTrigger.Connect([&](const Nz::ButtonWidget*)