Removed lcArray from control points.

This commit is contained in:
Leonardo Zide 2024-05-12 12:45:15 -07:00
parent a3646c9728
commit aae75b36fe
5 changed files with 127 additions and 120 deletions

View file

@ -452,11 +452,9 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly, lcStep LastStep)
{ {
Stream << QLatin1String("0 !LEOCAD SYNTH BEGIN\r\n"); Stream << QLatin1String("0 !LEOCAD SYNTH BEGIN\r\n");
const lcArray<lcPieceControlPoint>& ControlPoints = Piece->GetControlPoints(); const std::vector<lcPieceControlPoint>& ControlPoints = Piece->GetControlPoints();
for (int ControlPointIdx = 0; ControlPointIdx < ControlPoints.GetSize(); ControlPointIdx++) for (const lcPieceControlPoint& ControlPoint : ControlPoints)
{ {
const lcPieceControlPoint& ControlPoint = ControlPoints[ControlPointIdx];
Stream << QLatin1String("0 !LEOCAD SYNTH CONTROL_POINT"); Stream << QLatin1String("0 !LEOCAD SYNTH CONTROL_POINT");
const float* FloatMatrix = ControlPoint.Transform; const float* FloatMatrix = ControlPoint.Transform;
@ -559,7 +557,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
lcCamera* Camera = nullptr; lcCamera* Camera = nullptr;
lcLight* Light = nullptr; lcLight* Light = nullptr;
lcArray<lcGroup*> CurrentGroups; lcArray<lcGroup*> CurrentGroups;
lcArray<lcPieceControlPoint> ControlPoints; std::vector<lcPieceControlPoint> ControlPoints;
int CurrentStep = 1; int CurrentStep = 1;
lcPiecesLibrary* Library = lcGetPiecesLibrary(); lcPiecesLibrary* Library = lcGetPiecesLibrary();
@ -691,11 +689,11 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
if (Token == QLatin1String("BEGIN")) if (Token == QLatin1String("BEGIN"))
{ {
ControlPoints.RemoveAll(); ControlPoints.clear();
} }
else if (Token == QLatin1String("END")) else if (Token == QLatin1String("END"))
{ {
ControlPoints.RemoveAll(); ControlPoints.clear();
} }
else if (Token == QLatin1String("CONTROL_POINT")) else if (Token == QLatin1String("CONTROL_POINT"))
{ {
@ -703,7 +701,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
for (int TokenIdx = 0; TokenIdx < 13; TokenIdx++) for (int TokenIdx = 0; TokenIdx < 13; TokenIdx++)
LineStream >> Numbers[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), 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)); lcVector4(-Numbers[4], -Numbers[10], Numbers[7], 0.0f), lcVector4(Numbers[0], Numbers[2], -Numbers[1], 1.0f));
PieceControlPoint.Scale = Numbers[12]; PieceControlPoint.Scale = Numbers[12];
@ -756,7 +754,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
Piece->SetColorCode(ColorCode); Piece->SetColorCode(ColorCode);
Piece->VerifyControlPoints(ControlPoints); Piece->VerifyControlPoints(ControlPoints);
Piece->SetControlPoints(ControlPoints); Piece->SetControlPoints(ControlPoints);
ControlPoints.RemoveAll(); ControlPoints.clear();
if (Piece->mPieceInfo->IsModel() && Piece->mPieceInfo->GetModel()->IncludesModel(this)) if (Piece->mPieceInfo->IsModel() && Piece->mPieceInfo->GetModel()->IncludesModel(this))
{ {

View file

@ -12,12 +12,12 @@ class lcSynthInfoCurved : public lcSynthInfo
public: public:
lcSynthInfoCurved(float Length, float DefaultScale, int NumSections, bool RigidEdges); lcSynthInfoCurved(float Length, float DefaultScale, int NumSections, bool RigidEdges);
void GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const override; void GetDefaultControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const override;
void VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const override; void VerifyControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const override;
protected: protected:
float GetSectionTwist(const lcMatrix44& StartTransform, const lcMatrix44& EndTransform) const; float GetSectionTwist(const lcMatrix44& StartTransform, const lcMatrix44& EndTransform) const;
void CalculateSections(const lcArray<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const override; void CalculateSections(const std::vector<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const override;
static void AddTubeParts(lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections, float Radius, bool IsInner); static void AddTubeParts(lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections, float Radius, bool IsInner);
struct lcSynthComponent struct lcSynthComponent
@ -51,7 +51,7 @@ class lcSynthInfoFlexSystemHose : public lcSynthInfoCurved
public: public:
lcSynthInfoFlexSystemHose(float Length, int NumSections); lcSynthInfoFlexSystemHose(float Length, int NumSections);
void GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const override; void GetDefaultControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const override;
protected: protected:
void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const override; void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const override;
@ -92,7 +92,7 @@ public:
lcSynthInfoBraidedString(float Length, int NumSections); lcSynthInfoBraidedString(float Length, int NumSections);
protected: protected:
void CalculateSections(const lcArray<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const override; void CalculateSections(const std::vector<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const override;
void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const override; void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const override;
}; };
@ -101,10 +101,10 @@ class lcSynthInfoStraight : public lcSynthInfo
public: public:
explicit lcSynthInfoStraight(float Length); explicit lcSynthInfoStraight(float Length);
void VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const override; void VerifyControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const override;
protected: protected:
void CalculateSections(const lcArray<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const override; void CalculateSections(const std::vector<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const override;
}; };
class lcSynthInfoShockAbsorber : public lcSynthInfoStraight class lcSynthInfoShockAbsorber : public lcSynthInfoStraight
@ -112,7 +112,7 @@ class lcSynthInfoShockAbsorber : public lcSynthInfoStraight
public: public:
explicit lcSynthInfoShockAbsorber(const char* SpringPart); explicit lcSynthInfoShockAbsorber(const char* SpringPart);
void GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const override; void GetDefaultControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const override;
protected: protected:
void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const override; void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const override;
@ -125,7 +125,7 @@ class lcSynthInfoActuator : public lcSynthInfoStraight
public: public:
explicit lcSynthInfoActuator(const char* BodyPart, const char* PistonPart, const char* AxlePart, float Length, float AxleOffset); explicit lcSynthInfoActuator(const char* BodyPart, const char* PistonPart, const char* AxlePart, float Length, float AxleOffset);
void GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const override; void GetDefaultControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const override;
protected: protected:
void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const override; void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const override;
@ -141,11 +141,11 @@ class lcSynthInfoUniversalJoint : public lcSynthInfo
public: public:
lcSynthInfoUniversalJoint(float Length, float EndOffset, const char* EndPart, const char* CenterPart); lcSynthInfoUniversalJoint(float Length, float EndOffset, const char* EndPart, const char* CenterPart);
void GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const override; void GetDefaultControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const override;
void VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const override; void VerifyControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const override;
protected: protected:
void CalculateSections(const lcArray<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const override; void CalculateSections(const std::vector<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const override;
void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const override; void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const override;
float mEndOffset; float mEndOffset;
@ -538,9 +538,9 @@ lcSynthInfoUniversalJoint::lcSynthInfoUniversalJoint(float Length, float EndOffs
mNondirectional = true; mNondirectional = true;
} }
void lcSynthInfoCurved::GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const void lcSynthInfoCurved::GetDefaultControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const
{ {
ControlPoints.SetSize(2); ControlPoints.resize(2);
float HalfLength = mLength / 2.0f; float HalfLength = mLength / 2.0f;
float Scale = lcMin(mDefaultScale, HalfLength); float Scale = lcMin(mDefaultScale, HalfLength);
@ -552,13 +552,13 @@ void lcSynthInfoCurved::GetDefaultControlPoints(lcArray<lcPieceControlPoint>& Co
ControlPoints[1].Scale = Scale; ControlPoints[1].Scale = Scale;
} }
void lcSynthInfoCurved::VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const void lcSynthInfoCurved::VerifyControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const
{ {
if (ControlPoints.GetSize() < 2) if (ControlPoints.size() < 2)
GetDefaultControlPoints(ControlPoints); GetDefaultControlPoints(ControlPoints);
} }
void lcSynthInfoFlexSystemHose::GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const void lcSynthInfoFlexSystemHose::GetDefaultControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const
{ {
lcSynthInfoCurved::GetDefaultControlPoints(ControlPoints); lcSynthInfoCurved::GetDefaultControlPoints(ControlPoints);
@ -566,17 +566,17 @@ void lcSynthInfoFlexSystemHose::GetDefaultControlPoints(lcArray<lcPieceControlPo
ControlPoints[1].Transform = lcMatrix44Translation(lcVector3(0.0f, 0.0f, 0.0f)); ControlPoints[1].Transform = lcMatrix44Translation(lcVector3(0.0f, 0.0f, 0.0f));
} }
void lcSynthInfoStraight::VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const void lcSynthInfoStraight::VerifyControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const
{ {
if (ControlPoints.GetSize() < 2) if (ControlPoints.size() < 2)
GetDefaultControlPoints(ControlPoints); GetDefaultControlPoints(ControlPoints);
else else
ControlPoints.SetSize(2); ControlPoints.resize(2);
} }
void lcSynthInfoShockAbsorber::GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const void lcSynthInfoShockAbsorber::GetDefaultControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const
{ {
ControlPoints.SetSize(2); ControlPoints.resize(2);
ControlPoints[0].Transform = lcMatrix44Translation(lcVector3(0.0f, 0.0f, -mLength)); ControlPoints[0].Transform = lcMatrix44Translation(lcVector3(0.0f, 0.0f, -mLength));
ControlPoints[1].Transform = lcMatrix44Translation(lcVector3(0.0f, 0.0f, 0.0f)); ControlPoints[1].Transform = lcMatrix44Translation(lcVector3(0.0f, 0.0f, 0.0f));
@ -585,9 +585,9 @@ void lcSynthInfoShockAbsorber::GetDefaultControlPoints(lcArray<lcPieceControlPoi
ControlPoints[1].Scale = 1.0f; ControlPoints[1].Scale = 1.0f;
} }
void lcSynthInfoActuator::GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const void lcSynthInfoActuator::GetDefaultControlPoints(std::vector<lcPieceControlPoint>& 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[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)); 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<lcPieceControlPoint>&
ControlPoints[1].Scale = 1.0f; ControlPoints[1].Scale = 1.0f;
} }
void lcSynthInfoUniversalJoint::GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const void lcSynthInfoUniversalJoint::GetDefaultControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const
{ {
ControlPoints.SetSize(1); ControlPoints.resize(1);
float HalfLength = mLength / 2; float HalfLength = mLength / 2;
ControlPoints[0].Transform = lcMatrix44Translation(lcVector3(0.0f, HalfLength, 0.0f)); ControlPoints[0].Transform = lcMatrix44Translation(lcVector3(0.0f, HalfLength, 0.0f));
ControlPoints[0].Scale = 1.0f; ControlPoints[0].Scale = 1.0f;
} }
void lcSynthInfoUniversalJoint::VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const void lcSynthInfoUniversalJoint::VerifyControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const
{ {
if (ControlPoints.IsEmpty()) if (ControlPoints.empty())
GetDefaultControlPoints(ControlPoints); GetDefaultControlPoints(ControlPoints);
else else
ControlPoints.SetSize(1); ControlPoints.resize(1);
} }
float lcSynthInfoCurved::GetSectionTwist(const lcMatrix44& StartTransform, const lcMatrix44& EndTransform) const float lcSynthInfoCurved::GetSectionTwist(const lcMatrix44& StartTransform, const lcMatrix44& EndTransform) const
@ -658,19 +658,22 @@ float lcSynthInfoCurved::GetSectionTwist(const lcMatrix44& StartTransform, const
return 0.0f; return 0.0f;
} }
void lcSynthInfoCurved::CalculateSections(const lcArray<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const void lcSynthInfoCurved::CalculateSections(const std::vector<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const
{ {
if (ControlPoints.empty())
return;
float SectionLength = 0.0f; 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]; lcVector3 SegmentControlPoints[4];
lcMatrix44 StartTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIdx].Transform); lcMatrix44 StartTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIndex].Transform);
lcMatrix44 EndTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIdx + 1].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()); 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) if (mRigidEdges)
{ {
@ -686,8 +689,8 @@ void lcSynthInfoCurved::CalculateSections(const lcArray<lcPieceControlPoint>& Co
EndTransform = lcMatrix44(lcMul(lcMul(lcMatrix33(mEnd.Transform), lcMatrix33(EndTransform)), lcMatrix33Scale(lcVector3(1.0f, -1.0f, 1.0f))), EndTransform.GetTranslation()); EndTransform = lcMatrix44(lcMul(lcMul(lcMatrix33(mEnd.Transform), lcMatrix33(EndTransform)), lcMatrix33Scale(lcVector3(1.0f, -1.0f, 1.0f))), EndTransform.GetTranslation());
SegmentControlPoints[0] = StartTransform.GetTranslation(); SegmentControlPoints[0] = StartTransform.GetTranslation();
SegmentControlPoints[1] = lcMul31(lcVector3(0.0f, ControlPoints[ControlPointIdx].Scale, 0.0f), StartTransform); SegmentControlPoints[1] = lcMul31(lcVector3(0.0f, ControlPoints[ControlPointIndex].Scale, 0.0f), StartTransform);
SegmentControlPoints[2] = lcMul31(lcVector3(0.0f, -ControlPoints[ControlPointIdx + 1].Scale, 0.0f), EndTransform); SegmentControlPoints[2] = lcMul31(lcVector3(0.0f, -ControlPoints[ControlPointIndex + 1].Scale, 0.0f), EndTransform);
SegmentControlPoints[3] = EndTransform.GetTranslation(); SegmentControlPoints[3] = EndTransform.GetTranslation();
const int NumCurvePoints = 8192; const int NumCurvePoints = 8192;
@ -744,7 +747,7 @@ void lcSynthInfoCurved::CalculateSections(const lcArray<lcPieceControlPoint>& Co
Sections.Add(lcMatrix44(lcMatrix33(Up, Tangent, Side), CurvePoints[CurrentPointIndex])); Sections.Add(lcMatrix44(lcMatrix33(Up, Tangent, Side), CurvePoints[CurrentPointIndex]));
if (SectionCallback) if (SectionCallback)
SectionCallback(CurvePoints[CurrentPointIndex], ControlPointIdx, t); SectionCallback(CurvePoints[CurrentPointIndex], ControlPointIndex, t);
if (Sections.GetSize() == mNumSections + 2) if (Sections.GetSize() == mNumSections + 2)
break; break;
@ -761,14 +764,14 @@ void lcSynthInfoCurved::CalculateSections(const lcArray<lcPieceControlPoint>& Co
while (Sections.GetSize() < mNumSections + 2) 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()); 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); lcVector3 Position = lcMul31(lcVector3(0.0f, SectionLength, 0.0f), EndTransform);
EndTransform.SetTranslation(Position); EndTransform.SetTranslation(Position);
Sections.Add(EndTransform); Sections.Add(EndTransform);
if (SectionCallback) if (SectionCallback)
SectionCallback(Position, ControlPoints.GetSize() - 1, 1.0f); SectionCallback(Position, static_cast<quint32>(ControlPoints.size()) - 1, 1.0f);
if (mCenterLength != 0.0f && (Sections.GetSize() == mNumSections / 2 + 1)) if (mCenterLength != 0.0f && (Sections.GetSize() == mNumSections / 2 + 1))
SectionLength += mCenterLength; SectionLength += mCenterLength;
@ -780,19 +783,22 @@ void lcSynthInfoCurved::CalculateSections(const lcArray<lcPieceControlPoint>& Co
} }
} }
void lcSynthInfoBraidedString::CalculateSections(const lcArray<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const void lcSynthInfoBraidedString::CalculateSections(const std::vector<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const
{ {
if (ControlPoints.empty())
return;
float SectionLength = 0.0f; 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]; lcVector3 SegmentControlPoints[4];
lcMatrix44 StartTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIdx].Transform); lcMatrix44 StartTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIndex].Transform);
lcMatrix44 EndTransform = lcMatrix44LeoCADToLDraw(ControlPoints[ControlPointIdx + 1].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()); 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) if (mRigidEdges)
{ {
@ -808,8 +814,8 @@ void lcSynthInfoBraidedString::CalculateSections(const lcArray<lcPieceControlPoi
EndTransform = lcMatrix44(lcMul(lcMul(lcMatrix33(mEnd.Transform), lcMatrix33(EndTransform)), lcMatrix33Scale(lcVector3(1.0f, -1.0f, 1.0f))), EndTransform.GetTranslation()); EndTransform = lcMatrix44(lcMul(lcMul(lcMatrix33(mEnd.Transform), lcMatrix33(EndTransform)), lcMatrix33Scale(lcVector3(1.0f, -1.0f, 1.0f))), EndTransform.GetTranslation());
SegmentControlPoints[0] = StartTransform.GetTranslation(); SegmentControlPoints[0] = StartTransform.GetTranslation();
SegmentControlPoints[1] = lcMul31(lcVector3(ControlPoints[ControlPointIdx].Scale, 0.0f, 0.0f), StartTransform); SegmentControlPoints[1] = lcMul31(lcVector3(ControlPoints[ControlPointIndex].Scale, 0.0f, 0.0f), StartTransform);
SegmentControlPoints[2] = lcMul31(lcVector3(-ControlPoints[ControlPointIdx + 1].Scale, 0.0f, 0.0f), EndTransform); SegmentControlPoints[2] = lcMul31(lcVector3(-ControlPoints[ControlPointIndex + 1].Scale, 0.0f, 0.0f), EndTransform);
SegmentControlPoints[3] = EndTransform.GetTranslation(); SegmentControlPoints[3] = EndTransform.GetTranslation();
const int NumCurvePoints = 8192; const int NumCurvePoints = 8192;
@ -866,7 +872,7 @@ void lcSynthInfoBraidedString::CalculateSections(const lcArray<lcPieceControlPoi
Sections.Add(lcMatrix44(lcMatrix33(Tangent, Up, -Side), CurvePoints[CurrentPointIndex])); Sections.Add(lcMatrix44(lcMatrix33(Tangent, Up, -Side), CurvePoints[CurrentPointIndex]));
if (SectionCallback) if (SectionCallback)
SectionCallback(CurvePoints[CurrentPointIndex], ControlPointIdx, t); SectionCallback(CurvePoints[CurrentPointIndex], ControlPointIndex, t);
if (Sections.GetSize() == mNumSections + 2) if (Sections.GetSize() == mNumSections + 2)
break; break;
@ -883,14 +889,14 @@ void lcSynthInfoBraidedString::CalculateSections(const lcArray<lcPieceControlPoi
while (Sections.GetSize() < mNumSections + 2) 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()); EndTransform = lcMatrix44(lcMul(lcMul(lcMatrix33(mEnd.Transform), lcMatrix33(EndTransform)), lcMatrix33Scale(lcVector3(1.0f, -1.0f, 1.0f))), EndTransform.GetTranslation());
lcVector3 Position = lcMul31(lcVector3(SectionLength, 0.0f, 0.0f), EndTransform); lcVector3 Position = lcMul31(lcVector3(SectionLength, 0.0f, 0.0f), EndTransform);
EndTransform.SetTranslation(Position); EndTransform.SetTranslation(Position);
Sections.Add(EndTransform); Sections.Add(EndTransform);
if (SectionCallback) if (SectionCallback)
SectionCallback(Position, ControlPoints.GetSize() - 1, 1.0f); SectionCallback(Position, static_cast<quint32>(ControlPoints.size()) - 1, 1.0f);
if (mCenterLength != 0.0f && (Sections.GetSize() == mNumSections / 2 + 1)) if (mCenterLength != 0.0f && (Sections.GetSize() == mNumSections / 2 + 1))
SectionLength += mCenterLength; SectionLength += mCenterLength;
@ -902,27 +908,27 @@ void lcSynthInfoBraidedString::CalculateSections(const lcArray<lcPieceControlPoi
} }
} }
void lcSynthInfoStraight::CalculateSections(const lcArray<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const void lcSynthInfoStraight::CalculateSections(const std::vector<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& 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); Sections.Add(Transform);
if (SectionCallback) if (SectionCallback)
SectionCallback(Transform.GetTranslation(), ControlPointIdx, 1.0f); SectionCallback(Transform.GetTranslation(), ControlPointIndex, 1.0f);
} }
} }
void lcSynthInfoUniversalJoint::CalculateSections(const lcArray<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const void lcSynthInfoUniversalJoint::CalculateSections(const std::vector<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& 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); Sections.Add(Transform);
if (SectionCallback) 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)); File.WriteBuffer(Line, strlen(Line));
} }
lcMesh* lcSynthInfo::CreateMesh(const lcArray<lcPieceControlPoint>& ControlPoints) const lcMesh* lcSynthInfo::CreateMesh(const std::vector<lcPieceControlPoint>& ControlPoints) const
{ {
lcArray<lcMatrix44> Sections; lcArray<lcMatrix44> Sections;
@ -1520,11 +1526,11 @@ lcMesh* lcSynthInfo::CreateMesh(const lcArray<lcPieceControlPoint>& ControlPoint
return nullptr; return nullptr;
} }
int lcSynthInfo::InsertControlPoint(lcArray<lcPieceControlPoint>& ControlPoints, const lcVector3& Start, const lcVector3& End) const int lcSynthInfo::InsertControlPoint(std::vector<lcPieceControlPoint>& ControlPoints, const lcVector3& Start, const lcVector3& End) const
{ {
lcArray<lcMatrix44> Sections; lcArray<lcMatrix44> Sections;
int BestSegment = -1; quint32 BestSegment = UINT32_MAX;
float BestTime; float BestTime;
float BestDistance = FLT_MAX; float BestDistance = FLT_MAX;
lcVector3 BestPosition; lcVector3 BestPosition;
@ -1543,18 +1549,18 @@ int lcSynthInfo::InsertControlPoint(lcArray<lcPieceControlPoint>& ControlPoints,
} }
); );
if (BestSegment != -1) if (BestSegment != UINT32_MAX)
{ {
lcPieceControlPoint ControlPoint = ControlPoints[BestSegment]; lcPieceControlPoint ControlPoint = ControlPoints[BestSegment];
ControlPoint.Transform.SetTranslation(BestPosition); ControlPoint.Transform.SetTranslation(BestPosition);
if (BestSegment != ControlPoints.GetSize() - 1) if (BestSegment != ControlPoints.size() - 1)
{ {
lcPieceControlPoint NextControlPoint = ControlPoints[BestSegment + 1]; lcPieceControlPoint NextControlPoint = ControlPoints[BestSegment + 1];
ControlPoint.Scale = ControlPoint.Scale * (1.0f - BestTime) + NextControlPoint.Scale * BestTime; 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; return BestSegment + 1;

View file

@ -36,14 +36,14 @@ public:
return mNondirectional; return mNondirectional;
} }
virtual void GetDefaultControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const = 0; virtual void GetDefaultControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const = 0;
virtual void VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const = 0; virtual void VerifyControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const = 0;
int InsertControlPoint(lcArray<lcPieceControlPoint>& ControlPoints, const lcVector3& Start, const lcVector3& End) const; int InsertControlPoint(std::vector<lcPieceControlPoint>& ControlPoints, const lcVector3& Start, const lcVector3& End) const;
lcMesh* CreateMesh(const lcArray<lcPieceControlPoint>& ControlPoints) const; lcMesh* CreateMesh(const std::vector<lcPieceControlPoint>& ControlPoints) const;
protected: protected:
using SectionCallbackFunc = std::function<void(const lcVector3& CurvePoint, int SegmentIndex, float t)>; using SectionCallbackFunc = std::function<void(const lcVector3& CurvePoint, quint32 SegmentIndex, float t)>;
virtual void CalculateSections(const lcArray<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const = 0; virtual void CalculateSections(const std::vector<lcPieceControlPoint>& ControlPoints, lcArray<lcMatrix44>& Sections, SectionCallbackFunc SectionCallback) const = 0;
virtual void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const = 0; virtual void AddParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray<lcMatrix44>& Sections) const = 0;
bool mCurve = false; bool mCurve = false;

View file

@ -77,7 +77,7 @@ void lcPiece::SetPieceInfo(PieceInfo* Info, const QString& ID, bool Wait)
else else
mID.clear(); mID.clear();
mControlPoints.RemoveAll(); mControlPoints.clear();
delete mMesh; delete mMesh;
mMesh = nullptr; 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 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); 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 PointStart = lcMul31(Start, InverseTransform);
const lcVector3 PointEnd = lcMul31(End, 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)) if (lcBoundingBoxRayIntersectDistance(Min, Max, PointStart, PointEnd, &Distance, nullptr, &Plane))
{ {
ObjectRayTest.ObjectSection.Object = const_cast<lcPiece*>(this); ObjectRayTest.ObjectSection.Object = const_cast<lcPiece*>(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.Distance = Distance;
ObjectRayTest.PieceInfoRayTest.Plane = Plane; 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); Context->DrawIndexedPrimitives(GL_LINES, 24, GL_UNSIGNED_SHORT, 0);
} }
if (!mControlPoints.IsEmpty() && AreControlPointsVisible()) if (!mControlPoints.empty() && AreControlPointsVisible())
{ {
float Verts[8 * 3]; float Verts[8 * 3];
float* CurVert = Verts; float* CurVert = Verts;
@ -637,15 +637,15 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const
const lcVector4 ControlPointColor = lcVector4FromColor(Preferences.mControlPointColor); const lcVector4 ControlPointColor = lcVector4FromColor(Preferences.mControlPointColor);
const lcVector4 ControlPointFocusedColor = lcVector4FromColor(Preferences.mControlPointFocusedColor); 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->SetVertexBufferPointer(Verts);
Context->SetVertexFormatPosition(3); Context->SetVertexFormatPosition(3);
Context->SetIndexBufferPointer(Indices); Context->SetIndexBufferPointer(Indices);
if (IsFocused(LC_PIECE_SECTION_CONTROL_POINT_FIRST + ControlPointIdx)) if (IsFocused(LC_PIECE_SECTION_CONTROL_POINT_FIRST + ControlPointIndex))
Context->SetColor(ControlPointFocusedColor); Context->SetColor(ControlPointFocusedColor);
else else
Context->SetColor(ControlPointColor); Context->SetColor(ControlPointColor);
@ -990,11 +990,11 @@ void lcPiece::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance)
mModelWorld.SetTranslation(Position); 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)); const lcMatrix33 InverseWorldMatrix = lcMatrix33AffineInverse(lcMatrix33(mModelWorld));
lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform;
@ -1028,11 +1028,11 @@ void lcPiece::Rotate(lcStep Step, bool AddKey, const lcMatrix33& RotationMatrix,
SetPosition(Center + Distance, Step, AddKey); SetPosition(Center + Distance, Step, AddKey);
SetRotation(NewLocalToWorldMatrix, 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; lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform;
const lcMatrix33 PieceWorldMatrix(mModelWorld); const lcMatrix33 PieceWorldMatrix(mModelWorld);
@ -1096,7 +1096,7 @@ quint32 lcPiece::GetAllowedTransforms() const
bool lcPiece::CanAddControlPoint() const bool lcPiece::CanAddControlPoint() const
{ {
if (mControlPoints.GetSize() >= LC_MAX_CONTROL_POINTS) if (mControlPoints.size() >= LC_MAX_CONTROL_POINTS)
return false; return false;
const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo(); const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo();
@ -1106,7 +1106,7 @@ bool lcPiece::CanAddControlPoint() const
bool lcPiece::CanRemoveControlPoint() const bool lcPiece::CanRemoveControlPoint() const
{ {
const quint32 Section = GetFocusSection(); 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) 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() 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; return false;
SetFocused(GetFocusSection(), false); SetFocused(GetFocusSection(), false);
SetFocused(LC_PIECE_SECTION_POSITION, true); SetFocused(LC_PIECE_SECTION_POSITION, true);
mControlPoints.RemoveIndex(ControlPointIndex); mControlPoints.erase(mControlPoints.begin() + ControlPointIndex);
UpdateMesh(); UpdateMesh();
return true; return true;
} }
void lcPiece::VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const void lcPiece::VerifyControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const
{ {
const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo(); const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo();
if (!SynthInfo) if (!SynthInfo)
{ {
ControlPoints.RemoveAll(); ControlPoints.clear();
} }
else else
{ {
if (ControlPoints.GetSize() > LC_MAX_CONTROL_POINTS) if (ControlPoints.size() > LC_MAX_CONTROL_POINTS)
ControlPoints.SetSize(LC_MAX_CONTROL_POINTS); ControlPoints.resize(LC_MAX_CONTROL_POINTS);
SynthInfo->VerifyControlPoints(ControlPoints); SynthInfo->VerifyControlPoints(ControlPoints);
} }

View file

@ -100,11 +100,11 @@ public:
else else
return mModelWorld.GetTranslation(); 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; const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform;
return lcMul(Transform, mModelWorld).GetTranslation(); return lcMul(Transform, mModelWorld).GetTranslation();
@ -154,12 +154,12 @@ public:
mHidden = Hidden; mHidden = Hidden;
} }
const lcArray<lcPieceControlPoint>& GetControlPoints() const const std::vector<lcPieceControlPoint>& GetControlPoints() const
{ {
return mControlPoints; return mControlPoints;
} }
void SetControlPoints(const lcArray<lcPieceControlPoint>& ControlPoints) void SetControlPoints(const std::vector<lcPieceControlPoint>& ControlPoints)
{ {
mControlPoints = ControlPoints; mControlPoints = ControlPoints;
UpdateMesh(); UpdateMesh();
@ -200,7 +200,7 @@ public:
bool InsertControlPoint(const lcVector3& WorldStart, const lcVector3& WorldEnd); bool InsertControlPoint(const lcVector3& WorldStart, const lcVector3& WorldEnd);
bool RemoveFocusedControlPoint(); bool RemoveFocusedControlPoint();
void VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const; void VerifyControlPoints(std::vector<lcPieceControlPoint>& ControlPoints) const;
lcGroup* GetTopGroup(); lcGroup* GetTopGroup();
@ -295,21 +295,19 @@ public:
{ {
if (mPivotPointValid) if (mPivotPointValid)
return lcMul31(mPivotMatrix.GetTranslation(), mModelWorld); 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; const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform;
return lcMul31(Transform.GetTranslation(), mModelWorld); return lcMul31(Transform.GetTranslation(), mModelWorld);
} }
return mModelWorld.GetTranslation();
} }
return mModelWorld.GetTranslation();
} }
lcMatrix33 GetRelativeRotation() const lcMatrix33 GetRelativeRotation() const
@ -323,18 +321,18 @@ public:
else else
return lcMatrix33(mModelWorld); 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; const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform;
return lcMatrix33(lcMul(Transform, mModelWorld)); return lcMatrix33(lcMul(Transform, mModelWorld));
} }
return lcMatrix33Identity();
} }
return lcMatrix33Identity();
} }
void ResetPivotPoint() void ResetPivotPoint()
@ -380,6 +378,6 @@ protected:
bool mHidden = false; bool mHidden = false;
bool mSelected = false; bool mSelected = false;
quint32 mFocusedSection = LC_PIECE_SECTION_INVALID; quint32 mFocusedSection = LC_PIECE_SECTION_INVALID;
lcArray<lcPieceControlPoint> mControlPoints; std::vector<lcPieceControlPoint> mControlPoints;
lcMesh* mMesh = nullptr; lcMesh* mMesh = nullptr;
}; };