diff --git a/src/Editor/CGizmo.cpp b/src/Editor/CGizmo.cpp index 58917e8c..99a15791 100644 --- a/src/Editor/CGizmo.cpp +++ b/src/Editor/CGizmo.cpp @@ -11,34 +11,12 @@ #include CGizmo::CGizmo() - : mSelectedAxes(EAxis::None) - , mTransformSpace(ETransformSpace::World) - , mGizmoSize(1.f) - , mCameraDist(0.f) - , mIsTransforming(false) - , mHasTransformed(false) - , mWrapOffset(0.f) - , mEnableCursorWrap(true) - , mPosition(CVector3f::Zero()) - , mRotation(CQuaternion::Identity()) - , mLocalRotation(CQuaternion::Identity()) - , mScale(CVector3f::One()) - , mFlipScaleX(false) - , mFlipScaleY(false) - , mFlipScaleZ(false) - , mDeltaTranslation(CVector3f::Zero()) - , mDeltaRotation(CQuaternion::Identity()) - , mDeltaScale(CVector3f::One()) - , mTotalScale(CVector3f::One()) - , mSetOffset(false) { LoadModels(); SetMode(EGizmoMode::Translate); } -CGizmo::~CGizmo() -{ -} +CGizmo::~CGizmo() = default; void CGizmo::AddToRenderer(CRenderer *pRenderer, const SViewInfo&) { @@ -521,22 +499,22 @@ void CGizmo::SetMode(EGizmoMode Mode) switch (Mode) { case EGizmoMode::Translate: - mpCurrentParts = smTranslateModels; - mNumCurrentParts = CGIZMO_TRANSLATE_NUM; + mpCurrentParts = smTranslateModels.data(); + mNumCurrentParts = smTranslateModels.size(); mDeltaRotation = CQuaternion::Identity(); mDeltaScale = CVector3f::One(); break; case EGizmoMode::Rotate: - mpCurrentParts = smRotateModels; - mNumCurrentParts = CGIZMO_ROTATE_NUM; + mpCurrentParts = smRotateModels.data(); + mNumCurrentParts = smRotateModels.size(); mDeltaTranslation = CVector3f::Zero(); mDeltaScale = CVector3f::One(); break; case EGizmoMode::Scale: - mpCurrentParts = smScaleModels; - mNumCurrentParts = CGIZMO_SCALE_NUM; + mpCurrentParts = smScaleModels.data(); + mNumCurrentParts = smScaleModels.size(); mDeltaTranslation = CVector3f::Zero(); mDeltaRotation = CQuaternion::Identity(); break; @@ -671,9 +649,3 @@ void CGizmo::WrapCursor() mWrapOffset.Y += 2.f; } } - -// ************ STATIC MEMBER INITIALIZATION ************ -bool CGizmo::smModelsLoaded = false; -CGizmo::SModelPart CGizmo::smTranslateModels[CGIZMO_TRANSLATE_NUM]; -CGizmo::SModelPart CGizmo::smRotateModels[CGIZMO_ROTATE_NUM]; -CGizmo::SModelPart CGizmo::smScaleModels[CGIZMO_SCALE_NUM]; diff --git a/src/Editor/CGizmo.h b/src/Editor/CGizmo.h index 27221161..5ee5a477 100644 --- a/src/Editor/CGizmo.h +++ b/src/Editor/CGizmo.h @@ -11,6 +11,7 @@ #include #include #include +#include #define CGIZMO_TRANSLATE_X 0 #define CGIZMO_TRANSLATE_Y 1 @@ -49,74 +50,74 @@ public: }; private: - EGizmoMode mMode; - FAxes mSelectedAxes; - ETransformSpace mTransformSpace; + EGizmoMode mMode{EGizmoMode::Off}; + FAxes mSelectedAxes{EAxis::None}; + ETransformSpace mTransformSpace{ETransformSpace::World}; CQuaternion mBillboardRotation; - float mGizmoSize; - float mCameraDist; - bool mIsTransforming; - bool mHasTransformed; - CVector2f mWrapOffset; - bool mEnableCursorWrap; + float mGizmoSize = 1.0f; + float mCameraDist = 0.0f; + bool mIsTransforming = false; + bool mHasTransformed = false; + CVector2f mWrapOffset{0.0f}; + bool mEnableCursorWrap = true; // Transform CTransform4f mTransform; CTransform4f mBillboardTransform; CTransform4f mScaledTransform; - CVector3f mPosition; - CQuaternion mRotation; - CQuaternion mLocalRotation; - CVector3f mScale; - bool mFlipScaleX; - bool mFlipScaleY; - bool mFlipScaleZ; + CVector3f mPosition{CVector3f::Zero()}; + CQuaternion mRotation{CQuaternion::Identity()}; + CQuaternion mLocalRotation{CQuaternion::Identity()}; + CVector3f mScale{CVector3f::One()}; + bool mFlipScaleX = false; + bool mFlipScaleY = false; + bool mFlipScaleZ = false; // Delta transform - CVector3f mDeltaTranslation; + CVector3f mDeltaTranslation{CVector3f::Zero()}; CVector3f mTotalTranslation; - CQuaternion mDeltaRotation; + CQuaternion mDeltaRotation{CQuaternion::Identity()}; CQuaternion mCurrentRotation; CVector3f mTotalRotation; // This is a CVector3f because this value displays on the UI and a quat would cause rollover - CVector3f mDeltaScale; - CVector3f mTotalScale; + CVector3f mDeltaScale{CVector3f::One()}; + CVector3f mTotalScale{CVector3f::One()}; // Transform helpers CPlane mTranslatePlane; CVector3f mTranslateOffset; - float mRotateOffset; - float mScaleOffset; - bool mSetOffset; + float mRotateOffset = 0.0f; + float mScaleOffset = 0.0f; + bool mSetOffset = false; CVector3f mHitPoint; CVector3f mMoveDir; // Model parts struct SModelPart { - FAxes ModelAxes; - bool EnableRayCast; - bool IsBillboard; + FAxes ModelAxes{EAxis::None}; + bool EnableRayCast = false; + bool IsBillboard = false; TResPtr pModel; - SModelPart() {} + SModelPart() = default; SModelPart(FAxes Axes, bool RayCastOn, bool Billboard, TResPtr _pModel) : ModelAxes(Axes), EnableRayCast(RayCastOn), IsBillboard(Billboard), pModel(_pModel) {} }; - SModelPart *mpCurrentParts; - uint32 mNumCurrentParts; + SModelPart *mpCurrentParts = nullptr; + uint32 mNumCurrentParts = 0; // Static - static bool smModelsLoaded; - static SModelPart smTranslateModels[CGIZMO_TRANSLATE_NUM]; - static SModelPart smRotateModels[CGIZMO_ROTATE_NUM]; - static SModelPart smScaleModels[CGIZMO_SCALE_NUM]; + static inline bool smModelsLoaded = false; + static inline std::array smTranslateModels; + static inline std::array smRotateModels; + static inline std::array smScaleModels; public: CGizmo(); - ~CGizmo(); + ~CGizmo() override; - void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo); - void Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand Command, const SViewInfo& rkViewInfo); + void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) override; + void Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand Command, const SViewInfo& rkViewInfo) override; void IncrementSize(); void DecrementSize(); @@ -129,22 +130,22 @@ public: void EndTransform(); // Accessors - inline EGizmoMode Mode() const { return mMode; } - inline ETransformSpace TransformSpace() const { return mTransformSpace; } - inline CVector3f Position() const { return mPosition; } - inline CVector3f DeltaTranslation() const { return mDeltaTranslation; } - inline CVector3f TotalTranslation() const { return mTotalTranslation; } - inline CQuaternion Rotation() const { return mRotation; } - inline CQuaternion DeltaRotation() const { return mDeltaRotation; } - inline CVector3f TotalRotation() const { return mTotalRotation; } - inline CVector3f Scale() const { return mScale; } - inline CVector3f DeltaScale() const { return mDeltaScale; } - inline CVector3f TotalScale() const { return mTotalScale; } - inline bool IsTransforming() const { return mIsTransforming; } - inline bool HasTransformed() const { return mHasTransformed; } + EGizmoMode Mode() const { return mMode; } + ETransformSpace TransformSpace() const { return mTransformSpace; } + CVector3f Position() const { return mPosition; } + CVector3f DeltaTranslation() const { return mDeltaTranslation; } + CVector3f TotalTranslation() const { return mTotalTranslation; } + CQuaternion Rotation() const { return mRotation; } + CQuaternion DeltaRotation() const { return mDeltaRotation; } + CVector3f TotalRotation() const { return mTotalRotation; } + CVector3f Scale() const { return mScale; } + CVector3f DeltaScale() const { return mDeltaScale; } + CVector3f TotalScale() const { return mTotalScale; } + bool IsTransforming() const { return mIsTransforming; } + bool HasTransformed() const { return mHasTransformed; } - inline void SetPosition(const CVector3f& rkPosition) { mPosition = rkPosition; } - inline void EnableCursorWrap(bool Enable) { mEnableCursorWrap = Enable; } + void SetPosition(const CVector3f& rkPosition) { mPosition = rkPosition; } + void EnableCursorWrap(bool Enable) { mEnableCursorWrap = Enable; } void SetMode(EGizmoMode mode); void SetTransformSpace(ETransformSpace Space); void SetLocalRotation(const CQuaternion& rkOrientation);