transform properties
This commit is contained in:
@@ -44,16 +44,17 @@ namespace uLib {
|
||||
* that defines the box's specific origin and size relative to its own
|
||||
* coordinate system.
|
||||
*/
|
||||
class ContainerBox : public AffineTransform, public Object {
|
||||
|
||||
typedef AffineTransform BaseClass;
|
||||
class ContainerBox : public AffineTransform {
|
||||
|
||||
public:
|
||||
uLibTypeMacro(ContainerBox, AffineTransform)
|
||||
|
||||
virtual const char * GetClassName() const override { return "ContainerBox"; }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// PROPERTIES //
|
||||
Property<Vector3f> p_Size;
|
||||
Property<Vector3f> p_Origin;
|
||||
virtual const char * GetClassName() const { return "ContainerBox"; }
|
||||
Vector3f Size;
|
||||
Vector3f Origin;
|
||||
|
||||
/**
|
||||
* @brief Default constructor.
|
||||
@@ -61,10 +62,10 @@ public:
|
||||
*/
|
||||
ContainerBox()
|
||||
: m_LocalT(this), // BaseClass is Parent of m_LocalTransform
|
||||
p_Size(this, "Size", Vector3f(1.0f, 1.0f, 1.0f)),
|
||||
p_Origin(this, "Origin", Vector3f(0.0f, 0.0f, 0.0f)) {
|
||||
Object::connect(&p_Size, &Property<Vector3f>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&p_Origin, &Property<Vector3f>::PropertyChanged, this, &ContainerBox::SyncOrigin);
|
||||
Size(1.0f, 1.0f, 1.0f),
|
||||
Origin(0.0f, 0.0f, 0.0f) {
|
||||
ULIB_ACTIVATE_PROPERTIES(*this);
|
||||
this->Sync();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,11 +74,10 @@ public:
|
||||
*/
|
||||
ContainerBox(const Vector3f &size)
|
||||
: m_LocalT(this),
|
||||
p_Size(this, "Size", size),
|
||||
p_Origin(this, "Origin", Vector3f(0.0f, 0.0f, 0.0f)) {
|
||||
Object::connect(&p_Size, &Property<Vector3f>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&p_Origin, &Property<Vector3f>::PropertyChanged, this, &ContainerBox::SyncOrigin);
|
||||
this->SetSize(size);
|
||||
Size(size),
|
||||
Origin(0.0f, 0.0f, 0.0f) {
|
||||
ULIB_ACTIVATE_PROPERTIES(*this);
|
||||
this->Sync();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,13 +85,21 @@ public:
|
||||
* @param copy The ContainerBox instance to copy from.
|
||||
*/
|
||||
ContainerBox(const ContainerBox ©)
|
||||
: m_LocalT(copy.m_LocalT), // Copy local transform state
|
||||
: m_LocalT(this), // Reset parent to the new object
|
||||
AffineTransform(copy),
|
||||
p_Size(this, "Size", copy.p_Size),
|
||||
p_Origin(this, "Origin", copy.p_Origin) {
|
||||
m_LocalT.SetParent(this); // Reset parent to the new object
|
||||
Object::connect(&p_Size, &Property<Vector3f>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&p_Origin, &Property<Vector3f>::PropertyChanged, this, &ContainerBox::SyncOrigin);
|
||||
Size(copy.Size),
|
||||
Origin(copy.Origin) {
|
||||
ULIB_ACTIVATE_PROPERTIES(*this);
|
||||
this->Sync();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Serialization template for property registration and persistence.
|
||||
*/
|
||||
template <class ArchiveT>
|
||||
void serialize(ArchiveT & ar, const unsigned int version) {
|
||||
ar & HRP(Size);
|
||||
ar & HRP(Origin);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +107,7 @@ public:
|
||||
* @param v The origin position vector.
|
||||
*/
|
||||
void SetOrigin(const Vector3f &v) {
|
||||
p_Origin = v;
|
||||
Origin = v;
|
||||
m_LocalT.SetPosition(v);
|
||||
}
|
||||
|
||||
@@ -115,7 +123,7 @@ public:
|
||||
* @param v The size vector (width, height, depth).
|
||||
*/
|
||||
void SetSize(const Vector3f &v) {
|
||||
p_Size = v;
|
||||
Size = v;
|
||||
Vector3f pos = this->GetOrigin();
|
||||
m_LocalT = AffineTransform(this); // regenerate local transform
|
||||
m_LocalT.Scale(v);
|
||||
@@ -194,26 +202,27 @@ public:
|
||||
}
|
||||
|
||||
/** Translate using transformation chain */
|
||||
using BaseClass::Translate;
|
||||
using AffineTransform::Translate;
|
||||
|
||||
/** Rotate using transformation chain */
|
||||
using BaseClass::Rotate;
|
||||
using AffineTransform::Rotate;
|
||||
|
||||
/** Scale using transformation chain */
|
||||
using BaseClass::Scale;
|
||||
using AffineTransform::Scale;
|
||||
|
||||
signals:
|
||||
|
||||
// signal to emit when the box is updated //
|
||||
virtual void Updated() override { ULIB_SIGNAL_EMIT(ContainerBox::Updated); }
|
||||
|
||||
private slots:
|
||||
void SyncSize() {
|
||||
this->SetSize(p_Size);
|
||||
/** Signal emitted when properties change */
|
||||
virtual void Updated() override {
|
||||
this->Sync();
|
||||
ULIB_SIGNAL_EMIT(ContainerBox::Updated);
|
||||
}
|
||||
|
||||
void SyncOrigin() {
|
||||
this->SetOrigin(p_Origin);
|
||||
private:
|
||||
/** Synchronizes internal transformation with properties */
|
||||
void Sync() {
|
||||
this->SetOrigin(Origin);
|
||||
this->SetSize(Size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user