transform properties
This commit is contained in:
@@ -39,10 +39,17 @@ namespace uLib {
|
||||
* The cylinder orientation is defined by the Axis property (0=X, 1=Y, 2=Z).
|
||||
* By default, it is aligned with the Y axis (Axis=1).
|
||||
*/
|
||||
class Cylinder : public AffineTransform, public Object {
|
||||
class Cylinder : public AffineTransform {
|
||||
|
||||
public:
|
||||
uLibTypeMacro(Cylinder, Object)
|
||||
uLibTypeMacro(Cylinder, AffineTransform)
|
||||
|
||||
/**
|
||||
* @brief PROPERTIES
|
||||
*/
|
||||
float Radius;
|
||||
float Height;
|
||||
int Axis;
|
||||
|
||||
virtual const char * GetClassName() const override { return "Cylinder"; }
|
||||
|
||||
@@ -51,7 +58,7 @@ public:
|
||||
*/
|
||||
Cylinder() : m_LocalT(this), Radius(1.0), Height(1.0), Axis(1) {
|
||||
ULIB_ACTIVATE_PROPERTIES(*this);
|
||||
UpdateLocalMatrix();
|
||||
this->Sync();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +67,7 @@ public:
|
||||
Cylinder(float radius, float height, int axis = 1)
|
||||
: m_LocalT(this), Radius(radius), Height(height), Axis(axis) {
|
||||
ULIB_ACTIVATE_PROPERTIES(*this);
|
||||
UpdateLocalMatrix();
|
||||
this->Sync();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +76,7 @@ public:
|
||||
Cylinder(const Cylinder ©)
|
||||
: m_LocalT(this), AffineTransform(copy), Radius(copy.Radius), Height(copy.Height), Axis(copy.Axis) {
|
||||
ULIB_ACTIVATE_PROPERTIES(*this);
|
||||
this->UpdateLocalMatrix();
|
||||
this->Sync();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +92,7 @@ public:
|
||||
/** Sets the radius of the cylinder */
|
||||
inline void SetRadius(float r) {
|
||||
Radius = r;
|
||||
UpdateLocalMatrix();
|
||||
this->Sync();
|
||||
}
|
||||
|
||||
/** Gets the radius of the cylinder */
|
||||
@@ -94,7 +101,7 @@ public:
|
||||
/** Sets the height of the cylinder */
|
||||
inline void SetHeight(float h) {
|
||||
Height = h;
|
||||
UpdateLocalMatrix();
|
||||
this->Sync();
|
||||
}
|
||||
|
||||
/** Gets the height of the cylinder */
|
||||
@@ -103,7 +110,7 @@ public:
|
||||
/** Sets the main axis (0=X, 1=Y, 2=Z) */
|
||||
inline void SetAxis(int axis) {
|
||||
Axis = axis;
|
||||
UpdateLocalMatrix();
|
||||
this->Sync();
|
||||
}
|
||||
|
||||
/** Gets the main axis */
|
||||
@@ -157,25 +164,33 @@ public:
|
||||
return Vector3f(r, theta, h);
|
||||
}
|
||||
|
||||
/** Translate using transformation chain */
|
||||
using AffineTransform::Translate;
|
||||
|
||||
/** Rotate using transformation chain */
|
||||
using AffineTransform::Rotate;
|
||||
|
||||
/** Scale using transformation chain */
|
||||
using AffineTransform::Scale;
|
||||
|
||||
signals:
|
||||
/** Signal emitted when properties change */
|
||||
virtual void Updated() override {
|
||||
this->UpdateLocalMatrix();
|
||||
this->Sync();
|
||||
ULIB_SIGNAL_EMIT(Cylinder::Updated);
|
||||
}
|
||||
|
||||
private:
|
||||
/** Recalculates the internal local matrix based on dimensions and axis */
|
||||
void UpdateLocalMatrix() {
|
||||
m_LocalT = AffineTransform(this);
|
||||
if (Axis == 0) m_LocalT.Scale(Vector3f(Height, Radius, Radius));
|
||||
else if (Axis == 1) m_LocalT.Scale(Vector3f(Radius, Height, Radius));
|
||||
else m_LocalT.Scale(Vector3f(Radius, Radius, Height));
|
||||
}
|
||||
/** Synchronizes internal transformation with properties */
|
||||
void Sync() {
|
||||
m_LocalT = AffineTransform(this);
|
||||
if (Axis == 0) m_LocalT.Scale(Vector3f(Height, Radius, Radius));
|
||||
else if (Axis == 1) m_LocalT.Scale(Vector3f(Radius, Height, Radius));
|
||||
else m_LocalT.Scale(Vector3f(Radius, Radius, Height));
|
||||
}
|
||||
|
||||
float Radius;
|
||||
float Height;
|
||||
int Axis;
|
||||
|
||||
private:
|
||||
AffineTransform m_LocalT;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user