2017-07-19 23:20:32 +02:00
|
|
|
#pragma once
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_glwidget.h"
|
2014-05-03 23:16:48 +02:00
|
|
|
#include "camera.h"
|
2017-04-02 01:53:54 +02:00
|
|
|
#include "lc_scene.h"
|
2018-10-29 01:59:01 +01:00
|
|
|
#include "lc_viewsphere.h"
|
2018-08-20 05:27:58 +02:00
|
|
|
#include "lc_commands.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2020-02-15 20:36:06 +01:00
|
|
|
enum class lcTrackButton
|
2014-05-18 01:03:05 +02:00
|
|
|
{
|
2020-02-15 20:36:06 +01:00
|
|
|
None,
|
|
|
|
Left,
|
|
|
|
Middle,
|
|
|
|
Right
|
2014-05-18 01:03:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum lcTrackTool
|
|
|
|
{
|
|
|
|
LC_TRACKTOOL_NONE,
|
|
|
|
LC_TRACKTOOL_INSERT,
|
|
|
|
LC_TRACKTOOL_POINTLIGHT,
|
|
|
|
LC_TRACKTOOL_SPOTLIGHT,
|
|
|
|
LC_TRACKTOOL_CAMERA,
|
|
|
|
LC_TRACKTOOL_SELECT,
|
|
|
|
LC_TRACKTOOL_MOVE_X,
|
|
|
|
LC_TRACKTOOL_MOVE_Y,
|
|
|
|
LC_TRACKTOOL_MOVE_Z,
|
|
|
|
LC_TRACKTOOL_MOVE_XY,
|
|
|
|
LC_TRACKTOOL_MOVE_XZ,
|
|
|
|
LC_TRACKTOOL_MOVE_YZ,
|
|
|
|
LC_TRACKTOOL_MOVE_XYZ,
|
|
|
|
LC_TRACKTOOL_ROTATE_X,
|
|
|
|
LC_TRACKTOOL_ROTATE_Y,
|
|
|
|
LC_TRACKTOOL_ROTATE_Z,
|
|
|
|
LC_TRACKTOOL_ROTATE_XY,
|
|
|
|
LC_TRACKTOOL_ROTATE_XYZ,
|
2016-03-12 01:05:49 +01:00
|
|
|
LC_TRACKTOOL_SCALE_PLUS,
|
|
|
|
LC_TRACKTOOL_SCALE_MINUS,
|
2014-05-18 01:03:05 +02:00
|
|
|
LC_TRACKTOOL_ERASER,
|
|
|
|
LC_TRACKTOOL_PAINT,
|
2020-02-15 20:14:12 +01:00
|
|
|
LC_TRACKTOOL_COLOR_PICKER,
|
2014-05-18 01:03:05 +02:00
|
|
|
LC_TRACKTOOL_ZOOM,
|
|
|
|
LC_TRACKTOOL_PAN,
|
|
|
|
LC_TRACKTOOL_ORBIT_X,
|
|
|
|
LC_TRACKTOOL_ORBIT_Y,
|
|
|
|
LC_TRACKTOOL_ORBIT_XY,
|
|
|
|
LC_TRACKTOOL_ROLL,
|
2020-02-15 20:36:06 +01:00
|
|
|
LC_TRACKTOOL_ZOOM_REGION,
|
|
|
|
LC_TRACKTOOL_COUNT
|
2014-05-18 01:03:05 +02:00
|
|
|
};
|
|
|
|
|
2018-01-12 19:50:25 +01:00
|
|
|
enum class lcDragState
|
2014-05-27 00:58:08 +02:00
|
|
|
{
|
2020-02-15 20:36:06 +01:00
|
|
|
None,
|
|
|
|
Piece,
|
|
|
|
Color
|
2014-05-27 00:58:08 +02:00
|
|
|
};
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
class View : public lcGLWidget
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-12-08 08:32:39 +01:00
|
|
|
View(lcModel* Model);
|
2020-03-22 23:44:41 +01:00
|
|
|
~View();
|
2012-02-05 03:50:57 +01:00
|
|
|
|
2018-03-29 19:20:36 +02:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mModel = nullptr;
|
|
|
|
mActiveSubmodelInstance = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
lcModel* GetModel() const
|
|
|
|
{
|
|
|
|
return mModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
lcModel* GetActiveModel() const;
|
2018-10-14 01:45:14 +02:00
|
|
|
void SetTopSubmodelActive();
|
2018-03-29 19:20:36 +02:00
|
|
|
void SetSelectedSubmodelActive();
|
|
|
|
|
2015-04-27 02:47:31 +02:00
|
|
|
static void CreateResources(lcContext* Context);
|
|
|
|
static void DestroyResources(lcContext* Context);
|
|
|
|
|
2020-03-22 23:44:41 +01:00
|
|
|
void OnDraw() override;
|
|
|
|
void OnInitialUpdate() override;
|
|
|
|
void OnUpdateCursor() override;
|
|
|
|
void OnLeftButtonDown() override;
|
|
|
|
void OnLeftButtonUp() override;
|
|
|
|
void OnLeftButtonDoubleClick() override;
|
|
|
|
void OnMiddleButtonDown() override;
|
|
|
|
void OnMiddleButtonUp() override;
|
|
|
|
void OnRightButtonDown() override;
|
|
|
|
void OnRightButtonUp() override;
|
|
|
|
void OnBackButtonUp() override;
|
|
|
|
void OnForwardButtonUp() override;
|
|
|
|
void OnMouseMove() override;
|
|
|
|
void OnMouseWheel(float Direction) override;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2018-09-12 01:36:10 +02:00
|
|
|
bool IsTracking() const
|
|
|
|
{
|
2020-02-15 20:36:06 +01:00
|
|
|
return mTrackButton != lcTrackButton::None;
|
2018-09-12 01:36:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StartOrbitTracking();
|
2014-11-29 03:55:58 +01:00
|
|
|
void CancelTrackingOrClearSelection();
|
2018-01-12 19:50:25 +01:00
|
|
|
void BeginDrag(lcDragState DragState);
|
|
|
|
void EndDrag(bool Accept);
|
2014-11-30 18:53:09 +01:00
|
|
|
|
|
|
|
void SetProjection(bool Ortho);
|
|
|
|
void LookAt();
|
2014-11-08 02:05:17 +01:00
|
|
|
void ZoomExtents();
|
2018-01-15 20:35:15 +01:00
|
|
|
void MoveCamera(const lcVector3& Direction);
|
2019-02-10 01:30:11 +01:00
|
|
|
void Zoom(float Amount);
|
2014-05-27 00:58:08 +02:00
|
|
|
|
2014-11-25 01:51:34 +01:00
|
|
|
void RemoveCamera();
|
2014-11-08 02:05:17 +01:00
|
|
|
void SetCamera(lcCamera* Camera, bool ForceCopy);
|
2017-06-21 06:43:39 +02:00
|
|
|
void SetCamera(const char* CameraName);
|
2014-11-25 01:51:34 +01:00
|
|
|
void SetCameraIndex(int Index);
|
2014-11-08 02:05:17 +01:00
|
|
|
void SetViewpoint(lcViewpoint Viewpoint);
|
2018-08-20 05:27:58 +02:00
|
|
|
void SetViewpoint(const lcVector3& Position);
|
2017-12-14 02:36:35 +01:00
|
|
|
void SetCameraAngles(float Latitude, float Longitude);
|
2012-08-20 06:05:56 +02:00
|
|
|
void SetDefaultCamera();
|
2014-05-03 03:22:24 +02:00
|
|
|
lcMatrix44 GetProjectionMatrix() const;
|
2020-02-15 20:36:06 +01:00
|
|
|
lcCursor GetCursor() const;
|
2015-12-04 21:32:10 +01:00
|
|
|
void ShowContextMenu() const;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-11-30 18:53:09 +01:00
|
|
|
lcVector3 GetMoveDirection(const lcVector3& Direction) const;
|
2017-11-13 04:38:07 +01:00
|
|
|
lcMatrix44 GetPieceInsertPosition(bool IgnoreSelected, PieceInfo* Info) const;
|
2019-08-10 21:31:28 +02:00
|
|
|
lcVector3 GetCameraLightInsertPosition() const;
|
2016-03-03 01:04:49 +01:00
|
|
|
void GetRayUnderPointer(lcVector3& Start, lcVector3& End) const;
|
2017-11-13 04:38:07 +01:00
|
|
|
lcObjectSection FindObjectUnderPointer(bool PiecesOnly, bool IgnoreSelected) const;
|
2014-11-29 03:55:58 +01:00
|
|
|
lcArray<lcObject*> FindObjectsInBox(float x1, float y1, float x2, float y2) const;
|
2014-05-03 18:59:57 +02:00
|
|
|
|
2014-05-18 01:03:05 +02:00
|
|
|
lcCamera* mCamera;
|
2013-12-17 03:43:16 +01:00
|
|
|
|
2014-05-03 08:08:52 +02:00
|
|
|
lcVector3 ProjectPoint(const lcVector3& Point) const
|
|
|
|
{
|
|
|
|
int Viewport[4] = { 0, 0, mWidth, mHeight };
|
|
|
|
return lcProjectPoint(Point, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
|
|
|
|
}
|
|
|
|
|
|
|
|
lcVector3 UnprojectPoint(const lcVector3& Point) const
|
|
|
|
{
|
|
|
|
int Viewport[4] = { 0, 0, mWidth, mHeight };
|
|
|
|
return lcUnprojectPoint(Point, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnprojectPoints(lcVector3* Points, int NumPoints) const
|
|
|
|
{
|
|
|
|
int Viewport[4] = { 0, 0, mWidth, mHeight };
|
|
|
|
lcUnprojectPoints(Points, NumPoints, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
|
|
|
|
}
|
2014-05-18 01:03:05 +02:00
|
|
|
|
2017-07-30 23:18:57 +02:00
|
|
|
bool BeginRenderToImage(int Width, int Height);
|
|
|
|
void EndRenderToImage();
|
|
|
|
|
|
|
|
QImage GetRenderImage() const
|
|
|
|
{
|
|
|
|
return mRenderImage;
|
|
|
|
}
|
|
|
|
|
2014-05-18 01:03:05 +02:00
|
|
|
protected:
|
2015-04-27 02:47:31 +02:00
|
|
|
static void CreateSelectMoveOverlayMesh(lcContext* Context);
|
|
|
|
|
2014-05-18 01:03:05 +02:00
|
|
|
void DrawSelectMoveOverlay();
|
|
|
|
void DrawRotateOverlay();
|
|
|
|
void DrawSelectZoomRegionOverlay();
|
|
|
|
void DrawRotateViewOverlay();
|
2014-08-24 00:56:59 +02:00
|
|
|
void DrawGrid();
|
|
|
|
void DrawAxes();
|
2014-05-18 01:03:05 +02:00
|
|
|
void DrawViewport();
|
|
|
|
|
|
|
|
void UpdateTrackTool();
|
2017-12-02 21:22:04 +01:00
|
|
|
bool IsTrackToolAllowed(lcTrackTool TrackTool, quint32 AllowedTransforms) const;
|
2014-05-18 01:03:05 +02:00
|
|
|
lcTool GetCurrentTool() const;
|
2016-04-23 02:17:33 +02:00
|
|
|
lcTrackTool GetOverrideTrackTool(Qt::MouseButton Button) const;
|
2014-05-18 01:03:05 +02:00
|
|
|
float GetOverlayScale() const;
|
|
|
|
void StartTracking(lcTrackButton TrackButton);
|
|
|
|
void StopTracking(bool Accept);
|
2016-05-09 03:59:10 +02:00
|
|
|
void OnButtonDown(lcTrackButton TrackButton);
|
2017-08-05 21:02:45 +02:00
|
|
|
lcMatrix44 GetTileProjectionMatrix(int CurrentRow, int CurrentColumn, int CurrentTileWidth, int CurrentTileHeight) const;
|
2014-05-18 01:03:05 +02:00
|
|
|
|
2018-03-29 19:20:36 +02:00
|
|
|
lcModel* mModel;
|
|
|
|
lcPiece* mActiveSubmodelInstance;
|
2018-04-08 02:17:32 +02:00
|
|
|
lcMatrix44 mActiveSubmodelTransform;
|
2018-03-29 19:20:36 +02:00
|
|
|
|
2015-02-08 19:54:51 +01:00
|
|
|
lcScene mScene;
|
2014-05-27 00:58:08 +02:00
|
|
|
lcDragState mDragState;
|
2014-05-18 01:03:05 +02:00
|
|
|
lcTrackButton mTrackButton;
|
|
|
|
lcTrackTool mTrackTool;
|
2018-02-06 23:47:11 +01:00
|
|
|
bool mTrackToolFromOverlay;
|
2016-05-19 23:16:31 +02:00
|
|
|
bool mTrackUpdated;
|
2014-05-18 01:03:05 +02:00
|
|
|
int mMouseDownX;
|
|
|
|
int mMouseDownY;
|
2017-11-13 04:38:07 +01:00
|
|
|
lcVector3 mMouseDownPosition;
|
|
|
|
PieceInfo* mMouseDownPiece;
|
2017-07-30 23:18:57 +02:00
|
|
|
QImage mRenderImage;
|
2017-12-29 15:50:18 +01:00
|
|
|
std::pair<lcFramebuffer, lcFramebuffer> mRenderFramebuffer;
|
2018-10-29 01:59:01 +01:00
|
|
|
lcViewSphere mViewSphere;
|
2015-04-14 06:14:10 +02:00
|
|
|
|
2015-04-26 20:14:33 +02:00
|
|
|
lcVertexBuffer mGridBuffer;
|
2015-04-14 06:14:10 +02:00
|
|
|
int mGridSettings[7];
|
2015-04-27 02:47:31 +02:00
|
|
|
|
|
|
|
static lcVertexBuffer mRotateMoveVertexBuffer;
|
|
|
|
static lcIndexBuffer mRotateMoveIndexBuffer;
|
2011-09-07 23:06:51 +02:00
|
|
|
};
|
|
|
|
|