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*)

View File

@ -29,25 +29,29 @@ namespace Nz
inline Node(Node&& node) noexcept;
virtual ~Node();
inline void EnsureDerivedUpdate() const;
inline bool DoesInheritPosition() const;
inline bool DoesInheritRotation() const;
inline bool DoesInheritScale() const;
inline void EnsureGlobalsUpdate() const;
inline void EnsureTransformMatrixUpdate() const;
inline Vector3f GetBackward() const;
inline const std::vector<Node*>& GetChilds() const;
inline Vector3f GetDown() const;
inline Vector3f GetForward() const;
inline bool GetInheritPosition() const;
inline bool GetInheritRotation() const;
inline bool GetInheritScale() const;
inline Vector3f GetInitialPosition() const;
inline Quaternionf GetInitialRotation() const;
inline Vector3f GetInitialScale() const;
inline const Vector3f& GetGlobalPosition() const;
inline const Quaternionf& GetGlobalRotation() const;
inline const Vector3f& GetGlobalScale() const;
inline const Vector3f& GetInitialPosition() const;
inline const Quaternionf& GetInitialRotation() const;
inline const Vector3f& GetInitialScale() const;
inline Vector3f GetLeft() const;
inline const Node* GetParent() const;
inline Vector3f GetPosition(CoordSys coordSys = CoordSys::Local) const;
inline const Vector3f& GetPosition() const;
inline Vector3f GetRight() const;
inline Quaternionf GetRotation(CoordSys coordSys = CoordSys::Local) const;
inline Vector3f GetScale(CoordSys coordSys = CoordSys::Local) const;
inline const Quaternionf& GetRotation() const;
inline const Vector3f& GetScale() const;
inline const Matrix4f& GetTransformMatrix() const;
inline Vector3f GetUp() const;
@ -55,17 +59,29 @@ namespace Nz
inline void Invalidate(Invalidation invalidation = Invalidation::InvalidateRecursively);
Node& Interpolate(const Node& nodeA, const Node& nodeB, float interpolation, CoordSys coordSys = CoordSys::Global, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& Interpolate(const Node& nodeA, const Node& nodeB, float interpolation, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& InterpolateGlobal(const Node& nodeA, const Node& nodeB, float interpolation, Invalidation invalidation = Invalidation::InvalidateRecursively);
Node& Move(const Vector3f& movement, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& Move(float movementX, float movementY, float movementZ = 0.f, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& Move(const Vector2f& movement, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& Move(const Vector3f& movement, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& MoveGlobal(const Vector2f& movement, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& MoveGlobal(const Vector3f& movement, Invalidation invalidation = Invalidation::InvalidateRecursively);
Node& Rotate(const Quaternionf& rotation, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& Rotate(const Quaternionf& rotation, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& RotateGlobal(const Quaternionf& rotation, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& Scale(const Vector3f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& Scale(float scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& Scale(float scaleX, float scaleY, float scaleZ = 1.f, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& Scale(const Vector2f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline Node& Scale(const Vector3f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetGlobalPosition(const Vector2f& position, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetGlobalPosition(const Vector3f& position, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetGlobalRotation(const Quaternionf& rotation, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetGlobalScale(const Vector2f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetGlobalScale(const Vector3f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetGlobalTransform(const Vector3f& position, const Quaternionf& rotation, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetGlobalTransform(const Vector3f& position, const Quaternionf& rotation, const Vector2f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetGlobalTransform(const Vector3f& position, const Quaternionf& rotation, const Vector3f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetInheritPosition(bool inheritPosition, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetInheritRotation(bool inheritRotation, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetInheritScale(bool inheritScale, Invalidation invalidation = Invalidation::InvalidateRecursively);
@ -77,15 +93,15 @@ namespace Nz
inline void SetInitialScale(float scaleX, float scaleY, float scaleZ = 1.f, Invalidation invalidation = Invalidation::InvalidateRecursively);
void SetParent(const Node* node = nullptr, bool keepDerived = false, Invalidation invalidation = Invalidation::InvalidateRecursively);
void SetParent(const Node& node, bool keepDerived = false, Invalidation invalidation = Invalidation::InvalidateRecursively);
void SetPosition(const Vector3f& translation, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetPosition(float translationX, float translationY, float translationZ = 0.f, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
void SetRotation(const Quaternionf& rotation, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetScale(const Vector2f& scale, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
void SetScale(const Vector3f& scale, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetScale(float scale, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetScale(float scaleX, float scaleY, float scaleZ = 1.f, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
void SetTransform(const Vector3f& position, const Quaternionf& rotation, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
void SetTransform(const Vector3f& position, const Quaternionf& rotation, const Vector3f& scale, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetPosition(const Vector2f& position, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetPosition(const Vector3f& position, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetRotation(const Quaternionf& rotation, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetScale(float scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetScale(const Vector2f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetScale(const Vector3f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetTransform(const Vector3f& position, const Quaternionf& rotation, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetTransform(const Vector3f& position, const Quaternionf& rotation, const Vector2f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetTransform(const Vector3f& position, const Quaternionf& rotation, const Vector3f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
inline void SetTransformMatrix(const Matrix4f& matrix, Invalidation invalidation = Invalidation::InvalidateRecursively);
// Local -> global
@ -123,20 +139,20 @@ namespace Nz
mutable std::vector<Node*> m_childs;
mutable Matrix4f m_transformMatrix;
mutable Quaternionf m_derivedRotation;
mutable Quaternionf m_globalRotation;
Quaternionf m_initialRotation;
Quaternionf m_rotation;
mutable Vector3f m_derivedPosition;
mutable Vector3f m_derivedScale;
mutable Vector3f m_globalPosition;
mutable Vector3f m_globalScale;
Vector3f m_initialPosition;
Vector3f m_initialScale;
Vector3f m_position;
Vector3f m_scale;
const Node* m_parent;
mutable bool m_derivedUpdated;
bool m_inheritPosition;
bool m_inheritRotation;
bool m_inheritScale;
bool m_doesInheritPosition;
bool m_doesInheritRotation;
bool m_doesInheritScale;
mutable bool m_transformMatrixUpdated;
};
}

View File

@ -17,9 +17,9 @@ namespace Nz
m_scale(scale),
m_parent(nullptr),
m_derivedUpdated(false),
m_inheritPosition(true),
m_inheritRotation(true),
m_inheritScale(true),
m_doesInheritPosition(true),
m_doesInheritRotation(true),
m_doesInheritScale(true),
m_transformMatrixUpdated(false)
{
}
@ -33,9 +33,9 @@ namespace Nz
m_scale(node.m_scale),
m_parent(nullptr),
m_derivedUpdated(false),
m_inheritPosition(node.m_inheritPosition),
m_inheritRotation(node.m_inheritRotation),
m_inheritScale(node.m_inheritScale),
m_doesInheritPosition(node.m_doesInheritPosition),
m_doesInheritRotation(node.m_doesInheritRotation),
m_doesInheritScale(node.m_doesInheritScale),
m_transformMatrixUpdated(false)
{
SetParent(node.m_parent, false);
@ -54,9 +54,9 @@ namespace Nz
m_scale(node.m_scale),
m_parent(node.m_parent),
m_derivedUpdated(false),
m_inheritPosition(node.m_inheritPosition),
m_inheritRotation(node.m_inheritRotation),
m_inheritScale(node.m_inheritScale),
m_doesInheritPosition(node.m_doesInheritPosition),
m_doesInheritRotation(node.m_doesInheritRotation),
m_doesInheritScale(node.m_doesInheritScale),
m_transformMatrixUpdated(false)
{
if (m_parent)
@ -70,7 +70,22 @@ namespace Nz
child->m_parent = this;
}
inline void Node::EnsureDerivedUpdate() const
inline bool Node::DoesInheritPosition() const
{
return m_doesInheritPosition;
}
inline bool Node::DoesInheritRotation() const
{
return m_doesInheritRotation;
}
inline bool Node::DoesInheritScale() const
{
return m_doesInheritScale;
}
inline void Node::EnsureGlobalsUpdate() const
{
if (!m_derivedUpdated)
UpdateDerived();
@ -84,8 +99,8 @@ namespace Nz
inline Vector3f Node::GetBackward() const
{
EnsureDerivedUpdate();
return m_derivedRotation * Vector3f::Backward();
EnsureGlobalsUpdate();
return m_globalRotation * Vector3f::Backward();
}
inline const std::vector<Node*>& Node::GetChilds() const
@ -95,50 +110,53 @@ namespace Nz
inline Vector3f Node::GetDown() const
{
EnsureDerivedUpdate();
return m_derivedRotation * Vector3f::Down();
EnsureGlobalsUpdate();
return m_globalRotation * Vector3f::Down();
}
inline Vector3f Node::GetForward() const
{
EnsureDerivedUpdate();
return m_derivedRotation * Vector3f::Forward();
EnsureGlobalsUpdate();
return m_globalRotation * Vector3f::Forward();
}
inline bool Node::GetInheritPosition() const
inline const Vector3f& Node::GetGlobalPosition() const
{
return m_inheritPosition;
EnsureGlobalsUpdate();
return m_globalPosition;
}
inline bool Node::GetInheritRotation() const
inline const Quaternionf& Node::GetGlobalRotation() const
{
return m_inheritRotation;
EnsureGlobalsUpdate();
return m_globalRotation;
}
inline bool Node::GetInheritScale() const
inline const Vector3f& Node::GetGlobalScale() const
{
return m_inheritScale;
EnsureGlobalsUpdate();
return m_globalScale;
}
inline Vector3f Node::GetInitialPosition() const
inline const Vector3f& Node::GetInitialPosition() const
{
return m_initialPosition;
}
inline Quaternionf Node::GetInitialRotation() const
inline const Quaternionf& Node::GetInitialRotation() const
{
return m_initialRotation;
}
inline Vector3f Node::GetInitialScale() const
inline const Vector3f& Node::GetInitialScale() const
{
return m_initialScale;
}
inline Vector3f Node::GetLeft() const
{
EnsureDerivedUpdate();
return m_derivedRotation * Vector3f::Left();
EnsureGlobalsUpdate();
return m_globalRotation * Vector3f::Left();
}
inline const Node* Node::GetParent() const
@ -146,58 +164,25 @@ namespace Nz
return m_parent;
}
inline Vector3f Node::GetPosition(CoordSys coordSys) const
inline const Vector3f& Node::GetPosition() const
{
switch (coordSys)
{
case CoordSys::Global:
EnsureDerivedUpdate();
return m_derivedPosition;
case CoordSys::Local:
return m_position;
}
NazaraErrorFmt("Coordinate system out of enum ({0:#x})", UnderlyingCast(coordSys));
return Vector3f();
return m_position;
}
inline Vector3f Node::GetRight() const
{
EnsureDerivedUpdate();
return m_derivedRotation * Vector3f::Right();
EnsureGlobalsUpdate();
return m_globalRotation * Vector3f::Right();
}
inline Quaternionf Node::GetRotation(CoordSys coordSys) const
inline const Quaternionf& Node::GetRotation() const
{
switch (coordSys)
{
case CoordSys::Global:
EnsureDerivedUpdate();
return m_derivedRotation;
case CoordSys::Local:
return m_rotation;
}
NazaraErrorFmt("Coordinate system out of enum ({0:#x})", UnderlyingCast(coordSys));
return Quaternionf();
return m_rotation;
}
inline Vector3f Node::GetScale(CoordSys coordSys) const
inline const Vector3f& Node::GetScale() const
{
switch (coordSys)
{
case CoordSys::Global:
EnsureDerivedUpdate();
return m_derivedScale;
case CoordSys::Local:
return m_scale;
}
NazaraErrorFmt("Coordinate system out of enum ({0:#x})", UnderlyingCast(coordSys));
return Vector3f();
return m_scale;
}
inline const Matrix4f& Node::GetTransformMatrix() const
@ -208,8 +193,8 @@ namespace Nz
inline Vector3f Node::GetUp() const
{
EnsureDerivedUpdate();
return m_derivedRotation * Vector3f::Up();
EnsureGlobalsUpdate();
return m_globalRotation * Vector3f::Up();
}
inline bool Node::HasChilds() const
@ -223,9 +208,80 @@ namespace Nz
InvalidateNode(invalidation);
}
inline Node& Node::Move(float moveX, float moveY, float moveZ, CoordSys coordSys, Invalidation invalidation)
inline Node& Node::Interpolate(const Node& nodeA, const Node& nodeB, float interpolation, Invalidation invalidation)
{
return Move(Vector3f(moveX, moveY, moveZ), coordSys, invalidation);
m_position = Vector3f::Lerp(nodeA.m_position, nodeB.m_position, interpolation);
m_rotation = Quaternionf::Slerp(nodeA.m_rotation, nodeB.m_rotation, interpolation);
m_scale = Vector3f::Lerp(nodeA.m_scale, nodeB.m_scale, interpolation);
Invalidate(invalidation);
return *this;
}
Node& Node::InterpolateGlobal(const Node& nodeA, const Node& nodeB, float interpolation, Invalidation invalidation)
{
nodeA.EnsureGlobalsUpdate();
nodeB.EnsureGlobalsUpdate();
m_position = ToLocalPosition(Vector3f::Lerp(nodeA.m_globalPosition, nodeB.m_globalPosition, interpolation));
m_rotation = ToLocalRotation(Quaternionf::Slerp(nodeA.m_globalRotation, nodeB.m_globalRotation, interpolation));
m_scale = ToLocalScale(Vector3f::Lerp(nodeA.m_globalScale, nodeB.m_globalScale, interpolation));
Invalidate(invalidation);
return *this;
}
inline Node& Node::Move(const Vector2f& movement, Invalidation invalidation)
{
return Move(Vector3f(movement), invalidation);
}
inline Node& Node::Move(const Vector3f& movement, Invalidation invalidation)
{
m_position += m_rotation * movement;
Invalidate(invalidation);
return *this;
}
inline Node& Node::MoveGlobal(const Vector2f& movement, Invalidation invalidation)
{
return MoveGlobal(Vector3f(movement), invalidation);
}
inline Node& Node::MoveGlobal(const Vector3f& movement, Invalidation invalidation)
{
if (m_parent)
{
m_parent->EnsureGlobalsUpdate();
m_position += (m_parent->m_globalRotation.GetConjugate() * (movement - m_parent->m_globalPosition)) / m_parent->m_globalScale;
}
else
m_position += movement;
Invalidate(invalidation);
return *this;
}
inline Node& Node::Rotate(const Quaternionf& rotation, Invalidation invalidation)
{
m_rotation = rotation * m_rotation;
m_rotation.Normalize();
Invalidate(invalidation);
return *this;
}
inline Node& Node::RotateGlobal(const Quaternionf& rotation, Invalidation invalidation)
{
EnsureGlobalsUpdate();
m_rotation = m_rotation * m_globalRotation.GetConjugate() * rotation * m_globalRotation;
m_rotation.Normalize();
Invalidate(invalidation);
return *this;
}
inline Node& Node::Scale(const Vector3f& scale, Invalidation invalidation)
@ -233,7 +289,6 @@ namespace Nz
m_scale *= scale;
Invalidate(invalidation);
return *this;
}
@ -242,27 +297,129 @@ namespace Nz
m_scale *= scale;
Invalidate(invalidation);
return *this;
}
inline Node& Node::Scale(float scaleX, float scaleY, float scaleZ, Invalidation invalidation)
inline Node& Node::Scale(const Vector2f& scale, Invalidation invalidation)
{
m_scale.x *= scaleX;
m_scale.y *= scaleY;
m_scale.z *= scaleZ;
return Scale(Vector3f(scale), invalidation);
}
inline void Node::SetGlobalPosition(const Vector2f& position, Invalidation invalidation)
{
return SetGlobalPosition(Vector3f(position), invalidation);
}
inline void Node::SetGlobalPosition(const Vector3f& position, Invalidation invalidation)
{
if (m_parent && m_doesInheritPosition)
{
m_parent->EnsureGlobalsUpdate();
m_position = (m_parent->m_globalRotation.GetConjugate() * (position - m_parent->m_globalPosition)) / m_parent->m_globalScale - m_initialPosition;
}
else
m_position = position - m_initialPosition;
Invalidate(invalidation);
}
return *this;
inline void Node::SetGlobalRotation(const Quaternionf& rotation, Invalidation invalidation)
{
if (m_parent && m_doesInheritRotation)
{
Quaternionf rot(m_parent->GetRotation() * m_initialRotation);
m_rotation = rot.GetConjugate() * rotation;
}
else
m_rotation = rotation;
Invalidate(invalidation);
}
inline void Node::SetGlobalScale(const Vector2f& scale, Invalidation invalidation)
{
return SetGlobalScale(Vector3f(scale.x, scale.y, 1.f), invalidation);
}
inline void Node::SetGlobalScale(const Vector3f& scale, Invalidation invalidation)
{
if (m_parent && m_doesInheritScale)
m_scale = scale / (m_initialScale * m_parent->m_globalScale);
else
m_scale = scale / m_initialScale;
Invalidate(invalidation);
}
inline void Node::SetGlobalTransform(const Vector3f& position, const Quaternionf& rotation, Invalidation invalidation)
{
// Position
if (m_parent && m_doesInheritPosition)
{
m_parent->EnsureGlobalsUpdate();
m_position = (m_parent->m_globalRotation.GetConjugate() * (position - m_parent->m_globalPosition)) / m_parent->m_globalScale - m_initialPosition;
}
else
m_position = position - m_initialPosition;
// Rotation
if (m_parent && m_doesInheritRotation)
{
Quaternionf rot(m_parent->GetRotation() * m_initialRotation);
m_rotation = rot.GetConjugate() * rotation;
}
else
m_rotation = rotation;
Invalidate(invalidation);
}
inline void Node::SetGlobalTransform(const Vector3f& position, const Quaternionf& rotation, const Vector2f& scale, Invalidation invalidation)
{
return SetGlobalTransform(position, rotation, Vector3f(scale.x, scale.y, 1.f), invalidation);
}
inline void Node::SetGlobalTransform(const Vector3f& position, const Quaternionf& rotation, const Vector3f& scale, Invalidation invalidation)
{
// Position
if (m_parent && m_doesInheritPosition)
{
m_parent->EnsureGlobalsUpdate();
m_position = (m_parent->m_globalRotation.GetConjugate() * (position - m_parent->m_globalPosition)) / m_parent->m_globalScale - m_initialPosition;
}
else
m_position = position - m_initialPosition;
// Rotation
if (m_parent && m_doesInheritRotation)
{
Quaternionf rot(m_parent->GetRotation() * m_initialRotation);
m_rotation = rot.GetConjugate() * rotation;
}
else
m_rotation = rotation;
// Scale
if (m_parent && m_doesInheritScale)
m_scale = scale / (m_initialScale * m_parent->GetScale());
else
m_scale = scale / m_initialScale;
Invalidate(invalidation);
}
inline void Node::SetInheritPosition(bool inheritPosition, Invalidation invalidation)
{
///DOC: Un appel redondant est sans effet
if (m_inheritPosition != inheritPosition)
if (m_doesInheritPosition != inheritPosition)
{
m_inheritPosition = inheritPosition;
m_doesInheritPosition = inheritPosition;
Invalidate(invalidation);
}
@ -271,9 +428,9 @@ namespace Nz
inline void Node::SetInheritRotation(bool inheritRotation, Invalidation invalidation)
{
///DOC: Un appel redondant est sans effet
if (m_inheritRotation != inheritRotation)
if (m_doesInheritRotation != inheritRotation)
{
m_inheritRotation = inheritRotation;
m_doesInheritRotation = inheritRotation;
Invalidate(invalidation);
}
@ -282,9 +439,9 @@ namespace Nz
inline void Node::SetInheritScale(bool inheritScale, Invalidation invalidation)
{
///DOC: Un appel redondant est sans effet
if (m_inheritScale != inheritScale)
if (m_doesInheritScale != inheritScale)
{
m_inheritScale = inheritScale;
m_doesInheritScale = inheritScale;
Invalidate(invalidation);
}
@ -337,32 +494,67 @@ namespace Nz
SetParent(&node, keepDerived, invalidation);
}
inline void Node::SetPosition(float positionX, float positionY, float positionZ, CoordSys coordSys, Invalidation invalidation)
inline void Node::SetPosition(const Vector2f& position, Invalidation invalidation)
{
SetPosition(Vector3f(positionX, positionY, positionZ), coordSys, invalidation);
m_position = Vector3f(position);
Invalidate(invalidation);
}
inline void Node::SetPosition(const Vector3f& position, Invalidation invalidation)
{
m_position = position;
Invalidate(invalidation);
}
inline void Node::SetScale(const Vector2f& scale, CoordSys coordSys, Invalidation invalidation)
inline void Node::SetRotation(const Quaternionf& rotation, Invalidation invalidation)
{
// Prevent Z scale at zero (can happen when using SetScale with a Vec2)
SetScale(scale.x, scale.y, 1.f, coordSys, invalidation);
m_rotation = rotation;
Invalidate(invalidation);
}
inline void Node::SetScale(float scale, CoordSys coordSys, Invalidation invalidation)
inline void Node::SetScale(float scale, Invalidation invalidation)
{
SetScale(Vector3f(scale), coordSys, invalidation);
return SetScale(Vector3f(scale, scale, scale), invalidation);
}
inline void Node::SetScale(float scaleX, float scaleY, float scaleZ, CoordSys coordSys, Invalidation invalidation)
inline void Node::SetScale(const Vector2f& scale, Invalidation invalidation)
{
SetScale(Vector3f(scaleX, scaleY, scaleZ), coordSys, invalidation);
return SetScale(Vector3f(scale.x, scale.y, 1.f), invalidation);
}
inline void Node::SetScale(const Vector3f& scale, Invalidation invalidation)
{
m_scale = scale;
Invalidate(invalidation);
}
inline void Node::SetTransform(const Vector3f& position, const Quaternionf& rotation, Invalidation invalidation)
{
m_position = position;
m_rotation = rotation;
Invalidate(invalidation);
}
inline void Node::SetTransform(const Vector3f& position, const Quaternionf& rotation, const Vector2f& scale, Invalidation invalidation)
{
return SetTransform(position, rotation, Vector3f(scale.x, scale.y, 1.f), invalidation);
}
inline void Node::SetTransform(const Vector3f& position, const Quaternionf& rotation, const Vector3f& scale, Invalidation invalidation)
{
m_position = position;
m_rotation = rotation;
m_scale = scale;
Invalidate(invalidation);
}
inline void Node::SetTransformMatrix(const Matrix4f& matrix, Invalidation invalidation)
{
SetPosition(matrix.GetTranslation(), CoordSys::Global, Invalidation::DontInvalidate);
SetRotation(matrix.GetRotation(), CoordSys::Global, Invalidation::DontInvalidate);
SetScale(matrix.GetScale(), CoordSys::Global, Invalidation::DontInvalidate);
SetGlobalPosition(matrix.GetTranslation(), Invalidation::DontInvalidate);
SetGlobalRotation(matrix.GetRotation(), Invalidation::DontInvalidate);
SetGlobalScale(matrix.GetScale(), Invalidation::DontInvalidate);
Invalidate(invalidation);
@ -372,47 +564,47 @@ namespace Nz
inline Vector3f Node::ToGlobalPosition(const Vector3f& localPosition) const
{
EnsureDerivedUpdate();
return TransformPositionTRS(m_derivedPosition, m_derivedRotation, m_derivedScale, localPosition);
EnsureGlobalsUpdate();
return TransformPositionTRS(m_globalPosition, m_globalRotation, m_globalScale, localPosition);
}
inline Quaternionf Node::ToGlobalRotation(const Quaternionf& localRotation) const
{
EnsureDerivedUpdate();
return TransformRotationTRS(m_derivedRotation, m_derivedScale, localRotation);
EnsureGlobalsUpdate();
return TransformRotationTRS(m_globalRotation, m_globalScale, localRotation);
}
inline Vector3f Node::ToGlobalScale(const Vector3f& localScale) const
{
EnsureDerivedUpdate();
return TransformScaleTRS(m_derivedScale, localScale);
EnsureGlobalsUpdate();
return TransformScaleTRS(m_globalScale, localScale);
}
inline Vector3f Node::ToLocalPosition(const Vector3f& globalPosition) const
{
EnsureDerivedUpdate();
return m_derivedRotation.GetConjugate() * (globalPosition - m_derivedPosition) / m_derivedScale;
EnsureGlobalsUpdate();
return m_globalRotation.GetConjugate() * (globalPosition - m_globalPosition) / m_globalScale;
}
inline Quaternionf Node::ToLocalRotation(const Quaternionf& globalRotation) const
{
EnsureDerivedUpdate();
return m_derivedRotation.GetConjugate() * globalRotation;
EnsureGlobalsUpdate();
return m_globalRotation.GetConjugate() * globalRotation;
}
inline Vector3f Node::ToLocalScale(const Vector3f& globalScale) const
{
EnsureDerivedUpdate();
return globalScale / m_derivedScale;
EnsureGlobalsUpdate();
return globalScale / m_globalScale;
}
inline Node& Node::operator=(const Node& node)
{
SetParent(node.m_parent, false, Invalidation::DontInvalidate);
m_inheritPosition = node.m_inheritPosition;
m_inheritRotation = node.m_inheritRotation;
m_inheritScale = node.m_inheritScale;
m_doesInheritPosition = node.m_doesInheritPosition;
m_doesInheritRotation = node.m_doesInheritRotation;
m_doesInheritScale = node.m_doesInheritScale;
m_initialPosition = node.m_initialPosition;
m_initialRotation = node.m_initialRotation;
m_initialScale = node.m_initialScale;
@ -430,9 +622,9 @@ namespace Nz
if (m_parent)
SetParent(nullptr);
m_inheritPosition = node.m_inheritPosition;
m_inheritRotation = node.m_inheritRotation;
m_inheritScale = node.m_inheritScale;
m_doesInheritPosition = node.m_doesInheritPosition;
m_doesInheritRotation = node.m_doesInheritRotation;
m_doesInheritScale = node.m_doesInheritScale;
m_initialPosition = node.m_initialPosition;
m_initialRotation = node.m_initialRotation;
m_initialScale = node.m_initialScale;

View File

@ -54,7 +54,7 @@ namespace Nz
Vector2f parentSize = m_parentWidget->GetSize();
Vector2f mySize = GetSize();
SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f);
SetPosition({ (parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f });
}
inline void BaseWidget::CenterHorizontal()
@ -63,7 +63,7 @@ namespace Nz
Vector2f parentSize = m_parentWidget->GetSize();
Vector2f mySize = GetSize();
SetPosition((parentSize.x - mySize.x) / 2.f, GetPosition(CoordSys::Local).y);
SetPosition({ (parentSize.x - mySize.x) / 2.f, GetPosition().y });
}
inline void BaseWidget::CenterVertical()
@ -72,7 +72,7 @@ namespace Nz
Vector2f parentSize = m_parentWidget->GetSize();
Vector2f mySize = GetSize();
SetPosition(GetPosition(CoordSys::Local).x, (parentSize.y - mySize.y) / 2.f);
SetPosition({ GetPosition().x, (parentSize.y - mySize.y) / 2.f });
}
inline void BaseWidget::ClearRenderingRect()

View File

@ -65,7 +65,7 @@ namespace Nz
{
WidgetEntry& entry = m_widgetEntries[index];
Nz::Vector3f pos = entry.widget->GetPosition(Nz::CoordSys::Global);
Nz::Vector3f pos = entry.widget->GetGlobalPosition();
Nz::Vector2f size = entry.widget->GetSize();
entry.box = Boxf(pos.x, pos.y, pos.z, size.x, size.y, 1.f);

View File

@ -97,9 +97,9 @@ namespace Nz
const SequenceJoint& sequenceJointB = m_impl->sequenceJoints[frameB*m_impl->jointCount + i];
Joint& joint = joints[i];
joint.SetPosition(Vector3f::Lerp(sequenceJointA.position, sequenceJointB.position, interpolation), CoordSys::Local, Node::Invalidation::DontInvalidate);
joint.SetRotation(Quaternionf::Slerp(sequenceJointA.rotation, sequenceJointB.rotation, interpolation), CoordSys::Local, Node::Invalidation::DontInvalidate);
joint.SetScale(Vector3f::Lerp(sequenceJointA.scale, sequenceJointB.scale, interpolation), CoordSys::Local, Node::Invalidation::DontInvalidate);
joint.SetPosition(Vector3f::Lerp(sequenceJointA.position, sequenceJointB.position, interpolation), Node::Invalidation::DontInvalidate);
joint.SetRotation(Quaternionf::Slerp(sequenceJointA.rotation, sequenceJointB.rotation, interpolation), Node::Invalidation::DontInvalidate);
joint.SetScale(Vector3f::Lerp(sequenceJointA.scale, sequenceJointB.scale, interpolation), Node::Invalidation::DontInvalidate);
}
targetSkeleton->GetRootJoint()->Invalidate();

View File

@ -86,7 +86,7 @@ namespace Nz
Joint* attachedJoints = m_attachedSkeleton.GetJoints();
for (std::size_t i = 0; i < jointCount; ++i)
attachedJoints[i].SetTransform(referenceJoints[i].GetPosition(), referenceJoints[i].GetRotation(), referenceJoints[i].GetScale(), CoordSys::Local, Node::Invalidation::DontInvalidate);
attachedJoints[i].SetTransform(referenceJoints[i].GetPosition(), referenceJoints[i].GetRotation(), referenceJoints[i].GetScale(), Node::Invalidation::DontInvalidate);
m_attachedSkeleton.GetRootJoint()->Invalidate();

View File

@ -23,83 +23,6 @@ namespace Nz
m_parent->RemoveChild(this);
}
Node& Node::Interpolate(const Node& nodeA, const Node& nodeB, float interpolation, CoordSys coordSys, Invalidation invalidation)
{
switch (coordSys)
{
case CoordSys::Global:
nodeA.EnsureDerivedUpdate();
nodeB.EnsureDerivedUpdate();
m_position = ToLocalPosition(Vector3f::Lerp(nodeA.m_derivedPosition, nodeB.m_derivedPosition, interpolation));
m_rotation = ToLocalRotation(Quaternionf::Slerp(nodeA.m_derivedRotation, nodeB.m_derivedRotation, interpolation));
m_scale = ToLocalScale(Vector3f::Lerp(nodeA.m_derivedScale, nodeB.m_derivedScale, interpolation));
break;
case CoordSys::Local:
m_position = Vector3f::Lerp(nodeA.m_position, nodeB.m_position, interpolation);
m_rotation = Quaternionf::Slerp(nodeA.m_rotation, nodeB.m_rotation, interpolation);
m_scale = Vector3f::Lerp(nodeA.m_scale, nodeB.m_scale, interpolation);
break;
}
Invalidate(invalidation);
return *this;
}
Node& Node::Move(const Vector3f& movement, CoordSys coordSys, Invalidation invalidation)
{
switch (coordSys)
{
case CoordSys::Global:
{
if (m_parent)
{
m_parent->EnsureDerivedUpdate();
m_position += (m_parent->m_derivedRotation.GetConjugate()*(movement - m_parent->m_derivedPosition))/m_parent->m_derivedScale; // Compensation
}
else
m_position += movement; // Rien n'affecte le node
break;
}
case CoordSys::Local:
m_position += m_rotation * movement;
break;
}
Invalidate(invalidation);
return *this;
}
Node& Node::Rotate(const Quaternionf& rotation, CoordSys coordSys, Invalidation invalidation)
{
switch (coordSys)
{
case CoordSys::Global:
{
EnsureDerivedUpdate();
m_rotation *= m_derivedRotation.GetInverse() * rotation * m_derivedRotation; ///FIXME: Correct ?
break;
}
case CoordSys::Local:
m_rotation *= rotation;
break;
}
m_rotation.Normalize();
Invalidate(invalidation);
return *this;
}
void Node::SetParent(const Node* node, bool keepDerived, Invalidation invalidation)
{
#if NAZARA_CORE_SAFE
@ -122,7 +45,7 @@ namespace Nz
if (keepDerived)
{
EnsureDerivedUpdate();
EnsureGlobalsUpdate();
if (m_parent)
m_parent->RemoveChild(this);
@ -131,9 +54,9 @@ namespace Nz
if (m_parent)
m_parent->AddChild(this);
SetRotation(m_derivedRotation, CoordSys::Global, Invalidation::DontInvalidate);
SetScale(m_derivedScale, CoordSys::Global, Invalidation::DontInvalidate);
SetPosition(m_derivedPosition, CoordSys::Global, Invalidation::DontInvalidate);
SetGlobalPosition(m_globalPosition, Invalidation::DontInvalidate);
SetGlobalRotation(m_globalRotation, Invalidation::DontInvalidate);
SetGlobalScale(m_globalScale, Invalidation::DontInvalidate);
Invalidate(invalidation);
}
@ -152,157 +75,6 @@ namespace Nz
OnParenting(node);
}
void Node::SetPosition(const Vector3f& position, CoordSys coordSys, Invalidation invalidation)
{
switch (coordSys)
{
case CoordSys::Global:
{
if (m_parent && m_inheritPosition)
{
m_parent->EnsureDerivedUpdate();
m_position = (m_parent->m_derivedRotation.GetConjugate() * (position - m_parent->m_derivedPosition)) / m_parent->m_derivedScale - m_initialPosition;
}
else
m_position = position - m_initialPosition;
break;
}
case CoordSys::Local:
m_position = position;
break;
}
Invalidate(invalidation);
}
void Node::SetRotation(const Quaternionf& rotation, CoordSys coordSys, Invalidation invalidation)
{
switch (coordSys)
{
case CoordSys::Global:
if (m_parent && m_inheritRotation)
{
Quaternionf rot(m_parent->GetRotation() * m_initialRotation);
m_rotation = rot.GetConjugate() * rotation;
}
else
m_rotation = rotation;
break;
case CoordSys::Local:
m_rotation = rotation;
break;
}
Invalidate(invalidation);
}
void Node::SetScale(const Vector3f& scale, CoordSys coordSys, Invalidation invalidation)
{
switch (coordSys)
{
case CoordSys::Global:
if (m_parent && m_inheritScale)
m_scale = scale / (m_initialScale * m_parent->GetScale());
else
m_scale = scale / m_initialScale;
break;
case CoordSys::Local:
m_scale = scale;
break;
}
Invalidate(invalidation);
}
void Node::SetTransform(const Vector3f& position, const Quaternionf& rotation, CoordSys coordSys, Invalidation invalidation)
{
switch (coordSys)
{
case CoordSys::Global:
{
// Position
if (m_parent && m_inheritPosition)
{
m_parent->EnsureDerivedUpdate();
m_position = (m_parent->m_derivedRotation.GetConjugate() * (position - m_parent->m_derivedPosition)) / m_parent->m_derivedScale - m_initialPosition;
}
else
m_position = position - m_initialPosition;
// Rotation
if (m_parent && m_inheritRotation)
{
Quaternionf rot(m_parent->GetRotation() * m_initialRotation);
m_rotation = rot.GetConjugate() * rotation;
}
else
m_rotation = rotation;
break;
}
case CoordSys::Local:
m_position = position;
m_rotation = rotation;
break;
}
Invalidate(invalidation);
}
void Node::SetTransform(const Vector3f& position, const Quaternionf& rotation, const Vector3f& scale, CoordSys coordSys, Invalidation invalidation)
{
switch (coordSys)
{
case CoordSys::Global:
{
// Position
if (m_parent && m_inheritPosition)
{
m_parent->EnsureDerivedUpdate();
m_position = (m_parent->m_derivedRotation.GetConjugate() * (position - m_parent->m_derivedPosition)) / m_parent->m_derivedScale - m_initialPosition;
}
else
m_position = position - m_initialPosition;
// Rotation
if (m_parent && m_inheritRotation)
{
Quaternionf rot(m_parent->GetRotation() * m_initialRotation);
m_rotation = rot.GetConjugate() * rotation;
}
else
m_rotation = rotation;
// Scale
if (m_parent && m_inheritScale)
m_scale = scale / (m_initialScale * m_parent->GetScale());
else
m_scale = scale / m_initialScale;
break;
}
case CoordSys::Local:
m_position = position;
m_rotation = rotation;
m_scale = scale;
break;
}
Invalidate(invalidation);
}
void Node::InvalidateNode(Invalidation invalidation)
{
m_derivedUpdated = false;
@ -326,34 +98,34 @@ namespace Nz
{
if (m_parent)
{
m_parent->EnsureDerivedUpdate();
m_parent->EnsureGlobalsUpdate();
if (m_inheritPosition)
m_derivedPosition = m_parent->m_derivedRotation*(m_parent->m_derivedScale * (m_initialPosition + m_position)) + m_parent->m_derivedPosition;
if (m_doesInheritPosition)
m_globalPosition = m_parent->m_globalRotation*(m_parent->m_globalScale * (m_initialPosition + m_position)) + m_parent->m_globalPosition;
else
m_derivedPosition = m_initialPosition + m_position;
m_globalPosition = m_initialPosition + m_position;
if (m_inheritRotation)
if (m_doesInheritRotation)
{
Quaternionf rotation = m_initialRotation * m_rotation;
if (m_inheritScale)
rotation = Quaternionf::Mirror(rotation, m_parent->m_derivedScale);
if (m_doesInheritScale)
rotation = Quaternionf::Mirror(rotation, m_parent->m_globalScale);
m_derivedRotation = m_parent->m_derivedRotation * rotation;
m_derivedRotation.Normalize();
m_globalRotation = m_parent->m_globalRotation * rotation;
m_globalRotation.Normalize();
}
else
m_derivedRotation = m_initialRotation * m_rotation;
m_globalRotation = m_initialRotation * m_rotation;
m_derivedScale = m_initialScale * m_scale;
if (m_inheritScale)
m_derivedScale *= m_parent->m_derivedScale;
m_globalScale = m_initialScale * m_scale;
if (m_doesInheritScale)
m_globalScale *= m_parent->m_globalScale;
}
else
{
m_derivedPosition = m_initialPosition + m_position;
m_derivedRotation = m_initialRotation * m_rotation;
m_derivedScale = m_initialScale * m_scale;
m_globalPosition = m_initialPosition + m_position;
m_globalRotation = m_initialRotation * m_rotation;
m_globalScale = m_initialScale * m_scale;
}
m_derivedUpdated = true;
@ -361,9 +133,9 @@ namespace Nz
void Node::UpdateTransformMatrix() const
{
EnsureDerivedUpdate();
EnsureGlobalsUpdate();
m_transformMatrix = Matrix4f::Transform(m_derivedPosition, m_derivedRotation, m_derivedScale);
m_transformMatrix = Matrix4f::Transform(m_globalPosition, m_globalRotation, m_globalScale);
m_transformMatrixUpdated = true;
}
}

View File

@ -173,8 +173,9 @@ namespace Nz
const Joint* jointsA = &skeletonA.m_impl->joints[0];
const Joint* jointsB = &skeletonB.m_impl->joints[0];
for (std::size_t i = 0; i < m_impl->joints.size(); ++i)
m_impl->joints[i].Interpolate(jointsA[i], jointsB[i], interpolation, CoordSys::Local);
m_impl->joints[i].Interpolate(jointsA[i], jointsB[i], interpolation, Node::Invalidation::DontInvalidate);
GetRootJoint()->Invalidate();
InvalidateJoints();
}
@ -192,9 +193,10 @@ namespace Nz
std::size_t index = indices[i];
NazaraAssert(index < m_impl->joints.size(), "joint index out of range");
m_impl->joints[index].Interpolate(jointsA[index], jointsB[index], interpolation, CoordSys::Local);
m_impl->joints[index].Interpolate(jointsA[index], jointsB[index], interpolation, Node::Invalidation::DontInvalidate);
}
GetRootJoint()->Invalidate();
InvalidateJoints();
}

View File

@ -291,11 +291,11 @@ namespace Nz
const NodeComponent& entityNode = m_registry.get<const NodeComponent>(entity);
CameraComponent& entityCamera = m_registry.get<CameraComponent>(entity);
Vector3f cameraPosition = entityNode.GetPosition(CoordSys::Global);
Vector3f cameraPosition = entityNode.GetGlobalPosition();
ViewerInstance& viewerInstance = entityCamera.GetViewerInstance();
viewerInstance.UpdateEyePosition(cameraPosition);
viewerInstance.UpdateViewMatrix(Nz::Matrix4f::TransformInverse(cameraPosition, entityNode.GetRotation(CoordSys::Global)));
viewerInstance.UpdateViewMatrix(Nz::Matrix4f::TransformInverse(cameraPosition, entityNode.GetGlobalRotation()));
}
m_invalidatedCameraNode.clear();
@ -318,9 +318,9 @@ namespace Nz
const NodeComponent& entityNode = m_registry.get<const NodeComponent>(entity);
LightComponent& entityLight = m_registry.get<LightComponent>(entity);
const Vector3f& position = entityNode.GetPosition(CoordSys::Global);
const Quaternionf& rotation = entityNode.GetRotation(CoordSys::Global);
const Vector3f& scale = entityNode.GetScale(CoordSys::Global);
const Vector3f& position = entityNode.GetGlobalPosition();
const Quaternionf& rotation = entityNode.GetGlobalRotation();
const Vector3f& scale = entityNode.GetGlobalScale();
for (const auto& lightEntry : entityLight.GetLights())
{

View File

@ -100,7 +100,7 @@ namespace Nz
const Joint* joint = skeleton.GetJoint(i);
const Node* parent = joint->GetParent();
if (parent)
DrawLine(joint->GetPosition(CoordSys::Global), parent->GetPosition(CoordSys::Global), color);
DrawLine(joint->GetGlobalPosition(), parent->GetGlobalPosition(), color);
}
}

View File

@ -42,7 +42,7 @@ namespace Nz
gfxComponent.AttachRenderable(m_textSprite, GetCanvas()->GetRenderMask());
auto& textNode = registry.get<NodeComponent>(m_textEntity);
textNode.SetPosition(s_textAreaPaddingWidth, GetHeight() - s_textAreaPaddingHeight);
textNode.SetPosition({ s_textAreaPaddingWidth, GetHeight() - s_textAreaPaddingHeight });
SetCursor(SystemCursor::Text);
@ -84,7 +84,7 @@ namespace Nz
const AbstractTextDrawer& textDrawer = GetTextDrawer();
auto& textNode = GetRegistry().get<NodeComponent>(m_textEntity);
Vector2f textPosition = Vector2f(textNode.GetPosition(CoordSys::Local));
Vector2f textPosition = Vector2f(textNode.GetPosition());
x -= textPosition.x;
y -= textPosition.y;
@ -627,19 +627,19 @@ namespace Nz
float glyphWidth = (lastGlyph) ? lastGlyph->bounds.width : 0.f;
auto& textNode = registry.get<NodeComponent>(m_textEntity);
float textPosition = textNode.GetPosition(CoordSys::Local).x - s_textAreaPaddingWidth;
float textPosition = textNode.GetPosition().x - s_textAreaPaddingWidth;
float cursorPosition = glyphPos + textPosition + ((overshooting) ? glyphWidth : 0.f);
float width = GetWidth();
if (width <= textDrawer.GetBounds().width)
{
if (cursorPosition + glyphWidth > width)
textNode.Move(width - cursorPosition - glyphWidth - s_textAreaPaddingWidth, 0.f);
textNode.Move({ width - cursorPosition - glyphWidth - s_textAreaPaddingWidth, 0.f });
else if (cursorPosition - glyphWidth < 0.f)
textNode.Move(-cursorPosition + glyphWidth - s_textAreaPaddingWidth, 0.f);
textNode.Move({ -cursorPosition + glyphWidth - s_textAreaPaddingWidth, 0.f });
}
else
textNode.Move(-textPosition, 0.f); //< Reset text position if we have enough room to show everything
textNode.Move({ -textPosition, 0.f }); //< Reset text position if we have enough room to show everything
// Create/destroy cursor entities and sprites
std::size_t selectionLineCount = m_cursorPositionEnd.y - m_cursorPositionBegin.y + 1;
@ -697,14 +697,14 @@ namespace Nz
cursor.sprite->SetSize(Vector2f(spriteSize, lineInfo.bounds.height));
registry.get<NodeComponent>(cursor.entity).SetPosition(beginX, textHeight - lineInfo.bounds.y - lineInfo.bounds.height);
registry.get<NodeComponent>(cursor.entity).SetPosition({ beginX, textHeight - lineInfo.bounds.y - lineInfo.bounds.height });
}
else
{
// Full line selection
cursor.sprite->SetSize(Vector2f(lineInfo.bounds.width, lineInfo.bounds.height));
registry.get<NodeComponent>(cursor.entity).SetPosition(0.f, textHeight - lineInfo.bounds.y - lineInfo.bounds.height);
registry.get<NodeComponent>(cursor.entity).SetPosition({ 0.f, textHeight - lineInfo.bounds.y - lineInfo.bounds.height });
}
}
}
@ -724,6 +724,6 @@ namespace Nz
Vector2f textSize = Vector2f(m_textSprite->GetAABB().GetLengths());
auto& textNode = GetRegistry().get<NodeComponent>(m_textEntity);
textNode.SetPosition(s_textAreaPaddingWidth, GetHeight() - s_textAreaPaddingHeight - textSize.y);
textNode.SetPosition({ s_textAreaPaddingWidth, GetHeight() - s_textAreaPaddingHeight - textSize.y });
}
}

View File

@ -306,7 +306,7 @@ namespace Nz
Rectf BaseWidget::GetScissorRect() const
{
Vector2f widgetPos = Vector2f(GetPosition(CoordSys::Global));
Vector2f widgetPos = Vector2f(GetGlobalPosition());
Vector2f widgetSize = GetSize();
Rectf widgetRect(widgetPos.x, widgetPos.y, widgetSize.x, widgetSize.y);

View File

@ -25,7 +25,7 @@ namespace Nz
{
float contentPosition = (GetHeight() - m_content->GetHeight()) * (1.f - newValue);
m_content->SetPosition(0.f, contentPosition);
m_content->SetPosition({ 0.f, contentPosition });
m_content->SetRenderingRect(Nz::Rectf(-std::numeric_limits<float>::infinity(), -contentPosition, std::numeric_limits<float>::infinity(), GetHeight()));
});
@ -78,7 +78,7 @@ namespace Nz
if (m_isScrollbarEnabled)
m_horizontalScrollbar->Show();
m_horizontalScrollbar->SetPosition(contentSize.x, 0.f);
m_horizontalScrollbar->SetPosition({ contentSize.x, 0.f, 0.f });
m_horizontalScrollbar->Resize({ scrollBarWidth, GetHeight() });
ScrollToRatio(m_horizontalScrollbar->GetValue());

View File

@ -108,19 +108,19 @@ namespace Nz
{
m_scrollBackButton->Resize({ size.y, size.y });
m_scrollNextButton->Resize({ size.y, size.y });
m_scrollNextButton->SetPosition({ GetWidth() - m_scrollNextButton->GetWidth(), 0.f, 0.f });
m_scrollNextButton->SetPosition({ GetWidth() - m_scrollNextButton->GetWidth(), 0.f });
float start = m_scrollBackButton->GetWidth();
float remaining = size.x - start - m_scrollNextButton->GetWidth();
float centerPosition = start + invValuePct * (remaining - remaining * stepPct);
m_scrollCenterButton->Resize({ remaining * stepPct, size.y });
m_scrollCenterButton->SetPosition(start + centerPosition, 0.f);
m_scrollCenterButton->SetPosition({ start + centerPosition, 0.f });
}
else
{
m_scrollBackButton->Resize({ size.x, size.x });
m_scrollBackButton->SetPosition({ 0.f, GetHeight() - m_scrollBackButton->GetHeight(), 0.f });
m_scrollBackButton->SetPosition({ 0.f, GetHeight() - m_scrollBackButton->GetHeight() });
m_scrollNextButton->Resize({ size.x, size.x });
float start = m_scrollBackButton->GetHeight();
@ -128,7 +128,7 @@ namespace Nz
float centerPosition = start + invValuePct * (remaining - remaining * stepPct);
m_scrollCenterButton->Resize({ size.x, remaining * stepPct });
m_scrollCenterButton->SetPosition(0.f, centerPosition);
m_scrollCenterButton->SetPosition({ 0.f, centerPosition });
}
m_style->Layout(size);

View File

@ -56,7 +56,7 @@ namespace Nz
entt::registry& registry = GetRegistry();
Boxf textBox = m_textSprite->GetAABB();
registry.get<NodeComponent>(m_textEntity).SetPosition(size.x / 2.f - textBox.width / 2.f, size.y / 2.f - textBox.height / 2.f);
registry.get<NodeComponent>(m_textEntity).SetPosition({ size.x / 2.f - textBox.width / 2.f, size.y / 2.f - textBox.height / 2.f });
}
void SimpleButtonWidgetStyle::OnHoverBegin()
@ -150,7 +150,7 @@ namespace Nz
Vector2f checkSize = size * 0.66f;
m_checkSprite->SetSize(checkSize);
GetRegistry().get<NodeComponent>(m_checkEntity).SetPosition(size.x / 2.f - checkSize.x / 2.f, size.y / 2.f - checkSize.y / 2.f);
GetRegistry().get<NodeComponent>(m_checkEntity).SetPosition({ size.x / 2.f - checkSize.x / 2.f, size.y / 2.f - checkSize.y / 2.f });
}
void SimpleCheckboxWidgetStyle::OnHoverBegin()
@ -363,7 +363,7 @@ namespace Nz
entt::registry& registry = GetRegistry();
Boxf textBox = m_textSprite->GetAABB();
registry.get<NodeComponent>(m_entity).SetPosition(size.x / 2.f - textBox.width / 2.f, size.y / 2.f - textBox.height / 2.f);
registry.get<NodeComponent>(m_entity).SetPosition({ size.x / 2.f - textBox.width / 2.f, size.y / 2.f - textBox.height / 2.f });
}
void SimpleLabelWidgetStyle::OnHoverBegin()
@ -426,7 +426,7 @@ namespace Nz
m_barEntity = CreateGraphicsEntity();
registry.get<GraphicsComponent>(m_barEntity).AttachRenderable(m_progressBarSprite, renderMask);
registry.get<NodeComponent>(m_barEntity).SetPosition(m_barOffset, m_barOffset);
registry.get<NodeComponent>(m_barEntity).SetPosition({ m_barOffset, m_barOffset });
}
void SimpleProgressBarWidgetStyle::Layout(const Vector2f& size)

View File

@ -165,7 +165,7 @@ int main()
float delta = (accumulatorTime.AsSeconds() / timeToMove.AsSeconds());
spriteEntity.get<Nz::NodeComponent>().SetPosition(Nz::Lerp(128.f / 2.f, windowSize.x - 128.f / 2.f, delta * delta * (3.f - 2.f * delta)), windowSize.y / 2.f, 0.f);
spriteEntity.get<Nz::NodeComponent>().SetPosition({ Nz::Lerp(128.f / 2.f, windowSize.x - 128.f / 2.f, delta * delta * (3.f - 2.f * delta)), windowSize.y / 2.f });
// Limit FPS
if (limitFps)