diff --git a/src/Editor/CLineRenderable.h b/src/Editor/CLineRenderable.h new file mode 100644 index 00000000..2bcb9961 --- /dev/null +++ b/src/Editor/CLineRenderable.h @@ -0,0 +1,45 @@ +#ifndef CLINERENDERABLE +#define CLINERENDERABLE + +#include +#include +#include +#include +#include + +class CLineRenderable : public IRenderable +{ + CVector3f mPoints[2]; + CColor mColor; + +public: + CLineRenderable() : IRenderable() {} + + inline void SetPoints(const CVector3f& rkPointA, const CVector3f& rkPointB) + { + mPoints[0] = rkPointA; + mPoints[1] = rkPointB; + } + + inline void SetColor(const CColor& rkColor) + { + mColor = rkColor; + } + + void AddToRenderer(CRenderer *pRenderer, const SViewInfo& /*rkViewInfo*/) + { + pRenderer->AddMesh(this, -1, CAABox::skInfinite, false, eDrawMesh); + } + + void Draw(FRenderOptions, int, ERenderCommand, const SViewInfo&) + { + CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity; + CGraphics::UpdateMVPBlock(); + glDepthRange(0.f, 1.f); + glLineWidth(1.f); + CDrawUtil::DrawLine(mPoints[0], mPoints[1], mColor); + } +}; + +#endif // CLINERENDERABLE + diff --git a/src/Editor/CSceneViewport.cpp b/src/Editor/CSceneViewport.cpp index bc406c82..feb5cdba 100644 --- a/src/Editor/CSceneViewport.cpp +++ b/src/Editor/CSceneViewport.cpp @@ -20,6 +20,8 @@ CSceneViewport::CSceneViewport(QWidget *pParent) , mpContextMenu(nullptr) , mpMenuNode(nullptr) { + mLinkLine.SetColor(CColor::skYellow); + mpRenderer = new CRenderer(); mpRenderer->SetClearColor(CColor::skBlack); mpRenderer->SetViewportSize(width(), height()); @@ -317,14 +319,8 @@ void CSceneViewport::Paint() pGizmo->AddToRenderer(mpRenderer, mViewInfo); } - // Draw the line for the link the user is editing. This is a little hacky but I don't really have a better way to do this atm. - if (mLinkLineEnabled) - { - CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity; - CGraphics::UpdateMVPBlock(); - glDepthRange(0.f, 1.f); - CDrawUtil::DrawLine(mLinkLinePoints[0], mLinkLinePoints[1], CColor::skYellow); - } + // Draw the line for the link the user is editing. + if (mLinkLineEnabled) mLinkLine.AddToRenderer(mpRenderer, mViewInfo); mpRenderer->RenderBuckets(mViewInfo); mpRenderer->EndFrame(); diff --git a/src/Editor/CSceneViewport.h b/src/Editor/CSceneViewport.h index 2afe7b41..ebbbb230 100644 --- a/src/Editor/CSceneViewport.h +++ b/src/Editor/CSceneViewport.h @@ -2,6 +2,7 @@ #define CSCENEVIEWPORT_H #include "CBasicViewport.h" +#include "CLineRenderable.h" #include "INodeEditor.h" class CSceneViewport : public CBasicViewport @@ -41,7 +42,7 @@ class CSceneViewport : public CBasicViewport // Link Line bool mLinkLineEnabled; - CVector3f mLinkLinePoints[2]; + CLineRenderable mLinkLine; public: CSceneViewport(QWidget *pParent = 0); @@ -61,13 +62,8 @@ public: void keyPressEvent(QKeyEvent* pEvent); void keyReleaseEvent(QKeyEvent* pEvent); - inline void SetLinkLineEnabled(bool Enable) { mLinkLineEnabled = Enable; } - - inline void SetLinkLine(const CVector3f& rkPointA, const CVector3f& rkPointB) - { - mLinkLinePoints[0] = rkPointA; - mLinkLinePoints[1] = rkPointB; - } + inline void SetLinkLineEnabled(bool Enable) { mLinkLineEnabled = Enable; } + inline void SetLinkLine(const CVector3f& rkPointA, const CVector3f& rkPointB) { mLinkLine.SetPoints(rkPointA, rkPointB); } protected: void CreateContextMenu(); diff --git a/src/Editor/Editor.pro b/src/Editor/Editor.pro index 57168f56..14e7f083 100644 --- a/src/Editor/Editor.pro +++ b/src/Editor/Editor.pro @@ -163,7 +163,8 @@ HEADERS += \ CharacterEditor/CCharacterEditor.h \ CharacterEditor/CCharacterEditorViewport.h \ CGridRenderable.h \ - CharacterEditor/CSkeletonHierarchyModel.h + CharacterEditor/CSkeletonHierarchyModel.h \ + CLineRenderable.h # Source Files SOURCES += \