2015-08-16 04:29:37 +00:00
|
|
|
#ifndef CGIZMO_H
|
|
|
|
#define CGIZMO_H
|
|
|
|
|
2015-08-20 01:01:58 +00:00
|
|
|
#include <Common/CPlane.h>
|
2015-08-16 04:29:37 +00:00
|
|
|
#include <Common/CQuaternion.h>
|
2015-08-20 01:01:58 +00:00
|
|
|
#include <Common/CVector3f.h>
|
2015-08-16 04:29:37 +00:00
|
|
|
#include <Common/EnumUtil.h>
|
2015-08-24 01:02:14 +00:00
|
|
|
#include <Common/ETransformSpace.h>
|
2015-08-16 04:29:37 +00:00
|
|
|
#include <Core/CCamera.h>
|
|
|
|
#include <Core/CToken.h>
|
|
|
|
#include <Core/IRenderable.h>
|
|
|
|
#include <Resource/model/CModel.h>
|
|
|
|
|
|
|
|
#define CGIZMO_TRANSLATE_X 0
|
|
|
|
#define CGIZMO_TRANSLATE_Y 1
|
|
|
|
#define CGIZMO_TRANSLATE_Z 2
|
2015-08-17 18:10:42 +00:00
|
|
|
#define CGIZMO_TRANSLATE_LINES_XY 3
|
|
|
|
#define CGIZMO_TRANSLATE_LINES_XZ 4
|
|
|
|
#define CGIZMO_TRANSLATE_LINES_YZ 5
|
|
|
|
#define CGIZMO_TRANSLATE_POLY_XY 6
|
|
|
|
#define CGIZMO_TRANSLATE_POLY_XZ 7
|
|
|
|
#define CGIZMO_TRANSLATE_POLY_YZ 8
|
2015-08-24 01:02:14 +00:00
|
|
|
#define CGIZMO_ROTATE_OUTLINE 0
|
|
|
|
#define CGIZMO_ROTATE_X 1
|
|
|
|
#define CGIZMO_ROTATE_Y 2
|
|
|
|
#define CGIZMO_ROTATE_Z 3
|
|
|
|
#define CGIZMO_ROTATE_XYZ 4
|
2015-08-16 04:29:37 +00:00
|
|
|
#define CGIZMO_SCALE_X 0
|
|
|
|
#define CGIZMO_SCALE_Y 1
|
|
|
|
#define CGIZMO_SCALE_Z 2
|
2015-08-17 18:10:42 +00:00
|
|
|
#define CGIZMO_SCALE_LINES_XY 3
|
|
|
|
#define CGIZMO_SCALE_LINES_XZ 4
|
|
|
|
#define CGIZMO_SCALE_LINES_YZ 5
|
|
|
|
#define CGIZMO_SCALE_POLY_XY 6
|
|
|
|
#define CGIZMO_SCALE_POLY_XZ 7
|
|
|
|
#define CGIZMO_SCALE_POLY_YZ 8
|
|
|
|
#define CGIZMO_SCALE_XYZ 9
|
2015-08-16 04:29:37 +00:00
|
|
|
|
|
|
|
class CGizmo : public IRenderable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum EGizmoMode
|
|
|
|
{
|
2015-09-01 17:05:48 +00:00
|
|
|
eTranslate, eRotate, eScale, eOff
|
2015-08-16 04:29:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum EGizmoAxes
|
|
|
|
{
|
|
|
|
eNone = 0x0,
|
|
|
|
eX = 0x1,
|
|
|
|
eY = 0x2,
|
|
|
|
eZ = 0x4,
|
|
|
|
eXY = eX | eY,
|
|
|
|
eXZ = eX | eZ,
|
|
|
|
eYZ = eY | eZ,
|
|
|
|
eXYZ = eX | eY | eZ
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
EGizmoMode mMode;
|
|
|
|
EGizmoAxes mSelectedAxes;
|
2015-08-24 01:02:14 +00:00
|
|
|
ETransformSpace mTransformSpace;
|
2015-08-16 04:29:37 +00:00
|
|
|
CQuaternion mBillboardRotation;
|
|
|
|
float mGizmoSize;
|
|
|
|
float mCameraDist;
|
2015-08-24 01:02:14 +00:00
|
|
|
bool mIsTransforming;
|
|
|
|
bool mHasTransformed;
|
|
|
|
CVector2f mWrapOffset;
|
|
|
|
bool mEnableCursorWrap;
|
2015-08-16 04:29:37 +00:00
|
|
|
|
2015-09-01 17:05:48 +00:00
|
|
|
// Transform
|
2015-08-16 04:29:37 +00:00
|
|
|
CTransform4f mTransform;
|
2015-08-28 22:57:24 +00:00
|
|
|
CTransform4f mBillboardTransform;
|
|
|
|
CTransform4f mScaledTransform;
|
2015-08-16 04:29:37 +00:00
|
|
|
CVector3f mPosition;
|
2015-08-28 22:57:24 +00:00
|
|
|
CQuaternion mRotation;
|
|
|
|
CQuaternion mLocalRotation;
|
|
|
|
CVector3f mScale;
|
|
|
|
bool mFlipScaleX;
|
|
|
|
bool mFlipScaleY;
|
|
|
|
bool mFlipScaleZ;
|
|
|
|
|
2015-09-01 17:05:48 +00:00
|
|
|
// Delta transform
|
2015-08-20 01:01:58 +00:00
|
|
|
CVector3f mDeltaTranslation;
|
|
|
|
CVector3f mTotalTranslation;
|
2015-08-16 04:29:37 +00:00
|
|
|
CQuaternion mDeltaRotation;
|
2015-08-24 01:02:14 +00:00
|
|
|
CQuaternion mCurrentRotation;
|
|
|
|
CVector3f mTotalRotation; // This is a CVector3f because this value displays on the UI and a quat would cause rollover
|
2015-08-16 04:29:37 +00:00
|
|
|
CVector3f mDeltaScale;
|
2015-08-20 01:01:58 +00:00
|
|
|
CVector3f mTotalScale;
|
2015-08-16 04:29:37 +00:00
|
|
|
|
2015-09-01 17:05:48 +00:00
|
|
|
// Transform helpers
|
2015-08-20 01:01:58 +00:00
|
|
|
CPlane mTranslatePlane;
|
|
|
|
CVector3f mTranslateOffset;
|
2015-08-24 01:02:14 +00:00
|
|
|
float mRotateOffset;
|
2015-08-28 22:57:24 +00:00
|
|
|
float mScaleOffset;
|
2015-08-20 01:01:58 +00:00
|
|
|
bool mSetOffset;
|
2015-08-28 22:57:24 +00:00
|
|
|
CVector3f mHitPoint;
|
|
|
|
CVector3f mMoveDir;
|
2015-08-20 01:01:58 +00:00
|
|
|
|
2015-09-01 17:05:48 +00:00
|
|
|
// Model parts
|
2015-08-16 04:29:37 +00:00
|
|
|
struct SModelPart
|
|
|
|
{
|
|
|
|
EGizmoAxes modelAxes;
|
2015-08-17 18:10:42 +00:00
|
|
|
bool enableRayCast;
|
2015-08-24 01:02:14 +00:00
|
|
|
bool isBillboard;
|
2015-08-16 04:29:37 +00:00
|
|
|
CModel *pModel;
|
|
|
|
CToken modelToken;
|
|
|
|
|
|
|
|
SModelPart() {}
|
2015-08-24 01:02:14 +00:00
|
|
|
SModelPart(EGizmoAxes axes, bool rayCastOn, bool billboard, CModel *_pModel) :
|
|
|
|
modelAxes(axes), enableRayCast(rayCastOn), isBillboard(billboard), pModel(_pModel), modelToken(_pModel) {}
|
2015-08-16 04:29:37 +00:00
|
|
|
};
|
2015-08-17 18:10:42 +00:00
|
|
|
SModelPart *mpCurrentParts;
|
|
|
|
u32 mNumCurrentParts;
|
2015-08-16 04:29:37 +00:00
|
|
|
|
2015-08-17 18:10:42 +00:00
|
|
|
// Static
|
2015-08-16 04:29:37 +00:00
|
|
|
static bool smModelsLoaded;
|
2015-08-17 18:10:42 +00:00
|
|
|
static SModelPart smTranslateModels[9];
|
2015-08-24 01:02:14 +00:00
|
|
|
static SModelPart smRotateModels[5];
|
2015-08-17 18:10:42 +00:00
|
|
|
static SModelPart smScaleModels[10];
|
2015-08-16 04:29:37 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CGizmo();
|
|
|
|
~CGizmo();
|
2015-08-17 18:10:42 +00:00
|
|
|
|
2015-09-27 22:02:53 +00:00
|
|
|
void AddToRenderer(CRenderer *pRenderer, const CFrustumPlanes& frustum);
|
2015-08-16 04:29:37 +00:00
|
|
|
void DrawAsset(ERenderOptions options, u32 asset);
|
|
|
|
|
|
|
|
void IncrementSize();
|
|
|
|
void DecrementSize();
|
|
|
|
void UpdateForCamera(const CCamera& camera);
|
2015-08-20 01:01:58 +00:00
|
|
|
bool CheckSelectedAxes(const CRay& ray);
|
|
|
|
u32 NumSelectedAxes();
|
|
|
|
void ResetSelectedAxes();
|
|
|
|
void StartTransform();
|
2015-08-24 01:02:14 +00:00
|
|
|
bool TransformFromInput(const CRay& ray, CCamera& camera);
|
2015-08-20 01:01:58 +00:00
|
|
|
void EndTransform();
|
2015-09-29 10:48:28 +00:00
|
|
|
bool IsTransforming() const;
|
|
|
|
bool HasTransformed() const;
|
|
|
|
|
|
|
|
EGizmoMode Mode() const;
|
|
|
|
ETransformSpace TransformSpace() const;
|
|
|
|
CVector3f Position() const;
|
|
|
|
CVector3f DeltaTranslation() const;
|
|
|
|
CVector3f TotalTranslation() const;
|
|
|
|
CQuaternion Rotation() const;
|
|
|
|
CQuaternion DeltaRotation() const;
|
|
|
|
CVector3f TotalRotation() const;
|
|
|
|
CVector3f Scale() const;
|
|
|
|
CVector3f DeltaScale() const;
|
|
|
|
CVector3f TotalScale() const;
|
2015-08-16 04:29:37 +00:00
|
|
|
void SetMode(EGizmoMode mode);
|
2015-08-24 01:02:14 +00:00
|
|
|
void SetTransformSpace(ETransformSpace space);
|
2015-08-16 04:29:37 +00:00
|
|
|
void SetPosition(const CVector3f& position);
|
2015-08-28 22:57:24 +00:00
|
|
|
void SetLocalRotation(const CQuaternion& orientation);
|
2015-08-24 01:02:14 +00:00
|
|
|
void EnableCursorWrap(bool wrap);
|
2015-08-16 04:29:37 +00:00
|
|
|
|
|
|
|
// Protected
|
|
|
|
protected:
|
|
|
|
void UpdateTransform();
|
2015-08-24 01:02:14 +00:00
|
|
|
void WrapCursor();
|
2015-08-16 04:29:37 +00:00
|
|
|
|
|
|
|
// Private Static
|
|
|
|
private:
|
|
|
|
static void LoadModels();
|
|
|
|
};
|
|
|
|
DEFINE_ENUM_FLAGS(CGizmo::EGizmoAxes)
|
|
|
|
|
|
|
|
#endif // CGIZMO_H
|