Submodel edit mouse fixes.

This commit is contained in:
Leonardo Zide 2018-04-07 18:45:44 -07:00
parent 752ae54788
commit 7f6a7d82ae
2 changed files with 43 additions and 11 deletions

View file

@ -9,6 +9,7 @@
#include <QGLWidget> #include <QGLWidget>
#include <QtGui> #include <QtGui>
#include <QPrinter> #include <QPrinter>
#include <array>
#if !defined(EGL_VERSION_1_0) && !defined(GL_ES_VERSION_2_0) && !defined(GL_ES_VERSION_3_0) && !defined(QT_OPENGL_ES) #if !defined(EGL_VERSION_1_0) && !defined(GL_ES_VERSION_2_0) && !defined(GL_ES_VERSION_3_0) && !defined(QT_OPENGL_ES)
#undef GL_LINES_ADJACENCY_EXT #undef GL_LINES_ADJACENCY_EXT

View file

@ -55,8 +55,7 @@ void View::SetSelectedSubmodelActive()
if (mActiveSubmodelInstance) if (mActiveSubmodelInstance)
{ {
lcModel* Model = mActiveSubmodelInstance->mPieceInfo->GetModel(); ActiveModel->SetActive(false);
Model->SetActive(false);
mActiveSubmodelInstance = nullptr; mActiveSubmodelInstance = nullptr;
} }
@ -69,10 +68,12 @@ void View::SetSelectedSubmodelActive()
mActiveSubmodelTransform = lcMatrix44Identity(); mActiveSubmodelTransform = lcMatrix44Identity();
mModel->GetPieceWorldMatrix(Piece, mActiveSubmodelTransform); mModel->GetPieceWorldMatrix(Piece, mActiveSubmodelTransform);
mActiveSubmodelInstance = Piece; mActiveSubmodelInstance = Piece;
lcModel* Model = mActiveSubmodelInstance->mPieceInfo->GetModel(); ActiveModel = mActiveSubmodelInstance->mPieceInfo->GetModel();
Model->SetActive(true); ActiveModel->SetActive(true);
} }
} }
GetActiveModel()->UpdateInterface();
} }
void View::CreateResources(lcContext* Context) void View::CreateResources(lcContext* Context)
@ -552,8 +553,16 @@ lcMatrix44 View::GetPieceInsertPosition(bool IgnoreSelected, PieceInfo* Info) co
return WorldMatrix; return WorldMatrix;
} }
lcVector3 ClickPoints[2] = { lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f) }; std::array<lcVector3, 2> ClickPoints = { lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f) };
UnprojectPoints(ClickPoints, 2); UnprojectPoints(ClickPoints.data(), 2);
if (ActiveModel != mModel)
{
lcMatrix44 InverseMatrix = lcMatrix44AffineInverse(mActiveSubmodelTransform);
for (lcVector3& Point : ClickPoints)
Point = lcMul31(Point, InverseMatrix);
}
lcVector3 Intersection; lcVector3 Intersection;
@ -643,7 +652,7 @@ lcArray<lcObject*> View::FindObjectsInBox(float x1, float y1, float x2, float y2
Bottom = y1; Bottom = y1;
} }
lcVector3 Corners[6] = std::array<lcVector3, 6> Corners =
{ {
lcVector3(Left, Top, 0), lcVector3(Left, Top, 0),
lcVector3(Left, Bottom, 0), lcVector3(Left, Bottom, 0),
@ -653,7 +662,17 @@ lcArray<lcObject*> View::FindObjectsInBox(float x1, float y1, float x2, float y2
lcVector3(Right, Bottom, 1) lcVector3(Right, Bottom, 1)
}; };
UnprojectPoints(Corners, 6); UnprojectPoints(Corners.data(), Corners.size());
lcModel* ActiveModel = GetActiveModel();
if (ActiveModel != mModel)
{
lcMatrix44 InverseMatrix = lcMatrix44AffineInverse(mActiveSubmodelTransform);
for (lcVector3& Point : Corners)
Point = lcMul31(Point, InverseMatrix);
}
lcVector3 PlaneNormals[6]; lcVector3 PlaneNormals[6];
PlaneNormals[0] = lcNormalize(lcCross(Corners[4] - Corners[0], Corners[1] - Corners[0])); // Left PlaneNormals[0] = lcNormalize(lcCross(Corners[4] - Corners[0], Corners[1] - Corners[0])); // Left
@ -672,7 +691,6 @@ lcArray<lcObject*> View::FindObjectsInBox(float x1, float y1, float x2, float y2
ObjectBoxTest.Planes[4] = lcVector4(PlaneNormals[4], -lcDot(PlaneNormals[4], Corners[0])); ObjectBoxTest.Planes[4] = lcVector4(PlaneNormals[4], -lcDot(PlaneNormals[4], Corners[0]));
ObjectBoxTest.Planes[5] = lcVector4(PlaneNormals[5], -lcDot(PlaneNormals[5], Corners[5])); ObjectBoxTest.Planes[5] = lcVector4(PlaneNormals[5], -lcDot(PlaneNormals[5], Corners[5]));
lcModel* ActiveModel = GetActiveModel();
ActiveModel->BoxTest(ObjectBoxTest); ActiveModel->BoxTest(ObjectBoxTest);
return ObjectBoxTest.Objects; return ObjectBoxTest.Objects;
@ -719,7 +737,14 @@ void View::OnDraw()
PieceInfo* Info = gMainWindow->GetCurrentPieceInfo(); PieceInfo* Info = gMainWindow->GetCurrentPieceInfo();
if (Info) if (Info)
Info->AddRenderMeshes(mScene, GetPieceInsertPosition(false, gMainWindow->GetCurrentPieceInfo()), gMainWindow->mColorIndex, lcRenderMeshState::FOCUSED, true); {
lcMatrix44 WorldMatrix = GetPieceInsertPosition(false, gMainWindow->GetCurrentPieceInfo());
if (GetActiveModel() != mModel)
WorldMatrix = lcMul(WorldMatrix, mActiveSubmodelTransform);
Info->AddRenderMeshes(mScene, WorldMatrix, gMainWindow->mColorIndex, lcRenderMeshState::FOCUSED, true);
}
} }
int TotalTileRows = 1; int TotalTileRows = 1;
@ -1962,6 +1987,12 @@ void View::UpdateTrackTool()
if (!ActiveModel->GetMoveRotateTransform(OverlayCenter, RelativeRotation)) if (!ActiveModel->GetMoveRotateTransform(OverlayCenter, RelativeRotation))
break; break;
lcMatrix44 WorldMatrix = lcMatrix44(RelativeRotation, OverlayCenter);
if (ActiveModel != mModel)
WorldMatrix = lcMul(WorldMatrix, mActiveSubmodelTransform);
OverlayCenter = WorldMatrix.GetTranslation();
lcVector3 PlaneNormals[3] = lcVector3 PlaneNormals[3] =
{ {
lcVector3(1.0f, 0.0f, 0.0f), lcVector3(1.0f, 0.0f, 0.0f),
@ -1970,7 +2001,7 @@ void View::UpdateTrackTool()
}; };
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
PlaneNormals[i] = lcMul(PlaneNormals[i], RelativeRotation); PlaneNormals[i] = lcMul30(PlaneNormals[i], WorldMatrix);
lcVector3 StartEnd[2] = { lcVector3((float)x, (float)y, 0.0f), lcVector3((float)x, (float)y, 1.0f) }; lcVector3 StartEnd[2] = { lcVector3((float)x, (float)y, 0.0f), lcVector3((float)x, (float)y, 1.0f) };
UnprojectPoints(StartEnd, 2); UnprojectPoints(StartEnd, 2);