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