- TEST_SPEC.md: Updated test directory structure to reflect Core/Asset, Core/IO, and Resources/<Type> subdirectories - TEST_SPEC.md: Updated module names and test counts (852 total) - TEST_SPEC.md: Updated build commands for new Resources subdirectories - README.md: Updated engine structure with Core/Asset/ and Core/IO/ - README.md: Updated Resources section with layered architecture - README.md: Updated test coverage table with accurate counts
107 lines
3.6 KiB
C++
107 lines
3.6 KiB
C++
#pragma once
|
|
|
|
#include "Component.h"
|
|
#include <XCEngine/Core/Math/Vector3.h>
|
|
#include <XCEngine/Core/Math/Quaternion.h>
|
|
#include <XCEngine/Core/Math/Matrix4.h>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <istream>
|
|
|
|
namespace XCEngine {
|
|
namespace Components {
|
|
|
|
class GameObject;
|
|
class Scene;
|
|
|
|
enum class Space {
|
|
Self,
|
|
World
|
|
};
|
|
|
|
class TransformComponent : public Component {
|
|
public:
|
|
TransformComponent();
|
|
~TransformComponent() override = default;
|
|
|
|
std::string GetName() const override { return "Transform"; }
|
|
|
|
void Serialize(std::ostream& os) const override;
|
|
void Deserialize(std::istream& is) override;
|
|
|
|
const Math::Vector3& GetLocalPosition() const { return m_localPosition; }
|
|
void SetLocalPosition(const Math::Vector3& position) { m_localPosition = position; SetDirty(); }
|
|
|
|
const Math::Quaternion& GetLocalRotation() const { return m_localRotation; }
|
|
void SetLocalRotation(const Math::Quaternion& rotation) { m_localRotation = rotation; SetDirty(); }
|
|
|
|
const Math::Vector3& GetLocalScale() const { return m_localScale; }
|
|
void SetLocalScale(const Math::Vector3& scale) { m_localScale = scale; SetDirty(); }
|
|
|
|
Math::Vector3 GetLocalEulerAngles() const;
|
|
void SetLocalEulerAngles(const Math::Vector3& eulers);
|
|
|
|
Math::Vector3 GetPosition() const;
|
|
void SetPosition(const Math::Vector3& position);
|
|
|
|
Math::Quaternion GetRotation() const;
|
|
void SetRotation(const Math::Quaternion& rotation);
|
|
|
|
Math::Vector3 GetScale() const;
|
|
void SetScale(const Math::Vector3& scale);
|
|
|
|
Math::Vector3 GetForward() const;
|
|
Math::Vector3 GetRight() const;
|
|
Math::Vector3 GetUp() const;
|
|
|
|
const Math::Matrix4x4& GetLocalToWorldMatrix() const;
|
|
Math::Matrix4x4 GetWorldToLocalMatrix() const;
|
|
|
|
TransformComponent* GetParent() const { return m_parent; }
|
|
void SetParent(TransformComponent* parent, bool worldPositionStays = true);
|
|
|
|
size_t GetChildCount() const { return m_children.size(); }
|
|
TransformComponent* GetChild(size_t index) const;
|
|
TransformComponent* Find(const std::string& name) const;
|
|
void DetachChildren();
|
|
|
|
int GetSiblingIndex() const { return m_siblingIndex; }
|
|
void SetSiblingIndex(int index);
|
|
void SetAsFirstSibling();
|
|
void SetAsLastSibling();
|
|
|
|
void LookAt(const Math::Vector3& target);
|
|
void LookAt(const Math::Vector3& target, const Math::Vector3& up);
|
|
void Rotate(const Math::Vector3& eulers, Space relativeTo = Space::Self);
|
|
void Rotate(const Math::Vector3& axis, float angle, Space relativeTo = Space::Self);
|
|
void Translate(const Math::Vector3& translation, Space relativeTo = Space::Self);
|
|
|
|
Math::Vector3 TransformPoint(const Math::Vector3& point) const;
|
|
Math::Vector3 InverseTransformPoint(const Math::Vector3& point) const;
|
|
Math::Vector3 TransformDirection(const Math::Vector3& direction) const;
|
|
Math::Vector3 InverseTransformDirection(const Math::Vector3& direction) const;
|
|
|
|
void SetDirty();
|
|
void UpdateWorldTransform() const;
|
|
void NotifyHierarchyChanged();
|
|
|
|
private:
|
|
Math::Vector3 m_localPosition = Math::Vector3::Zero();
|
|
Math::Quaternion m_localRotation = Math::Quaternion::Identity();
|
|
Math::Vector3 m_localScale = Math::Vector3::One();
|
|
|
|
TransformComponent* m_parent = nullptr;
|
|
std::vector<TransformComponent*> m_children;
|
|
|
|
mutable Math::Matrix4x4 m_localToWorldMatrix;
|
|
mutable Math::Vector3 m_worldPosition;
|
|
mutable Math::Quaternion m_worldRotation;
|
|
mutable Math::Vector3 m_worldScale;
|
|
mutable bool m_dirty = true;
|
|
int m_siblingIndex = 0;
|
|
|
|
friend class GameObject;
|
|
};
|
|
|
|
} // namespace Components
|
|
} // namespace XCEngine
|