From aae75b36fe1df422ff83d678cbefbd2810903cae Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 12 May 2024 12:45:15 -0700 Subject: [PATCH] Removed lcArray from control points. --- common/lc_model.cpp | 16 +++--- common/lc_synth.cpp | 132 +++++++++++++++++++++++--------------------- common/lc_synth.h | 12 ++-- common/piece.cpp | 51 +++++++++-------- common/piece.h | 36 ++++++------ 5 files changed, 127 insertions(+), 120 deletions(-) diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 0eb4b361..3102bd0f 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -452,11 +452,9 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly, lcStep LastStep) { Stream << QLatin1String("0 !LEOCAD SYNTH BEGIN\r\n"); - const lcArray& ControlPoints = Piece->GetControlPoints(); - for (int ControlPointIdx = 0; ControlPointIdx < ControlPoints.GetSize(); ControlPointIdx++) + const std::vector& ControlPoints = Piece->GetControlPoints(); + for (const lcPieceControlPoint& ControlPoint : ControlPoints) { - const lcPieceControlPoint& ControlPoint = ControlPoints[ControlPointIdx]; - Stream << QLatin1String("0 !LEOCAD SYNTH CONTROL_POINT"); const float* FloatMatrix = ControlPoint.Transform; @@ -559,7 +557,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project) lcCamera* Camera = nullptr; lcLight* Light = nullptr; lcArray CurrentGroups; - lcArray ControlPoints; + std::vector ControlPoints; int CurrentStep = 1; lcPiecesLibrary* Library = lcGetPiecesLibrary(); @@ -691,11 +689,11 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project) if (Token == QLatin1String("BEGIN")) { - ControlPoints.RemoveAll(); + ControlPoints.clear(); } else if (Token == QLatin1String("END")) { - ControlPoints.RemoveAll(); + ControlPoints.clear(); } else if (Token == QLatin1String("CONTROL_POINT")) { @@ -703,7 +701,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project) for (int TokenIdx = 0; TokenIdx < 13; TokenIdx++) LineStream >> Numbers[TokenIdx]; - lcPieceControlPoint& PieceControlPoint = ControlPoints.Add(); + lcPieceControlPoint& PieceControlPoint = ControlPoints.emplace_back(); PieceControlPoint.Transform = lcMatrix44(lcVector4(Numbers[3], Numbers[9], -Numbers[6], 0.0f), lcVector4(Numbers[5], Numbers[11], -Numbers[8], 0.0f), lcVector4(-Numbers[4], -Numbers[10], Numbers[7], 0.0f), lcVector4(Numbers[0], Numbers[2], -Numbers[1], 1.0f)); PieceControlPoint.Scale = Numbers[12]; @@ -756,7 +754,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project) Piece->SetColorCode(ColorCode); Piece->VerifyControlPoints(ControlPoints); Piece->SetControlPoints(ControlPoints); - ControlPoints.RemoveAll(); + ControlPoints.clear(); if (Piece->mPieceInfo->IsModel() && Piece->mPieceInfo->GetModel()->IncludesModel(this)) { diff --git a/common/lc_synth.cpp b/common/lc_synth.cpp index fdd1120e..41080e41 100644 --- a/common/lc_synth.cpp +++ b/common/lc_synth.cpp @@ -12,12 +12,12 @@ class lcSynthInfoCurved : public lcSynthInfo public: lcSynthInfoCurved(float Length, float DefaultScale, int NumSections, bool RigidEdges); - void GetDefaultControlPoints(lcArray& ControlPoints) const override; - void VerifyControlPoints(lcArray& ControlPoints) const override; + void GetDefaultControlPoints(std::vector& ControlPoints) const override; + void VerifyControlPoints(std::vector& ControlPoints) const override; protected: float GetSectionTwist(const lcMatrix44& StartTransform, const lcMatrix44& EndTransform) const; - void CalculateSections(const lcArray& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const override; + void CalculateSections(const std::vector& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const override; static void AddTubeParts(lcLibraryMeshData& MeshData, const lcArray& Sections, float Radius, bool IsInner); struct lcSynthComponent @@ -51,7 +51,7 @@ class lcSynthInfoFlexSystemHose : public lcSynthInfoCurved public: lcSynthInfoFlexSystemHose(float Length, int NumSections); - void GetDefaultControlPoints(lcArray& ControlPoints) const override; + void GetDefaultControlPoints(std::vector& ControlPoints) const override; protected: void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray& Sections) const override; @@ -92,7 +92,7 @@ public: lcSynthInfoBraidedString(float Length, int NumSections); protected: - void CalculateSections(const lcArray& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const override; + void CalculateSections(const std::vector& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const override; void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray& Sections) const override; }; @@ -101,10 +101,10 @@ class lcSynthInfoStraight : public lcSynthInfo public: explicit lcSynthInfoStraight(float Length); - void VerifyControlPoints(lcArray& ControlPoints) const override; + void VerifyControlPoints(std::vector& ControlPoints) const override; protected: - void CalculateSections(const lcArray& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const override; + void CalculateSections(const std::vector& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const override; }; class lcSynthInfoShockAbsorber : public lcSynthInfoStraight @@ -112,7 +112,7 @@ class lcSynthInfoShockAbsorber : public lcSynthInfoStraight public: explicit lcSynthInfoShockAbsorber(const char* SpringPart); - void GetDefaultControlPoints(lcArray& ControlPoints) const override; + void GetDefaultControlPoints(std::vector& ControlPoints) const override; protected: void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray& Sections) const override; @@ -125,7 +125,7 @@ class lcSynthInfoActuator : public lcSynthInfoStraight public: explicit lcSynthInfoActuator(const char* BodyPart, const char* PistonPart, const char* AxlePart, float Length, float AxleOffset); - void GetDefaultControlPoints(lcArray& ControlPoints) const override; + void GetDefaultControlPoints(std::vector& ControlPoints) const override; protected: void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray& Sections) const override; @@ -141,11 +141,11 @@ class lcSynthInfoUniversalJoint : public lcSynthInfo public: lcSynthInfoUniversalJoint(float Length, float EndOffset, const char* EndPart, const char* CenterPart); - void GetDefaultControlPoints(lcArray& ControlPoints) const override; - void VerifyControlPoints(lcArray& ControlPoints) const override; + void GetDefaultControlPoints(std::vector& ControlPoints) const override; + void VerifyControlPoints(std::vector& ControlPoints) const override; protected: - void CalculateSections(const lcArray& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const override; + void CalculateSections(const std::vector& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const override; void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray& Sections) const override; float mEndOffset; @@ -538,9 +538,9 @@ lcSynthInfoUniversalJoint::lcSynthInfoUniversalJoint(float Length, float EndOffs mNondirectional = true; } -void lcSynthInfoCurved::GetDefaultControlPoints(lcArray& ControlPoints) const +void lcSynthInfoCurved::GetDefaultControlPoints(std::vector& ControlPoints) const { - ControlPoints.SetSize(2); + ControlPoints.resize(2); float HalfLength = mLength / 2.0f; float Scale = lcMin(mDefaultScale, HalfLength); @@ -552,13 +552,13 @@ void lcSynthInfoCurved::GetDefaultControlPoints(lcArray& Co ControlPoints[1].Scale = Scale; } -void lcSynthInfoCurved::VerifyControlPoints(lcArray& ControlPoints) const +void lcSynthInfoCurved::VerifyControlPoints(std::vector& ControlPoints) const { - if (ControlPoints.GetSize() < 2) + if (ControlPoints.size() < 2) GetDefaultControlPoints(ControlPoints); } -void lcSynthInfoFlexSystemHose::GetDefaultControlPoints(lcArray& ControlPoints) const +void lcSynthInfoFlexSystemHose::GetDefaultControlPoints(std::vector& ControlPoints) const { lcSynthInfoCurved::GetDefaultControlPoints(ControlPoints); @@ -566,17 +566,17 @@ void lcSynthInfoFlexSystemHose::GetDefaultControlPoints(lcArray& ControlPoints) const +void lcSynthInfoStraight::VerifyControlPoints(std::vector& ControlPoints) const { - if (ControlPoints.GetSize() < 2) + if (ControlPoints.size() < 2) GetDefaultControlPoints(ControlPoints); else - ControlPoints.SetSize(2); + ControlPoints.resize(2); } -void lcSynthInfoShockAbsorber::GetDefaultControlPoints(lcArray& ControlPoints) const +void lcSynthInfoShockAbsorber::GetDefaultControlPoints(std::vector& ControlPoints) const { - ControlPoints.SetSize(2); + ControlPoints.resize(2); ControlPoints[0].Transform = lcMatrix44Translation(lcVector3(0.0f, 0.0f, -mLength)); ControlPoints[1].Transform = lcMatrix44Translation(lcVector3(0.0f, 0.0f, 0.0f)); @@ -585,9 +585,9 @@ void lcSynthInfoShockAbsorber::GetDefaultControlPoints(lcArray& ControlPoints) const +void lcSynthInfoActuator::GetDefaultControlPoints(std::vector& ControlPoints) const { - ControlPoints.SetSize(2); + ControlPoints.resize(2); ControlPoints[0].Transform = lcMatrix44(lcMatrix33(lcVector3(1.0f, 0.0f, 0.0f), lcVector3(0.0f, 0.0f, -1.0f), lcVector3(0.0f, 1.0f, 0.0f)), lcVector3(0.0f, 0.0f, 0.0f)); ControlPoints[1].Transform = lcMatrix44(lcMatrix33(lcVector3(1.0f, 0.0f, 0.0f), lcVector3(0.0f, 0.0f, -1.0f), lcVector3(0.0f, 1.0f, 0.0f)), lcVector3(0.0f, mLength, 0.0f)); @@ -596,21 +596,21 @@ void lcSynthInfoActuator::GetDefaultControlPoints(lcArray& ControlPoints[1].Scale = 1.0f; } -void lcSynthInfoUniversalJoint::GetDefaultControlPoints(lcArray& ControlPoints) const +void lcSynthInfoUniversalJoint::GetDefaultControlPoints(std::vector& ControlPoints) const { - ControlPoints.SetSize(1); + ControlPoints.resize(1); float HalfLength = mLength / 2; ControlPoints[0].Transform = lcMatrix44Translation(lcVector3(0.0f, HalfLength, 0.0f)); ControlPoints[0].Scale = 1.0f; } -void lcSynthInfoUniversalJoint::VerifyControlPoints(lcArray& ControlPoints) const +void lcSynthInfoUniversalJoint::VerifyControlPoints(std::vector& ControlPoints) const { - if (ControlPoints.IsEmpty()) + if (ControlPoints.empty()) GetDefaultControlPoints(ControlPoints); else - ControlPoints.SetSize(1); + ControlPoints.resize(1); } float lcSynthInfoCurved::GetSectionTwist(const lcMatrix44& StartTransform, const lcMatrix44& EndTransform) const @@ -658,19 +658,22 @@ float lcSynthInfoCurved::GetSectionTwist(const lcMatrix44& StartTransform, const return 0.0f; } -void lcSynthInfoCurved::CalculateSections(const lcArray& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const +void lcSynthInfoCurved::CalculateSections(const std::vector& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const { + if (ControlPoints.empty()) + return; + float SectionLength = 0.0f; - for (int ControlPointIdx = 0; ControlPointIdx < ControlPoints.GetSize() - 1 && Sections.GetSize() < mNumSections + 2; ControlPointIdx++) + for (quint32 ControlPointIndex = 0; ControlPointIndex < ControlPoints.size() - 1 && Sections.GetSize() < mNumSections + 2; ControlPointIndex++) { lcVector3 SegmentControlPoints[4]; - lcMatrix44 StartTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIdx].Transform); - lcMatrix44 EndTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIdx + 1].Transform); + lcMatrix44 StartTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIndex].Transform); + lcMatrix44 EndTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIndex + 1].Transform); StartTransform = lcMatrix44(lcMul(lcMul(lcMatrix33(mStart.Transform), lcMatrix33(StartTransform)), lcMatrix33Scale(lcVector3(1.0f, -1.0f, 1.0f))), StartTransform.GetTranslation()); - if (ControlPointIdx == 0) + if (ControlPointIndex == 0) { if (mRigidEdges) { @@ -686,8 +689,8 @@ void lcSynthInfoCurved::CalculateSections(const lcArray& Co EndTransform = lcMatrix44(lcMul(lcMul(lcMatrix33(mEnd.Transform), lcMatrix33(EndTransform)), lcMatrix33Scale(lcVector3(1.0f, -1.0f, 1.0f))), EndTransform.GetTranslation()); SegmentControlPoints[0] = StartTransform.GetTranslation(); - SegmentControlPoints[1] = lcMul31(lcVector3(0.0f, ControlPoints[ControlPointIdx].Scale, 0.0f), StartTransform); - SegmentControlPoints[2] = lcMul31(lcVector3(0.0f, -ControlPoints[ControlPointIdx + 1].Scale, 0.0f), EndTransform); + SegmentControlPoints[1] = lcMul31(lcVector3(0.0f, ControlPoints[ControlPointIndex].Scale, 0.0f), StartTransform); + SegmentControlPoints[2] = lcMul31(lcVector3(0.0f, -ControlPoints[ControlPointIndex + 1].Scale, 0.0f), EndTransform); SegmentControlPoints[3] = EndTransform.GetTranslation(); const int NumCurvePoints = 8192; @@ -744,7 +747,7 @@ void lcSynthInfoCurved::CalculateSections(const lcArray& Co Sections.Add(lcMatrix44(lcMatrix33(Up, Tangent, Side), CurvePoints[CurrentPointIndex])); if (SectionCallback) - SectionCallback(CurvePoints[CurrentPointIndex], ControlPointIdx, t); + SectionCallback(CurvePoints[CurrentPointIndex], ControlPointIndex, t); if (Sections.GetSize() == mNumSections + 2) break; @@ -761,14 +764,14 @@ void lcSynthInfoCurved::CalculateSections(const lcArray& Co while (Sections.GetSize() < mNumSections + 2) { - lcMatrix44 EndTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPoints.GetSize() - 1].Transform); + lcMatrix44 EndTransform = lcMatrix44LeoCADToLDraw(ControlPoints.back().Transform); EndTransform = lcMatrix44(lcMul(lcMul(lcMatrix33(mEnd.Transform), lcMatrix33(EndTransform)), lcMatrix33Scale(lcVector3(1.0f, -1.0f, 1.0f))), EndTransform.GetTranslation()); lcVector3 Position = lcMul31(lcVector3(0.0f, SectionLength, 0.0f), EndTransform); EndTransform.SetTranslation(Position); Sections.Add(EndTransform); if (SectionCallback) - SectionCallback(Position, ControlPoints.GetSize() - 1, 1.0f); + SectionCallback(Position, static_cast(ControlPoints.size()) - 1, 1.0f); if (mCenterLength != 0.0f && (Sections.GetSize() == mNumSections / 2 + 1)) SectionLength += mCenterLength; @@ -780,19 +783,22 @@ void lcSynthInfoCurved::CalculateSections(const lcArray& Co } } -void lcSynthInfoBraidedString::CalculateSections(const lcArray& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const +void lcSynthInfoBraidedString::CalculateSections(const std::vector& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const { + if (ControlPoints.empty()) + return; + float SectionLength = 0.0f; - for (int ControlPointIdx = 0; ControlPointIdx < ControlPoints.GetSize() - 1 && Sections.GetSize() < mNumSections + 2; ControlPointIdx++) + for (quint32 ControlPointIndex = 0; ControlPointIndex < ControlPoints.size() - 1 && Sections.GetSize() < mNumSections + 2; ControlPointIndex++) { lcVector3 SegmentControlPoints[4]; - lcMatrix44 StartTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIdx].Transform); - lcMatrix44 EndTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIdx + 1].Transform); + lcMatrix44 StartTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIndex].Transform); + lcMatrix44 EndTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIndex + 1].Transform); StartTransform = lcMatrix44(lcMul(lcMul(lcMatrix33(mStart.Transform), lcMatrix33(StartTransform)), lcMatrix33Scale(lcVector3(1.0f, -1.0f, 1.0f))), StartTransform.GetTranslation()); - if (ControlPointIdx == 0) + if (ControlPointIndex == 0) { if (mRigidEdges) { @@ -808,8 +814,8 @@ void lcSynthInfoBraidedString::CalculateSections(const lcArray(ControlPoints.size()) - 1, 1.0f); if (mCenterLength != 0.0f && (Sections.GetSize() == mNumSections / 2 + 1)) SectionLength += mCenterLength; @@ -902,27 +908,27 @@ void lcSynthInfoBraidedString::CalculateSections(const lcArray& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const +void lcSynthInfoStraight::CalculateSections(const std::vector& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const { - for (int ControlPointIdx = 0; ControlPointIdx < ControlPoints.GetSize(); ControlPointIdx++) + for (quint32 ControlPointIndex = 0; ControlPointIndex < ControlPoints.size(); ControlPointIndex++) { - lcMatrix44 Transform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIdx].Transform); + lcMatrix44 Transform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIndex].Transform); Sections.Add(Transform); if (SectionCallback) - SectionCallback(Transform.GetTranslation(), ControlPointIdx, 1.0f); + SectionCallback(Transform.GetTranslation(), ControlPointIndex, 1.0f); } } -void lcSynthInfoUniversalJoint::CalculateSections(const lcArray& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const +void lcSynthInfoUniversalJoint::CalculateSections(const std::vector& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const { - for (int ControlPointIdx = 0; ControlPointIdx < ControlPoints.GetSize(); ControlPointIdx++) + for (quint32 ControlPointIndex = 0; ControlPointIndex < ControlPoints.size(); ControlPointIndex++) { - lcMatrix44 Transform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIdx].Transform); + lcMatrix44 Transform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIndex].Transform); Sections.Add(Transform); if (SectionCallback) - SectionCallback(Transform.GetTranslation(), ControlPointIdx, 1.0f); + SectionCallback(Transform.GetTranslation(), ControlPointIndex, 1.0f); } } @@ -1497,7 +1503,7 @@ void lcSynthInfoUniversalJoint::AddParts(lcMemFile& File, lcLibraryMeshData&, co File.WriteBuffer(Line, strlen(Line)); } -lcMesh* lcSynthInfo::CreateMesh(const lcArray& ControlPoints) const +lcMesh* lcSynthInfo::CreateMesh(const std::vector& ControlPoints) const { lcArray Sections; @@ -1520,11 +1526,11 @@ lcMesh* lcSynthInfo::CreateMesh(const lcArray& ControlPoint return nullptr; } -int lcSynthInfo::InsertControlPoint(lcArray& ControlPoints, const lcVector3& Start, const lcVector3& End) const +int lcSynthInfo::InsertControlPoint(std::vector& ControlPoints, const lcVector3& Start, const lcVector3& End) const { lcArray Sections; - int BestSegment = -1; + quint32 BestSegment = UINT32_MAX; float BestTime; float BestDistance = FLT_MAX; lcVector3 BestPosition; @@ -1543,18 +1549,18 @@ int lcSynthInfo::InsertControlPoint(lcArray& ControlPoints, } ); - if (BestSegment != -1) + if (BestSegment != UINT32_MAX) { lcPieceControlPoint ControlPoint = ControlPoints[BestSegment]; ControlPoint.Transform.SetTranslation(BestPosition); - if (BestSegment != ControlPoints.GetSize() - 1) + if (BestSegment != ControlPoints.size() - 1) { lcPieceControlPoint NextControlPoint = ControlPoints[BestSegment + 1]; ControlPoint.Scale = ControlPoint.Scale * (1.0f - BestTime) + NextControlPoint.Scale * BestTime; } - ControlPoints.InsertAt(BestSegment + 1, ControlPoint); + ControlPoints.insert(ControlPoints.begin() + BestSegment + 1, ControlPoint); } return BestSegment + 1; diff --git a/common/lc_synth.h b/common/lc_synth.h index 4f15601c..1644c308 100644 --- a/common/lc_synth.h +++ b/common/lc_synth.h @@ -36,14 +36,14 @@ public: return mNondirectional; } - virtual void GetDefaultControlPoints(lcArray& ControlPoints) const = 0; - virtual void VerifyControlPoints(lcArray& ControlPoints) const = 0; - int InsertControlPoint(lcArray& ControlPoints, const lcVector3& Start, const lcVector3& End) const; - lcMesh* CreateMesh(const lcArray& ControlPoints) const; + virtual void GetDefaultControlPoints(std::vector& ControlPoints) const = 0; + virtual void VerifyControlPoints(std::vector& ControlPoints) const = 0; + int InsertControlPoint(std::vector& ControlPoints, const lcVector3& Start, const lcVector3& End) const; + lcMesh* CreateMesh(const std::vector& ControlPoints) const; protected: - using SectionCallbackFunc = std::function; - virtual void CalculateSections(const lcArray& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const = 0; + using SectionCallbackFunc = std::function; + virtual void CalculateSections(const std::vector& ControlPoints, lcArray& Sections, SectionCallbackFunc SectionCallback) const = 0; virtual void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray& Sections) const = 0; bool mCurve = false; diff --git a/common/piece.cpp b/common/piece.cpp index 6e442133..0f3ac800 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -77,7 +77,7 @@ void lcPiece::SetPieceInfo(PieceInfo* Info, const QString& ID, bool Wait) else mID.clear(); - mControlPoints.RemoveAll(); + mControlPoints.clear(); delete mMesh; mMesh = nullptr; @@ -492,9 +492,9 @@ void lcPiece::RayTest(lcObjectRayTest& ObjectRayTest) const const lcVector3 Min(-LC_PIECE_CONTROL_POINT_SIZE, -LC_PIECE_CONTROL_POINT_SIZE, -LC_PIECE_CONTROL_POINT_SIZE); const lcVector3 Max(LC_PIECE_CONTROL_POINT_SIZE, LC_PIECE_CONTROL_POINT_SIZE, LC_PIECE_CONTROL_POINT_SIZE); - for (int ControlPointIdx = 0; ControlPointIdx < mControlPoints.GetSize(); ControlPointIdx++) + for (quint32 ControlPointIndex = 0; ControlPointIndex < mControlPoints.size(); ControlPointIndex++) { - const lcMatrix44 InverseTransform = lcMatrix44AffineInverse(mControlPoints[ControlPointIdx].Transform); + const lcMatrix44 InverseTransform = lcMatrix44AffineInverse(mControlPoints[ControlPointIndex].Transform); const lcVector3 PointStart = lcMul31(Start, InverseTransform); const lcVector3 PointEnd = lcMul31(End, InverseTransform); @@ -504,7 +504,7 @@ void lcPiece::RayTest(lcObjectRayTest& ObjectRayTest) const if (lcBoundingBoxRayIntersectDistance(Min, Max, PointStart, PointEnd, &Distance, nullptr, &Plane)) { ObjectRayTest.ObjectSection.Object = const_cast(this); - ObjectRayTest.ObjectSection.Section = LC_PIECE_SECTION_CONTROL_POINT_FIRST + ControlPointIdx; + ObjectRayTest.ObjectSection.Section = LC_PIECE_SECTION_CONTROL_POINT_FIRST + ControlPointIndex; ObjectRayTest.Distance = Distance; ObjectRayTest.PieceInfoRayTest.Plane = Plane; } @@ -608,7 +608,7 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const Context->DrawIndexedPrimitives(GL_LINES, 24, GL_UNSIGNED_SHORT, 0); } - if (!mControlPoints.IsEmpty() && AreControlPointsVisible()) + if (!mControlPoints.empty() && AreControlPointsVisible()) { float Verts[8 * 3]; float* CurVert = Verts; @@ -637,15 +637,15 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const const lcVector4 ControlPointColor = lcVector4FromColor(Preferences.mControlPointColor); const lcVector4 ControlPointFocusedColor = lcVector4FromColor(Preferences.mControlPointFocusedColor); - for (int ControlPointIdx = 0; ControlPointIdx < mControlPoints.GetSize(); ControlPointIdx++) + for (quint32 ControlPointIndex = 0; ControlPointIndex < mControlPoints.size(); ControlPointIndex++) { - Context->SetWorldMatrix(lcMul(mControlPoints[ControlPointIdx].Transform, WorldMatrix)); + Context->SetWorldMatrix(lcMul(mControlPoints[ControlPointIndex].Transform, WorldMatrix)); Context->SetVertexBufferPointer(Verts); Context->SetVertexFormatPosition(3); Context->SetIndexBufferPointer(Indices); - if (IsFocused(LC_PIECE_SECTION_CONTROL_POINT_FIRST + ControlPointIdx)) + if (IsFocused(LC_PIECE_SECTION_CONTROL_POINT_FIRST + ControlPointIndex)) Context->SetColor(ControlPointFocusedColor); else Context->SetColor(ControlPointColor); @@ -990,11 +990,11 @@ void lcPiece::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance) mModelWorld.SetTranslation(Position); } - else + else if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST) { - const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; + const quint32 ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; - if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) + if (ControlPointIndex < mControlPoints.size()) { const lcMatrix33 InverseWorldMatrix = lcMatrix33AffineInverse(lcMatrix33(mModelWorld)); lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; @@ -1028,11 +1028,11 @@ void lcPiece::Rotate(lcStep Step, bool AddKey, const lcMatrix33& RotationMatrix, SetPosition(Center + Distance, Step, AddKey); SetRotation(NewLocalToWorldMatrix, Step, AddKey); } - else + else if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST) { - const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; + const quint32 ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; - if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) + if (ControlPointIndex < mControlPoints.size()) { lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; const lcMatrix33 PieceWorldMatrix(mModelWorld); @@ -1096,7 +1096,7 @@ quint32 lcPiece::GetAllowedTransforms() const bool lcPiece::CanAddControlPoint() const { - if (mControlPoints.GetSize() >= LC_MAX_CONTROL_POINTS) + if (mControlPoints.size() >= LC_MAX_CONTROL_POINTS) return false; const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo(); @@ -1106,7 +1106,7 @@ bool lcPiece::CanAddControlPoint() const bool lcPiece::CanRemoveControlPoint() const { const quint32 Section = GetFocusSection(); - return Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST && Section <= LC_PIECE_SECTION_CONTROL_POINT_LAST && mControlPoints.GetSize() > 2; + return Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST && Section <= LC_PIECE_SECTION_CONTROL_POINT_LAST && mControlPoints.size() > 2; } bool lcPiece::InsertControlPoint(const lcVector3& WorldStart, const lcVector3& WorldEnd) @@ -1134,32 +1134,37 @@ bool lcPiece::InsertControlPoint(const lcVector3& WorldStart, const lcVector3& W bool lcPiece::RemoveFocusedControlPoint() { - const int ControlPointIndex = GetFocusSection() - LC_PIECE_SECTION_CONTROL_POINT_FIRST; + quint32 Section = GetFocusSection(); - if (ControlPointIndex < 0 || ControlPointIndex >= mControlPoints.GetSize() || mControlPoints.GetSize() <= 2) + if( Section < LC_PIECE_SECTION_CONTROL_POINT_FIRST ) + return false; + + const quint32 ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; + + if (ControlPointIndex >= mControlPoints.size() || mControlPoints.size() <= 2) return false; SetFocused(GetFocusSection(), false); SetFocused(LC_PIECE_SECTION_POSITION, true); - mControlPoints.RemoveIndex(ControlPointIndex); + mControlPoints.erase(mControlPoints.begin() + ControlPointIndex); UpdateMesh(); return true; } -void lcPiece::VerifyControlPoints(lcArray& ControlPoints) const +void lcPiece::VerifyControlPoints(std::vector& ControlPoints) const { const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo(); if (!SynthInfo) { - ControlPoints.RemoveAll(); + ControlPoints.clear(); } else { - if (ControlPoints.GetSize() > LC_MAX_CONTROL_POINTS) - ControlPoints.SetSize(LC_MAX_CONTROL_POINTS); + if (ControlPoints.size() > LC_MAX_CONTROL_POINTS) + ControlPoints.resize(LC_MAX_CONTROL_POINTS); SynthInfo->VerifyControlPoints(ControlPoints); } diff --git a/common/piece.h b/common/piece.h index 43aca3f6..e1db7371 100644 --- a/common/piece.h +++ b/common/piece.h @@ -100,11 +100,11 @@ public: else return mModelWorld.GetTranslation(); } - else + else if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST) { - const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; + const quint32 ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; - if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) + if (ControlPointIndex < mControlPoints.size()) { const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; return lcMul(Transform, mModelWorld).GetTranslation(); @@ -154,12 +154,12 @@ public: mHidden = Hidden; } - const lcArray& GetControlPoints() const + const std::vector& GetControlPoints() const { return mControlPoints; } - void SetControlPoints(const lcArray& ControlPoints) + void SetControlPoints(const std::vector& ControlPoints) { mControlPoints = ControlPoints; UpdateMesh(); @@ -200,7 +200,7 @@ public: bool InsertControlPoint(const lcVector3& WorldStart, const lcVector3& WorldEnd); bool RemoveFocusedControlPoint(); - void VerifyControlPoints(lcArray& ControlPoints) const; + void VerifyControlPoints(std::vector& ControlPoints) const; lcGroup* GetTopGroup(); @@ -295,21 +295,19 @@ public: { if (mPivotPointValid) return lcMul31(mPivotMatrix.GetTranslation(), mModelWorld); - else - return mModelWorld.GetTranslation(); } - else + else if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST) { - const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; + const quint32 ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; - if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) + if (ControlPointIndex < mControlPoints.size()) { const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; return lcMul31(Transform.GetTranslation(), mModelWorld); } - - return mModelWorld.GetTranslation(); } + + return mModelWorld.GetTranslation(); } lcMatrix33 GetRelativeRotation() const @@ -323,18 +321,18 @@ public: else return lcMatrix33(mModelWorld); } - else + else if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST) { - const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; + const quint32 ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; - if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) + if (ControlPointIndex < mControlPoints.size()) { const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; return lcMatrix33(lcMul(Transform, mModelWorld)); } - - return lcMatrix33Identity(); } + + return lcMatrix33Identity(); } void ResetPivotPoint() @@ -380,6 +378,6 @@ protected: bool mHidden = false; bool mSelected = false; quint32 mFocusedSection = LC_PIECE_SECTION_INVALID; - lcArray mControlPoints; + std::vector mControlPoints; lcMesh* mMesh = nullptr; };