mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Widget cleanup.
This commit is contained in:
parent
194e02c74c
commit
256d3792b1
10 changed files with 134 additions and 234 deletions
|
@ -2,6 +2,8 @@
|
|||
#include "lc_glwidget.h"
|
||||
#include "lc_application.h"
|
||||
#include "lc_context.h"
|
||||
#include "camera.h"
|
||||
#include "texfont.h"
|
||||
|
||||
lcGLWidget::lcGLWidget()
|
||||
{
|
||||
|
@ -85,6 +87,39 @@ void lcGLWidget::SetCursor(lcCursor CursorType)
|
|||
}
|
||||
}
|
||||
|
||||
lcMatrix44 lcGLWidget::GetProjectionMatrix() const
|
||||
{
|
||||
float AspectRatio = (float)mWidth / (float)mHeight;
|
||||
|
||||
if (mCamera->IsOrtho())
|
||||
{
|
||||
float OrthoHeight = mCamera->GetOrthoHeight() / 2.0f;
|
||||
float OrthoWidth = OrthoHeight * AspectRatio;
|
||||
|
||||
return lcMatrix44Ortho(-OrthoWidth, OrthoWidth, -OrthoHeight, OrthoHeight, mCamera->m_zNear, mCamera->m_zFar * 4);
|
||||
}
|
||||
else
|
||||
return lcMatrix44Perspective(mCamera->m_fovy, AspectRatio, mCamera->m_zNear, mCamera->m_zFar);
|
||||
}
|
||||
|
||||
lcVector3 lcGLWidget::ProjectPoint(const lcVector3& Point) const
|
||||
{
|
||||
int Viewport[4] = { 0, 0, mWidth, mHeight };
|
||||
return lcProjectPoint(Point, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
|
||||
}
|
||||
|
||||
lcVector3 lcGLWidget::UnprojectPoint(const lcVector3& Point) const
|
||||
{
|
||||
int Viewport[4] = { 0, 0, mWidth, mHeight };
|
||||
return lcUnprojectPoint(Point, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
|
||||
}
|
||||
|
||||
void lcGLWidget::UnprojectPoints(lcVector3* Points, int NumPoints) const
|
||||
{
|
||||
int Viewport[4] = { 0, 0, mWidth, mHeight };
|
||||
lcUnprojectPoints(Points, NumPoints, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
|
||||
}
|
||||
|
||||
void lcGLWidget::DrawBackground() const
|
||||
{
|
||||
const lcPreferences& Preferences = lcGetPreferences();
|
||||
|
@ -135,3 +170,71 @@ void lcGLWidget::DrawBackground() const
|
|||
glEnable(GL_DEPTH_TEST);
|
||||
Context->SetDepthWrite(true);
|
||||
}
|
||||
|
||||
void lcGLWidget::DrawAxes() const
|
||||
{
|
||||
// glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
const float Verts[28 * 3] =
|
||||
{
|
||||
0.00f, 0.00f, 0.00f, 20.00f, 0.00f, 0.00f, 12.00f, 3.00f, 0.00f, 12.00f, 2.12f, 2.12f,
|
||||
12.00f, 0.00f, 3.00f, 12.00f, -2.12f, 2.12f, 12.00f, -3.00f, 0.00f, 12.00f, -2.12f, -2.12f,
|
||||
12.00f, 0.00f, -3.00f, 12.00f, 2.12f, -2.12f, 0.00f, 20.00f, 0.00f, 3.00f, 12.00f, 0.00f,
|
||||
2.12f, 12.00f, 2.12f, 0.00f, 12.00f, 3.00f, -2.12f, 12.00f, 2.12f, -3.00f, 12.00f, 0.00f,
|
||||
-2.12f, 12.00f, -2.12f, 0.00f, 12.00f, -3.00f, 2.12f, 12.00f, -2.12f, 0.00f, 0.00f, 20.00f,
|
||||
0.00f, 3.00f, 12.00f, 2.12f, 2.12f, 12.00f, 3.00f, 0.00f, 12.00f, 2.12f, -2.12f, 12.00f,
|
||||
0.00f, -3.00f, 12.00f, -2.12f, -2.12f, 12.00f, -3.00f, 0.00f, 12.00f, -2.12f, 2.12f, 12.00f,
|
||||
};
|
||||
|
||||
const GLushort Indices[78] =
|
||||
{
|
||||
0, 1, 0, 10, 0, 19,
|
||||
1, 2, 3, 1, 3, 4, 1, 4, 5, 1, 5, 6, 1, 6, 7, 1, 7, 8, 1, 8, 9, 1, 9, 2,
|
||||
10, 11, 12, 10, 12, 13, 10, 13, 14, 10, 14, 15, 10, 15, 16, 10, 16, 17, 10, 17, 18, 10, 18, 11,
|
||||
19, 20, 21, 19, 21, 22, 19, 22, 23, 19, 23, 24, 19, 24, 25, 19, 25, 26, 19, 26, 27, 19, 27, 20
|
||||
};
|
||||
|
||||
lcMatrix44 TranslationMatrix = lcMatrix44Translation(lcVector3(30.375f, 30.375f, 0.0f));
|
||||
lcMatrix44 WorldViewMatrix = mCamera->mWorldView;
|
||||
WorldViewMatrix.SetTranslation(lcVector3(0, 0, 0));
|
||||
|
||||
mContext->SetMaterial(lcMaterialType::UnlitColor);
|
||||
mContext->SetWorldMatrix(lcMatrix44Identity());
|
||||
mContext->SetViewMatrix(lcMul(WorldViewMatrix, TranslationMatrix));
|
||||
mContext->SetProjectionMatrix(lcMatrix44Ortho(0, mWidth, 0, mHeight, -50, 50));
|
||||
|
||||
mContext->SetVertexBufferPointer(Verts);
|
||||
mContext->SetVertexFormatPosition(3);
|
||||
mContext->SetIndexBufferPointer(Indices);
|
||||
|
||||
mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_LINES, 6, GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
mContext->SetColor(0.8f, 0.0f, 0.0f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, 6 * 2);
|
||||
mContext->SetColor(0.0f, 0.8f, 0.0f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, (6 + 24) * 2);
|
||||
mContext->SetColor(0.0f, 0.0f, 0.8f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, (6 + 48) * 2);
|
||||
|
||||
mContext->SetMaterial(lcMaterialType::UnlitTextureModulate);
|
||||
mContext->SetViewMatrix(TranslationMatrix);
|
||||
mContext->BindTexture2D(gTexFont.GetTexture());
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
float TextBuffer[6 * 5 * 3];
|
||||
lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix);
|
||||
gTexFont.GetGlyphTriangles(PosX.x, PosX.y, PosX.z, 'X', TextBuffer);
|
||||
lcVector3 PosY = lcMul30(lcVector3(0.0f, 25.0f, 0.0f), WorldViewMatrix);
|
||||
gTexFont.GetGlyphTriangles(PosY.x, PosY.y, PosY.z, 'Y', TextBuffer + 5 * 6);
|
||||
lcVector3 PosZ = lcMul30(lcVector3(0.0f, 0.0f, 25.0f), WorldViewMatrix);
|
||||
gTexFont.GetGlyphTriangles(PosZ.x, PosZ.y, PosZ.z, 'Z', TextBuffer + 5 * 6 * 2);
|
||||
|
||||
mContext->SetVertexBufferPointer(TextBuffer);
|
||||
mContext->SetVertexFormat(0, 3, 0, 2, 0, false);
|
||||
|
||||
mContext->SetColor(lcVector4FromColor(lcGetPreferences().mAxesColor));
|
||||
mContext->DrawPrimitives(GL_TRIANGLES, 0, 6 * 3);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
|
|
@ -48,11 +48,23 @@ public:
|
|||
lcGLWidget(const lcGLWidget&) = delete;
|
||||
lcGLWidget& operator=(const lcGLWidget&) = delete;
|
||||
|
||||
lcCamera* GetCamera() const
|
||||
{
|
||||
return mCamera;
|
||||
}
|
||||
|
||||
void SetContext(lcContext* Context);
|
||||
void MakeCurrent();
|
||||
void Redraw();
|
||||
void SetCursor(lcCursor Cursor);
|
||||
|
||||
lcVector3 ProjectPoint(const lcVector3& Point) const;
|
||||
lcVector3 UnprojectPoint(const lcVector3& Point) const;
|
||||
void UnprojectPoints(lcVector3* Points, int NumPoints) const;
|
||||
lcMatrix44 GetProjectionMatrix() const;
|
||||
|
||||
void DrawBackground() const;
|
||||
void DrawAxes() const;
|
||||
|
||||
virtual void OnDraw() { }
|
||||
virtual void OnInitialUpdate() { }
|
||||
|
@ -79,5 +91,8 @@ public:
|
|||
lcCursor mCursor = lcCursor::Default;
|
||||
QGLWidget* mWidget = nullptr;
|
||||
lcContext* mContext = nullptr;
|
||||
|
||||
protected:
|
||||
lcCamera* mCamera = nullptr;
|
||||
bool mDeleteContext = true;
|
||||
};
|
||||
|
|
|
@ -1369,7 +1369,7 @@ QByteArray lcMainWindow::GetTabLayout()
|
|||
DataStream << (qint32)0;
|
||||
DataStream << (qint32)(TabWidget->GetActiveView() == CurrentView ? 1 : 0);
|
||||
|
||||
lcCamera* Camera = CurrentView->mCamera;
|
||||
const lcCamera* Camera = CurrentView->GetCamera();
|
||||
|
||||
if (Camera->IsSimple())
|
||||
{
|
||||
|
@ -1479,7 +1479,7 @@ void lcMainWindow::RestoreTabLayout(const QByteArray& TabLayout)
|
|||
|
||||
if (CurrentView)
|
||||
{
|
||||
lcCamera* Camera = CurrentView->mCamera;
|
||||
lcCamera* Camera = CurrentView->GetCamera();
|
||||
if (!std::isnan(FoV))
|
||||
Camera->m_fovy = FoV;
|
||||
if (!std::isnan(ZNear))
|
||||
|
@ -2157,7 +2157,7 @@ void lcMainWindow::UpdateCameraMenu()
|
|||
{
|
||||
const lcArray<lcCamera*>& Cameras = lcGetActiveModel()->GetCameras();
|
||||
View* ActiveView = GetActiveView();
|
||||
lcCamera* CurrentCamera = ActiveView ? ActiveView->mCamera : nullptr;
|
||||
const lcCamera* CurrentCamera = ActiveView ? ActiveView->GetCamera() : nullptr;
|
||||
int CurrentIndex = -1;
|
||||
|
||||
for (int ActionIdx = LC_VIEW_CAMERA_FIRST; ActionIdx <= LC_VIEW_CAMERA_LAST; ActionIdx++)
|
||||
|
@ -2197,7 +2197,7 @@ void lcMainWindow::UpdatePerspective()
|
|||
|
||||
if (ActiveView)
|
||||
{
|
||||
if (ActiveView->mCamera->IsOrtho())
|
||||
if (ActiveView->GetCamera()->IsOrtho())
|
||||
mActions[LC_VIEW_PROJECTION_ORTHO]->setChecked(true);
|
||||
else
|
||||
mActions[LC_VIEW_PROJECTION_PERSPECTIVE]->setChecked(true);
|
||||
|
|
|
@ -200,7 +200,7 @@ void lcModel::DeleteModel()
|
|||
for (int ViewIdx = 0; ViewIdx < Views->GetSize(); ViewIdx++)
|
||||
{
|
||||
View* View = (*Views)[ViewIdx];
|
||||
lcCamera* Camera = View->mCamera;
|
||||
lcCamera* Camera = View->GetCamera();
|
||||
|
||||
if (!Camera->IsSimple() && mCameras.FindIndex(Camera) != -1)
|
||||
View->SetCamera(Camera, true);
|
||||
|
@ -1265,7 +1265,7 @@ QImage lcModel::GetStepImage(bool Zoom, int Width, int Height, lcStep Step)
|
|||
|
||||
lcStep CurrentStep = mCurrentStep;
|
||||
|
||||
lcCamera* Camera = ActiveView->mCamera;
|
||||
lcCamera* Camera = ActiveView->GetCamera();
|
||||
if (Zoom)
|
||||
ZoomExtents(Camera, (float)Width / (float)Height);
|
||||
|
||||
|
@ -2608,7 +2608,7 @@ bool lcModel::RemoveSelectedObjects()
|
|||
{
|
||||
View* View = (*Views)[ViewIdx];
|
||||
|
||||
if (Camera == View->mCamera)
|
||||
if (Camera == View->GetCamera())
|
||||
View->SetCamera(Camera, true);
|
||||
}
|
||||
|
||||
|
@ -3943,22 +3943,22 @@ void lcModel::EndMouseTool(lcTool Tool, bool Accept)
|
|||
break;
|
||||
|
||||
case LC_TOOL_ZOOM:
|
||||
if (!mIsPreview && !gMainWindow->GetActiveView()->mCamera->IsSimple())
|
||||
if (!mIsPreview && !gMainWindow->GetActiveView()->GetCamera()->IsSimple())
|
||||
SaveCheckpoint(tr("Zoom"));
|
||||
break;
|
||||
|
||||
case LC_TOOL_PAN:
|
||||
if (!mIsPreview && !gMainWindow->GetActiveView()->mCamera->IsSimple())
|
||||
if (!mIsPreview && !gMainWindow->GetActiveView()->GetCamera()->IsSimple())
|
||||
SaveCheckpoint(tr("Pan"));
|
||||
break;
|
||||
|
||||
case LC_TOOL_ROTATE_VIEW:
|
||||
if (!mIsPreview && !gMainWindow->GetActiveView()->mCamera->IsSimple())
|
||||
if (!mIsPreview && !gMainWindow->GetActiveView()->GetCamera()->IsSimple())
|
||||
SaveCheckpoint(tr("Orbit"));
|
||||
break;
|
||||
|
||||
case LC_TOOL_ROLL:
|
||||
if (!mIsPreview && !gMainWindow->GetActiveView()->mCamera->IsSimple())
|
||||
if (!mIsPreview && !gMainWindow->GetActiveView()->GetCamera()->IsSimple())
|
||||
SaveCheckpoint(tr("Roll"));
|
||||
break;
|
||||
|
||||
|
@ -4089,7 +4089,7 @@ void lcModel::EraserToolClicked(lcObject* Object)
|
|||
for (int ViewIdx = 0; ViewIdx < Views->GetSize(); ViewIdx++)
|
||||
{
|
||||
View* View = (*Views)[ViewIdx];
|
||||
lcCamera* Camera = View->mCamera;
|
||||
lcCamera* Camera = View->GetCamera();
|
||||
|
||||
if (Camera == Object)
|
||||
View->SetCamera(Camera, true);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include "QMessageBox"
|
||||
#include "lc_global.h"
|
||||
#include "lc_previewwidget.h"
|
||||
#include "pieceinf.h"
|
||||
|
@ -6,7 +5,6 @@
|
|||
#include "project.h"
|
||||
#include "lc_model.h"
|
||||
#include "camera.h"
|
||||
#include "texfont.h"
|
||||
#include "lc_library.h"
|
||||
|
||||
#include "lc_qglwidget.h"
|
||||
|
@ -226,21 +224,6 @@ void lcPreviewWidget::ZoomExtents()
|
|||
}
|
||||
}
|
||||
|
||||
lcMatrix44 lcPreviewWidget::GetProjectionMatrix() const
|
||||
{
|
||||
float AspectRatio = (float)mWidth / (float)mHeight;
|
||||
|
||||
if (mCamera->IsOrtho())
|
||||
{
|
||||
float OrthoHeight = mCamera->GetOrthoHeight() / 2.0f;
|
||||
float OrthoWidth = OrthoHeight * AspectRatio;
|
||||
|
||||
return lcMatrix44Ortho(-OrthoWidth, OrthoWidth, -OrthoHeight, OrthoHeight, mCamera->m_zNear, mCamera->m_zFar * 4);
|
||||
}
|
||||
else
|
||||
return lcMatrix44Perspective(mCamera->m_fovy, AspectRatio, mCamera->m_zNear, mCamera->m_zFar);
|
||||
}
|
||||
|
||||
void lcPreviewWidget::StartOrbitTracking() // called by viewSphere
|
||||
{
|
||||
mTrackTool = LC_TRACKTOOL_ORBIT_XY;
|
||||
|
@ -291,74 +274,6 @@ void lcPreviewWidget::DrawViewport()
|
|||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void lcPreviewWidget::DrawAxes()
|
||||
{
|
||||
// glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
const float Verts[28 * 3] =
|
||||
{
|
||||
0.00f, 0.00f, 0.00f, 20.00f, 0.00f, 0.00f, 12.00f, 3.00f, 0.00f, 12.00f, 2.12f, 2.12f,
|
||||
12.00f, 0.00f, 3.00f, 12.00f, -2.12f, 2.12f, 12.00f, -3.00f, 0.00f, 12.00f, -2.12f, -2.12f,
|
||||
12.00f, 0.00f, -3.00f, 12.00f, 2.12f, -2.12f, 0.00f, 20.00f, 0.00f, 3.00f, 12.00f, 0.00f,
|
||||
2.12f, 12.00f, 2.12f, 0.00f, 12.00f, 3.00f, -2.12f, 12.00f, 2.12f, -3.00f, 12.00f, 0.00f,
|
||||
-2.12f, 12.00f, -2.12f, 0.00f, 12.00f, -3.00f, 2.12f, 12.00f, -2.12f, 0.00f, 0.00f, 20.00f,
|
||||
0.00f, 3.00f, 12.00f, 2.12f, 2.12f, 12.00f, 3.00f, 0.00f, 12.00f, 2.12f, -2.12f, 12.00f,
|
||||
0.00f, -3.00f, 12.00f, -2.12f, -2.12f, 12.00f, -3.00f, 0.00f, 12.00f, -2.12f, 2.12f, 12.00f,
|
||||
};
|
||||
|
||||
const GLushort Indices[78] =
|
||||
{
|
||||
0, 1, 0, 10, 0, 19,
|
||||
1, 2, 3, 1, 3, 4, 1, 4, 5, 1, 5, 6, 1, 6, 7, 1, 7, 8, 1, 8, 9, 1, 9, 2,
|
||||
10, 11, 12, 10, 12, 13, 10, 13, 14, 10, 14, 15, 10, 15, 16, 10, 16, 17, 10, 17, 18, 10, 18, 11,
|
||||
19, 20, 21, 19, 21, 22, 19, 22, 23, 19, 23, 24, 19, 24, 25, 19, 25, 26, 19, 26, 27, 19, 27, 20
|
||||
};
|
||||
|
||||
lcMatrix44 TranslationMatrix = lcMatrix44Translation(lcVector3(30.375f, 30.375f, 0.0f));
|
||||
lcMatrix44 WorldViewMatrix = mCamera->mWorldView;
|
||||
WorldViewMatrix.SetTranslation(lcVector3(0, 0, 0));
|
||||
|
||||
mContext->SetMaterial(lcMaterialType::UnlitColor);
|
||||
mContext->SetWorldMatrix(lcMatrix44Identity());
|
||||
mContext->SetViewMatrix(lcMul(WorldViewMatrix, TranslationMatrix));
|
||||
mContext->SetProjectionMatrix(lcMatrix44Ortho(0, mWidth, 0, mHeight, -50, 50));
|
||||
|
||||
mContext->SetVertexBufferPointer(Verts);
|
||||
mContext->SetVertexFormatPosition(3);
|
||||
mContext->SetIndexBufferPointer(Indices);
|
||||
|
||||
mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_LINES, 6, GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
mContext->SetColor(0.8f, 0.0f, 0.0f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, 6 * 2);
|
||||
mContext->SetColor(0.0f, 0.8f, 0.0f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, (6 + 24) * 2);
|
||||
mContext->SetColor(0.0f, 0.0f, 0.8f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, (6 + 48) * 2);
|
||||
|
||||
mContext->SetMaterial(lcMaterialType::UnlitTextureModulate);
|
||||
mContext->SetViewMatrix(TranslationMatrix);
|
||||
mContext->BindTexture2D(gTexFont.GetTexture());
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
float TextBuffer[6 * 5 * 3];
|
||||
lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix);
|
||||
gTexFont.GetGlyphTriangles(PosX.x, PosX.y, PosX.z, 'X', TextBuffer);
|
||||
lcVector3 PosY = lcMul30(lcVector3(0.0f, 25.0f, 0.0f), WorldViewMatrix);
|
||||
gTexFont.GetGlyphTriangles(PosY.x, PosY.y, PosY.z, 'Y', TextBuffer + 5 * 6);
|
||||
lcVector3 PosZ = lcMul30(lcVector3(0.0f, 0.0f, 25.0f), WorldViewMatrix);
|
||||
gTexFont.GetGlyphTriangles(PosZ.x, PosZ.y, PosZ.z, 'Z', TextBuffer + 5 * 6 * 2);
|
||||
|
||||
mContext->SetVertexBufferPointer(TextBuffer);
|
||||
mContext->SetVertexFormat(0, 3, 0, 2, 0, false);
|
||||
|
||||
mContext->SetColor(lcVector4FromColor(lcGetPreferences().mAxesColor));
|
||||
mContext->DrawPrimitives(GL_TRIANGLES, 0, 6 * 3);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
lcTool lcPreviewWidget::GetCurrentTool() const
|
||||
{
|
||||
const lcTool ToolFromTrackTool[] =
|
||||
|
|
|
@ -1,27 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QString>
|
||||
#include "lc_global.h"
|
||||
#include "lc_glwidget.h"
|
||||
#include "lc_scene.h"
|
||||
#include "lc_viewsphere.h"
|
||||
#include "lc_commands.h"
|
||||
#include "lc_application.h"
|
||||
#include "camera.h"
|
||||
|
||||
class QLabel;
|
||||
class Project;
|
||||
class lcModel;
|
||||
class lcPiece;
|
||||
class lcQGLWidget;
|
||||
class lcPreviewWidget;
|
||||
|
||||
class lcPreviewDockWidget : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit lcPreviewDockWidget(QMainWindow* parent = nullptr);
|
||||
explicit lcPreviewDockWidget(QMainWindow* Parent = nullptr);
|
||||
bool SetCurrentPiece(const QString& PartType, int ColorCode);
|
||||
void ClearPreview();
|
||||
void UpdatePreview();
|
||||
|
@ -64,32 +56,14 @@ public:
|
|||
return mTool;
|
||||
}
|
||||
|
||||
lcCamera* GetCamera() const
|
||||
{
|
||||
return mCamera;
|
||||
}
|
||||
|
||||
QString GetDescription() const
|
||||
{
|
||||
return mDescription;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void ClearPreview();
|
||||
void UpdatePreview();
|
||||
bool SetCurrentPiece(const QString& PartType, int ColorCode);
|
||||
lcMatrix44 GetProjectionMatrix() const;
|
||||
lcModel* GetActiveModel() const;
|
||||
lcCursor GetCursor() const;
|
||||
void SetCamera(lcCamera* Camera);
|
||||
|
@ -123,7 +97,6 @@ public:
|
|||
void OnMouseWheel(float Direction) override;
|
||||
|
||||
protected:
|
||||
void DrawAxes();
|
||||
void DrawViewport();
|
||||
|
||||
lcTool GetCurrentTool() const;
|
||||
|
@ -133,7 +106,6 @@ protected:
|
|||
|
||||
Project* mLoader;
|
||||
lcModel* mModel;
|
||||
lcCamera* mCamera;
|
||||
lcViewSphere mViewSphere;
|
||||
|
||||
lcScene mScene;
|
||||
|
|
|
@ -35,7 +35,7 @@ lcViewSphere::lcViewSphere(lcPreviewWidget* Preview)
|
|||
|
||||
lcMatrix44 lcViewSphere::GetViewMatrix() const
|
||||
{
|
||||
lcMatrix44 ViewMatrix = mIsPreview ? mPreview->GetCamera()->mWorldView : mView->mCamera->mWorldView;
|
||||
lcMatrix44 ViewMatrix = mIsPreview ? mPreview->GetCamera()->mWorldView : mView->GetCamera()->mWorldView;
|
||||
ViewMatrix.SetTranslation(lcVector3(0, 0, 0));
|
||||
return ViewMatrix;
|
||||
}
|
||||
|
|
|
@ -1961,7 +1961,7 @@ bool Project::ExportPOVRay(const QString& FileName)
|
|||
POVFile.WriteLine(Line);
|
||||
}
|
||||
|
||||
lcCamera* Camera = gMainWindow->GetActiveView()->mCamera;
|
||||
const lcCamera* Camera = gMainWindow->GetActiveView()->GetCamera();
|
||||
const lcVector3& Position = Camera->mPosition;
|
||||
const lcVector3& Target = Camera->mTargetPosition;
|
||||
const lcVector3& Up = Camera->mUpVector;
|
||||
|
|
|
@ -381,21 +381,6 @@ void View::SetDefaultCamera()
|
|||
gMainWindow->UpdateCurrentCamera(-1);
|
||||
}
|
||||
|
||||
lcMatrix44 View::GetProjectionMatrix() const
|
||||
{
|
||||
float AspectRatio = (float)mWidth / (float)mHeight;
|
||||
|
||||
if (mCamera->IsOrtho())
|
||||
{
|
||||
float OrthoHeight = mCamera->GetOrthoHeight() / 2.0f;
|
||||
float OrthoWidth = OrthoHeight * AspectRatio;
|
||||
|
||||
return lcMatrix44Ortho(-OrthoWidth, OrthoWidth, -OrthoHeight, OrthoHeight, mCamera->m_zNear, mCamera->m_zFar * 4);
|
||||
}
|
||||
else
|
||||
return lcMatrix44Perspective(mCamera->m_fovy, AspectRatio, mCamera->m_zNear, mCamera->m_zFar);
|
||||
}
|
||||
|
||||
lcMatrix44 View::GetTileProjectionMatrix(int CurrentRow, int CurrentColumn, int CurrentTileWidth, int CurrentTileHeight) const
|
||||
{
|
||||
int ImageWidth = mRenderImage.width();
|
||||
|
@ -1763,74 +1748,6 @@ void View::DrawGrid()
|
|||
}
|
||||
}
|
||||
|
||||
void View::DrawAxes()
|
||||
{
|
||||
// glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
const float Verts[28 * 3] =
|
||||
{
|
||||
0.00f, 0.00f, 0.00f, 20.00f, 0.00f, 0.00f, 12.00f, 3.00f, 0.00f, 12.00f, 2.12f, 2.12f,
|
||||
12.00f, 0.00f, 3.00f, 12.00f, -2.12f, 2.12f, 12.00f, -3.00f, 0.00f, 12.00f, -2.12f, -2.12f,
|
||||
12.00f, 0.00f, -3.00f, 12.00f, 2.12f, -2.12f, 0.00f, 20.00f, 0.00f, 3.00f, 12.00f, 0.00f,
|
||||
2.12f, 12.00f, 2.12f, 0.00f, 12.00f, 3.00f, -2.12f, 12.00f, 2.12f, -3.00f, 12.00f, 0.00f,
|
||||
-2.12f, 12.00f, -2.12f, 0.00f, 12.00f, -3.00f, 2.12f, 12.00f, -2.12f, 0.00f, 0.00f, 20.00f,
|
||||
0.00f, 3.00f, 12.00f, 2.12f, 2.12f, 12.00f, 3.00f, 0.00f, 12.00f, 2.12f, -2.12f, 12.00f,
|
||||
0.00f, -3.00f, 12.00f, -2.12f, -2.12f, 12.00f, -3.00f, 0.00f, 12.00f, -2.12f, 2.12f, 12.00f,
|
||||
};
|
||||
|
||||
const GLushort Indices[78] =
|
||||
{
|
||||
0, 1, 0, 10, 0, 19,
|
||||
1, 2, 3, 1, 3, 4, 1, 4, 5, 1, 5, 6, 1, 6, 7, 1, 7, 8, 1, 8, 9, 1, 9, 2,
|
||||
10, 11, 12, 10, 12, 13, 10, 13, 14, 10, 14, 15, 10, 15, 16, 10, 16, 17, 10, 17, 18, 10, 18, 11,
|
||||
19, 20, 21, 19, 21, 22, 19, 22, 23, 19, 23, 24, 19, 24, 25, 19, 25, 26, 19, 26, 27, 19, 27, 20
|
||||
};
|
||||
|
||||
lcMatrix44 TranslationMatrix = lcMatrix44Translation(lcVector3(30.375f, 30.375f, 0.0f));
|
||||
lcMatrix44 WorldViewMatrix = mCamera->mWorldView;
|
||||
WorldViewMatrix.SetTranslation(lcVector3(0, 0, 0));
|
||||
|
||||
mContext->SetMaterial(lcMaterialType::UnlitColor);
|
||||
mContext->SetWorldMatrix(lcMatrix44Identity());
|
||||
mContext->SetViewMatrix(lcMul(WorldViewMatrix, TranslationMatrix));
|
||||
mContext->SetProjectionMatrix(lcMatrix44Ortho(0, mWidth, 0, mHeight, -50, 50));
|
||||
|
||||
mContext->SetVertexBufferPointer(Verts);
|
||||
mContext->SetVertexFormatPosition(3);
|
||||
mContext->SetIndexBufferPointer(Indices);
|
||||
|
||||
mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_LINES, 6, GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
mContext->SetColor(0.8f, 0.0f, 0.0f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, 6 * 2);
|
||||
mContext->SetColor(0.0f, 0.8f, 0.0f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, (6 + 24) * 2);
|
||||
mContext->SetColor(0.0f, 0.0f, 0.8f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, (6 + 48) * 2);
|
||||
|
||||
mContext->SetMaterial(lcMaterialType::UnlitTextureModulate);
|
||||
mContext->SetViewMatrix(TranslationMatrix);
|
||||
mContext->BindTexture2D(gTexFont.GetTexture());
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
float TextBuffer[6 * 5 * 3];
|
||||
lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix);
|
||||
gTexFont.GetGlyphTriangles(PosX.x, PosX.y, PosX.z, 'X', TextBuffer);
|
||||
lcVector3 PosY = lcMul30(lcVector3(0.0f, 25.0f, 0.0f), WorldViewMatrix);
|
||||
gTexFont.GetGlyphTriangles(PosY.x, PosY.y, PosY.z, 'Y', TextBuffer + 5 * 6);
|
||||
lcVector3 PosZ = lcMul30(lcVector3(0.0f, 0.0f, 25.0f), WorldViewMatrix);
|
||||
gTexFont.GetGlyphTriangles(PosZ.x, PosZ.y, PosZ.z, 'Z', TextBuffer + 5 * 6 * 2);
|
||||
|
||||
mContext->SetVertexBufferPointer(TextBuffer);
|
||||
mContext->SetVertexFormat(0, 3, 0, 2, 0, false);
|
||||
|
||||
mContext->SetColor(lcVector4FromColor(lcGetPreferences().mAxesColor));
|
||||
mContext->DrawPrimitives(GL_TRIANGLES, 0, 6 * 3);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void View::DrawViewport()
|
||||
{
|
||||
mContext->SetWorldMatrix(lcMatrix44Identity());
|
||||
|
|
|
@ -117,7 +117,6 @@ public:
|
|||
void SetViewpoint(const lcVector3& Position);
|
||||
void SetCameraAngles(float Latitude, float Longitude);
|
||||
void SetDefaultCamera();
|
||||
lcMatrix44 GetProjectionMatrix() const;
|
||||
lcCursor GetCursor() const;
|
||||
void ShowContextMenu() const;
|
||||
|
||||
|
@ -128,26 +127,6 @@ public:
|
|||
lcObjectSection FindObjectUnderPointer(bool PiecesOnly, bool IgnoreSelected) const;
|
||||
lcArray<lcObject*> FindObjectsInBox(float x1, float y1, float x2, float y2) const;
|
||||
|
||||
lcCamera* mCamera;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool BeginRenderToImage(int Width, int Height);
|
||||
void EndRenderToImage();
|
||||
|
||||
|
@ -164,7 +143,6 @@ protected:
|
|||
void DrawSelectZoomRegionOverlay();
|
||||
void DrawRotateViewOverlay();
|
||||
void DrawGrid();
|
||||
void DrawAxes();
|
||||
void DrawViewport();
|
||||
|
||||
void UpdateTrackTool();
|
||||
|
|
Loading…
Reference in a new issue