leocad/common/piece.h

642 lines
18 KiB
C
Raw Normal View History

#pragma once
2011-09-07 23:06:51 +02:00
class PieceInfo;
#include "object.h"
2012-03-28 03:07:18 +02:00
#include "lc_colors.h"
#include "lc_math.h"
2011-09-07 23:06:51 +02:00
#define LC_PIECE_HIDDEN 0x000001
#define LC_PIECE_PIVOT_POINT_VALID 0x000002
#define LC_PIECE_POSITION_SELECTED 0x000004
#define LC_PIECE_POSITION_FOCUSED 0x000008
#define LC_PIECE_CONTROL_POINT_1_SELECTED 0x000010
#define LC_PIECE_CONTROL_POINT_1_FOCUSED 0x000020
#define LC_PIECE_CONTROL_POINT_2_SELECTED 0x000040
#define LC_PIECE_CONTROL_POINT_2_FOCUSED 0x000080
#define LC_PIECE_CONTROL_POINT_3_SELECTED 0x000100
#define LC_PIECE_CONTROL_POINT_3_FOCUSED 0x000200
#define LC_PIECE_CONTROL_POINT_4_SELECTED 0x000400
#define LC_PIECE_CONTROL_POINT_4_FOCUSED 0x000800
#define LC_PIECE_CONTROL_POINT_5_SELECTED 0x001000
#define LC_PIECE_CONTROL_POINT_5_FOCUSED 0x002000
#define LC_PIECE_CONTROL_POINT_6_SELECTED 0x004000
#define LC_PIECE_CONTROL_POINT_6_FOCUSED 0x008000
#define LC_PIECE_CONTROL_POINT_7_SELECTED 0x010000
#define LC_PIECE_CONTROL_POINT_7_FOCUSED 0x020000
#define LC_PIECE_CONTROL_POINT_8_SELECTED 0x040000
#define LC_PIECE_CONTROL_POINT_8_FOCUSED 0x080000
#define LC_PIECE_CONTROL_POINT_9_SELECTED 0x100000
#define LC_PIECE_CONTROL_POINT_9_FOCUSED 0x200000
#define LC_PIECE_CONTROL_POINT_10_SELECTED 0x400000
#define LC_PIECE_CONTROL_POINT_10_FOCUSED 0x800000
#define LC_MAX_CONTROL_POINTS 10
#define LC_PIECE_CONTROL_POINT_SELECTION_MASK (LC_PIECE_CONTROL_POINT_1_SELECTED | LC_PIECE_CONTROL_POINT_2_SELECTED | LC_PIECE_CONTROL_POINT_3_SELECTED | LC_PIECE_CONTROL_POINT_4_SELECTED | LC_PIECE_CONTROL_POINT_5_SELECTED | LC_PIECE_CONTROL_POINT_6_SELECTED | LC_PIECE_CONTROL_POINT_7_SELECTED | LC_PIECE_CONTROL_POINT_8_SELECTED | LC_PIECE_CONTROL_POINT_9_SELECTED | LC_PIECE_CONTROL_POINT_10_SELECTED)
#define LC_PIECE_CONTROL_POINT_FOCUS_MASK (LC_PIECE_CONTROL_POINT_1_FOCUSED | LC_PIECE_CONTROL_POINT_2_FOCUSED | LC_PIECE_CONTROL_POINT_3_FOCUSED | LC_PIECE_CONTROL_POINT_4_FOCUSED | LC_PIECE_CONTROL_POINT_5_FOCUSED | LC_PIECE_CONTROL_POINT_6_FOCUSED | LC_PIECE_CONTROL_POINT_7_FOCUSED | LC_PIECE_CONTROL_POINT_8_FOCUSED | LC_PIECE_CONTROL_POINT_9_FOCUSED | LC_PIECE_CONTROL_POINT_10_FOCUSED)
#define LC_PIECE_SELECTION_MASK (LC_PIECE_POSITION_SELECTED | LC_PIECE_CONTROL_POINT_SELECTION_MASK)
#define LC_PIECE_FOCUS_MASK (LC_PIECE_POSITION_FOCUSED | LC_PIECE_CONTROL_POINT_FOCUS_MASK)
enum lcPieceSection
{
LC_PIECE_SECTION_POSITION,
LC_PIECE_SECTION_CONTROL_POINT_FIRST,
LC_PIECE_SECTION_CONTROL_POINT_1 = LC_PIECE_SECTION_CONTROL_POINT_FIRST,
LC_PIECE_SECTION_CONTROL_POINT_2,
LC_PIECE_SECTION_CONTROL_POINT_3,
LC_PIECE_SECTION_CONTROL_POINT_4,
LC_PIECE_SECTION_CONTROL_POINT_5,
LC_PIECE_SECTION_CONTROL_POINT_6,
LC_PIECE_SECTION_CONTROL_POINT_7,
LC_PIECE_SECTION_CONTROL_POINT_8,
LC_PIECE_SECTION_CONTROL_POINT_9,
LC_PIECE_SECTION_CONTROL_POINT_10,
LC_PIECE_SECTION_CONTROL_POINT_LAST = LC_PIECE_SECTION_CONTROL_POINT_10
};
#define LC_PIECE_SECTION_INVALID (~0U)
struct lcPieceControlPoint
{
lcMatrix44 Transform;
float Scale;
};
2011-09-07 23:06:51 +02:00
2014-05-01 20:42:11 +02:00
class lcPiece : public lcObject
2011-09-07 23:06:51 +02:00
{
public:
lcPiece(PieceInfo* Info);
2017-03-09 00:49:57 +01:00
lcPiece(const lcPiece& Other);
2014-05-01 20:42:11 +02:00
~lcPiece();
2011-09-07 23:06:51 +02:00
2020-05-04 00:39:39 +02:00
lcPiece(lcPiece&&) = delete;
lcPiece& operator=(const lcPiece&) = delete;
lcPiece& operator=(lcPiece&&) = delete;
bool IsSelected() const override
{
return (mState & LC_PIECE_SELECTION_MASK) != 0;
}
2011-09-07 23:06:51 +02:00
bool IsSelected(quint32 Section) const override
{
2016-02-17 00:11:52 +01:00
Q_UNUSED(Section);
return (mState & LC_PIECE_SELECTION_MASK) != 0;
}
2011-09-07 23:06:51 +02:00
void SetSelected(bool Selected) override
{
if (Selected)
mState |= LC_PIECE_SELECTION_MASK;
else
mState &= ~(LC_PIECE_SELECTION_MASK | LC_PIECE_FOCUS_MASK);
}
2011-09-07 23:06:51 +02:00
void SetSelected(quint32 Section, bool Selected) override
{
switch (Section)
{
case LC_PIECE_SECTION_POSITION:
if (Selected)
mState |= LC_PIECE_POSITION_SELECTED;
else
mState &= ~(LC_PIECE_POSITION_SELECTED | LC_PIECE_POSITION_FOCUSED);
break;
case LC_PIECE_SECTION_CONTROL_POINT_1:
if (Selected)
mState |= LC_PIECE_CONTROL_POINT_1_SELECTED;
else
mState &= ~(LC_PIECE_CONTROL_POINT_1_SELECTED | LC_PIECE_CONTROL_POINT_1_FOCUSED);
break;
case LC_PIECE_SECTION_CONTROL_POINT_2:
if (Selected)
mState |= LC_PIECE_CONTROL_POINT_2_SELECTED;
else
mState &= ~(LC_PIECE_CONTROL_POINT_2_SELECTED | LC_PIECE_CONTROL_POINT_2_FOCUSED);
break;
case LC_PIECE_SECTION_CONTROL_POINT_3:
if (Selected)
mState |= LC_PIECE_CONTROL_POINT_3_SELECTED;
else
mState &= ~(LC_PIECE_CONTROL_POINT_3_SELECTED | LC_PIECE_CONTROL_POINT_3_FOCUSED);
break;
case LC_PIECE_SECTION_CONTROL_POINT_4:
if (Selected)
mState |= LC_PIECE_CONTROL_POINT_4_SELECTED;
else
mState &= ~(LC_PIECE_CONTROL_POINT_4_SELECTED | LC_PIECE_CONTROL_POINT_4_FOCUSED);
break;
case LC_PIECE_SECTION_CONTROL_POINT_5:
if (Selected)
mState |= LC_PIECE_CONTROL_POINT_5_SELECTED;
else
mState &= ~(LC_PIECE_CONTROL_POINT_5_SELECTED | LC_PIECE_CONTROL_POINT_5_FOCUSED);
break;
case LC_PIECE_SECTION_CONTROL_POINT_6:
if (Selected)
mState |= LC_PIECE_CONTROL_POINT_6_SELECTED;
else
mState &= ~(LC_PIECE_CONTROL_POINT_6_SELECTED | LC_PIECE_CONTROL_POINT_6_FOCUSED);
break;
case LC_PIECE_SECTION_CONTROL_POINT_7:
if (Selected)
mState |= LC_PIECE_CONTROL_POINT_7_SELECTED;
else
mState &= ~(LC_PIECE_CONTROL_POINT_7_SELECTED | LC_PIECE_CONTROL_POINT_7_FOCUSED);
break;
case LC_PIECE_SECTION_CONTROL_POINT_8:
if (Selected)
mState |= LC_PIECE_CONTROL_POINT_8_SELECTED;
else
mState &= ~(LC_PIECE_CONTROL_POINT_8_SELECTED | LC_PIECE_CONTROL_POINT_8_FOCUSED);
break;
case LC_PIECE_SECTION_CONTROL_POINT_9:
if (Selected)
mState |= LC_PIECE_CONTROL_POINT_9_SELECTED;
else
mState &= ~(LC_PIECE_CONTROL_POINT_9_SELECTED | LC_PIECE_CONTROL_POINT_9_FOCUSED);
break;
case LC_PIECE_SECTION_CONTROL_POINT_10:
if (Selected)
mState |= LC_PIECE_CONTROL_POINT_10_SELECTED;
else
mState &= ~(LC_PIECE_CONTROL_POINT_10_SELECTED | LC_PIECE_CONTROL_POINT_10_FOCUSED);
break;
}
}
bool IsFocused() const override
{
return (mState & LC_PIECE_FOCUS_MASK) != 0;
}
2011-09-07 23:06:51 +02:00
bool IsFocused(quint32 Section) const override
{
switch (Section)
{
case LC_PIECE_SECTION_POSITION:
return (mState & LC_PIECE_POSITION_FOCUSED) != 0;
case LC_PIECE_SECTION_CONTROL_POINT_1:
return (mState & LC_PIECE_CONTROL_POINT_1_FOCUSED) != 0;
case LC_PIECE_SECTION_CONTROL_POINT_2:
return (mState & LC_PIECE_CONTROL_POINT_2_FOCUSED) != 0;
case LC_PIECE_SECTION_CONTROL_POINT_3:
return (mState & LC_PIECE_CONTROL_POINT_3_FOCUSED) != 0;
case LC_PIECE_SECTION_CONTROL_POINT_4:
return (mState & LC_PIECE_CONTROL_POINT_4_FOCUSED) != 0;
case LC_PIECE_SECTION_CONTROL_POINT_5:
return (mState & LC_PIECE_CONTROL_POINT_5_FOCUSED) != 0;
case LC_PIECE_SECTION_CONTROL_POINT_6:
return (mState & LC_PIECE_CONTROL_POINT_6_FOCUSED) != 0;
case LC_PIECE_SECTION_CONTROL_POINT_7:
return (mState & LC_PIECE_CONTROL_POINT_7_FOCUSED) != 0;
case LC_PIECE_SECTION_CONTROL_POINT_8:
return (mState & LC_PIECE_CONTROL_POINT_8_FOCUSED) != 0;
case LC_PIECE_SECTION_CONTROL_POINT_9:
return (mState & LC_PIECE_CONTROL_POINT_9_FOCUSED) != 0;
case LC_PIECE_SECTION_CONTROL_POINT_10:
return (mState & LC_PIECE_CONTROL_POINT_10_FOCUSED) != 0;
}
return false;
}
void SetFocused(quint32 Section, bool Focused) override
{
switch (Section)
{
case LC_PIECE_SECTION_POSITION:
2015-12-16 01:28:40 +01:00
if (Focused)
mState |= (LC_PIECE_POSITION_SELECTED | LC_PIECE_POSITION_FOCUSED);
else
mState &= ~LC_PIECE_POSITION_FOCUSED;
break;
case LC_PIECE_SECTION_CONTROL_POINT_1:
2015-12-16 01:28:40 +01:00
if (Focused)
mState |= (LC_PIECE_CONTROL_POINT_1_SELECTED | LC_PIECE_CONTROL_POINT_1_FOCUSED);
else
mState &= ~LC_PIECE_CONTROL_POINT_1_FOCUSED;
break;
case LC_PIECE_SECTION_CONTROL_POINT_2:
2015-12-16 01:28:40 +01:00
if (Focused)
mState |= (LC_PIECE_CONTROL_POINT_2_SELECTED | LC_PIECE_CONTROL_POINT_2_FOCUSED);
else
mState &= ~LC_PIECE_CONTROL_POINT_2_FOCUSED;
break;
case LC_PIECE_SECTION_CONTROL_POINT_3:
2015-12-16 01:28:40 +01:00
if (Focused)
mState |= (LC_PIECE_CONTROL_POINT_3_SELECTED | LC_PIECE_CONTROL_POINT_3_FOCUSED);
else
mState &= ~LC_PIECE_CONTROL_POINT_3_FOCUSED;
break;
case LC_PIECE_SECTION_CONTROL_POINT_4:
2015-12-16 01:28:40 +01:00
if (Focused)
mState |= (LC_PIECE_CONTROL_POINT_4_SELECTED | LC_PIECE_CONTROL_POINT_4_FOCUSED);
else
mState &= ~LC_PIECE_CONTROL_POINT_4_FOCUSED;
break;
case LC_PIECE_SECTION_CONTROL_POINT_5:
2015-12-16 01:28:40 +01:00
if (Focused)
mState |= (LC_PIECE_CONTROL_POINT_5_SELECTED | LC_PIECE_CONTROL_POINT_5_FOCUSED);
else
mState &= ~LC_PIECE_CONTROL_POINT_5_FOCUSED;
break;
case LC_PIECE_SECTION_CONTROL_POINT_6:
2015-12-16 01:28:40 +01:00
if (Focused)
mState |= (LC_PIECE_CONTROL_POINT_6_SELECTED | LC_PIECE_CONTROL_POINT_6_FOCUSED);
else
mState &= ~LC_PIECE_CONTROL_POINT_6_FOCUSED;
break;
case LC_PIECE_SECTION_CONTROL_POINT_7:
2015-12-16 01:28:40 +01:00
if (Focused)
mState |= (LC_PIECE_CONTROL_POINT_7_SELECTED | LC_PIECE_CONTROL_POINT_7_FOCUSED);
else
mState &= ~LC_PIECE_CONTROL_POINT_7_FOCUSED;
break;
case LC_PIECE_SECTION_CONTROL_POINT_8:
2015-12-16 01:28:40 +01:00
if (Focused)
mState |= (LC_PIECE_CONTROL_POINT_8_SELECTED | LC_PIECE_CONTROL_POINT_8_FOCUSED);
else
mState &= ~LC_PIECE_CONTROL_POINT_8_FOCUSED;
break;
case LC_PIECE_SECTION_CONTROL_POINT_9:
if (Focused)
mState |= (LC_PIECE_CONTROL_POINT_9_SELECTED | LC_PIECE_CONTROL_POINT_9_FOCUSED);
else
mState &= ~LC_PIECE_CONTROL_POINT_9_FOCUSED;
break;
case LC_PIECE_SECTION_CONTROL_POINT_10:
if (Focused)
mState |= (LC_PIECE_CONTROL_POINT_10_SELECTED | LC_PIECE_CONTROL_POINT_10_FOCUSED);
else
mState &= ~LC_PIECE_CONTROL_POINT_10_FOCUSED;
break;
}
}
quint32 GetFocusSection() const override
{
if (mState & LC_PIECE_POSITION_FOCUSED)
return LC_PIECE_SECTION_POSITION;
if (mState & LC_PIECE_CONTROL_POINT_1_FOCUSED)
return LC_PIECE_SECTION_CONTROL_POINT_1;
if (mState & LC_PIECE_CONTROL_POINT_2_FOCUSED)
return LC_PIECE_SECTION_CONTROL_POINT_2;
if (mState & LC_PIECE_CONTROL_POINT_3_FOCUSED)
return LC_PIECE_SECTION_CONTROL_POINT_3;
if (mState & LC_PIECE_CONTROL_POINT_4_FOCUSED)
return LC_PIECE_SECTION_CONTROL_POINT_4;
if (mState & LC_PIECE_CONTROL_POINT_5_FOCUSED)
return LC_PIECE_SECTION_CONTROL_POINT_5;
if (mState & LC_PIECE_CONTROL_POINT_6_FOCUSED)
return LC_PIECE_SECTION_CONTROL_POINT_6;
if (mState & LC_PIECE_CONTROL_POINT_7_FOCUSED)
return LC_PIECE_SECTION_CONTROL_POINT_7;
if (mState & LC_PIECE_CONTROL_POINT_8_FOCUSED)
return LC_PIECE_SECTION_CONTROL_POINT_8;
if (mState & LC_PIECE_CONTROL_POINT_9_FOCUSED)
return LC_PIECE_SECTION_CONTROL_POINT_9;
if (mState & LC_PIECE_CONTROL_POINT_10_FOCUSED)
return LC_PIECE_SECTION_CONTROL_POINT_10;
return LC_PIECE_SECTION_INVALID;
}
quint32 GetAllowedTransforms() const override;
lcVector3 GetSectionPosition(quint32 Section) const override
{
switch (Section)
{
case LC_PIECE_SECTION_POSITION:
2015-12-15 02:57:22 +01:00
if (mState & LC_PIECE_PIVOT_POINT_VALID)
return lcMul(mPivotMatrix, mModelWorld).GetTranslation();
else
return mModelWorld.GetTranslation();
case LC_PIECE_SECTION_CONTROL_POINT_1:
return lcMul(mControlPoints[0].Transform, mModelWorld).GetTranslation();
case LC_PIECE_SECTION_CONTROL_POINT_2:
return lcMul(mControlPoints[1].Transform, mModelWorld).GetTranslation();
case LC_PIECE_SECTION_CONTROL_POINT_3:
return lcMul(mControlPoints[2].Transform, mModelWorld).GetTranslation();
case LC_PIECE_SECTION_CONTROL_POINT_4:
return lcMul(mControlPoints[3].Transform, mModelWorld).GetTranslation();
case LC_PIECE_SECTION_CONTROL_POINT_5:
return lcMul(mControlPoints[4].Transform, mModelWorld).GetTranslation();
case LC_PIECE_SECTION_CONTROL_POINT_6:
return lcMul(mControlPoints[5].Transform, mModelWorld).GetTranslation();
case LC_PIECE_SECTION_CONTROL_POINT_7:
return lcMul(mControlPoints[6].Transform, mModelWorld).GetTranslation();
case LC_PIECE_SECTION_CONTROL_POINT_8:
return lcMul(mControlPoints[7].Transform, mModelWorld).GetTranslation();
case LC_PIECE_SECTION_CONTROL_POINT_9:
return lcMul(mControlPoints[8].Transform, mModelWorld).GetTranslation();
case LC_PIECE_SECTION_CONTROL_POINT_10:
return lcMul(mControlPoints[9].Transform, mModelWorld).GetTranslation();
}
return lcVector3(0.0f, 0.0f, 0.0f);
}
2014-09-05 02:24:28 +02:00
void SaveLDraw(QTextStream& Stream) const;
2014-09-08 21:42:20 +02:00
bool ParseLDrawLine(QTextStream& Stream);
2015-03-21 21:12:04 +01:00
void SetFileLine(int Line)
{
mFileLine = Line;
}
int GetFileLine() const
{
return mFileLine;
}
void RayTest(lcObjectRayTest& ObjectRayTest) const override;
void BoxTest(lcObjectBoxTest& ObjectBoxTest) const override;
void DrawInterface(lcContext* Context, const lcScene& Scene) const override;
void RemoveKeyFrames() override;
2020-12-05 20:02:10 +01:00
void AddMainModelRenderMeshes(lcScene* Scene, bool Highlight, bool Fade) const;
void AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
void SubmodelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const;
2016-02-19 18:53:54 +01:00
2014-08-31 02:53:12 +02:00
void InsertTime(lcStep Start, lcStep Time);
void RemoveTime(lcStep Start, lcStep Time);
2011-09-07 23:06:51 +02:00
bool IsHidden() const
{
return (mState & LC_PIECE_HIDDEN) != 0;
}
void SetHidden(bool Hidden)
{
if (Hidden)
mState |= LC_PIECE_HIDDEN;
else
mState &= ~LC_PIECE_HIDDEN;
}
2011-09-07 23:06:51 +02:00
const lcArray<lcPieceControlPoint>& GetControlPoints() const
{
return mControlPoints;
}
2016-05-02 07:33:58 +02:00
void SetControlPoints(const lcArray<lcPieceControlPoint>& ControlPoints)
{
Synthesis of Technic Universal Joints (#456) * Split synth info initialzation by type. We are going to remove the type enumeration and use a class hierarchy instead. This preparation will then be helpful. * Make Add...Parts() overrides of a virtual AddPart() function. Since we have a class hierarchy for the different synthesized pieces, we can now turn a case distinction into a virtual function call. * Move initialization based on type to derived class constructors. Move initialization of end transformations of flexible parts into class lcSynthInfoCurved. * Make GetDefaultControlPoints() virtual with overrides. * Remove obsolete enum lcSynthType. We have replaced its purpose by derived classes by now. * Initialize shock absorbers' spring part ID early. This removes the awkward early return that is needed in the if-else cascade. * Split lcSynthInfo into derived classes for curved and straight pieces. * Only curved parts have varying sections, start, middle, and end properties. Move the properties from the base class to the derived class that needs them. * Use derived classes to mark synthesized objects of different kinds. We will extend the derived classes in the upcoming commits. * PieceInfo is only needed to synthesize some hoses and shock absorbers. * Initialize edge part IDs of flexible hoses early. This removes another case distinction in AddParts(). * Verify the number of control points loaded from a model file. * Synthesize Technic universal joints. The direction of one end can be changed so that it points to the control point. * Technic universal joints need only the position of the control point. * Synthesize legacy universal joints.
2020-03-30 21:17:08 +02:00
mControlPoints = ControlPoints;
UpdateMesh();
2016-05-02 07:33:58 +02:00
}
void SetControlPointScale(int ControlPointIndex, float Scale)
{
mControlPoints[ControlPointIndex].Scale = Scale;
UpdateMesh();
}
2017-07-23 05:54:33 +02:00
const QString& GetID() const
{
return mID;
}
2017-07-24 04:35:18 +02:00
void UpdateID();
2020-12-14 01:27:21 +01:00
QString GetName() const override;
2019-03-13 03:51:04 +01:00
bool IsVisible(lcStep Step) const;
bool IsVisibleInSubModel() const;
2019-05-28 01:39:51 +02:00
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector<lcModelPartsEntry>& ModelParts) const;
void Initialize(const lcMatrix44& WorldMatrix, lcStep Step);
2016-02-19 18:53:54 +01:00
const lcBoundingBox& GetBoundingBox() const;
void CompareBoundingBox(lcVector3& Min, lcVector3& Max) const;
2017-07-23 05:54:33 +02:00
void SetPieceInfo(PieceInfo* Info, const QString& ID, bool Wait);
2013-08-09 06:57:18 +02:00
bool FileLoad(lcFile& file);
2011-09-07 23:06:51 +02:00
2014-07-06 08:04:09 +02:00
void UpdatePosition(lcStep Step);
void MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance);
2015-12-16 01:28:40 +01:00
void Rotate(lcStep Step, bool AddKey, const lcMatrix33& RotationMatrix, const lcVector3& Center, const lcMatrix33& RotationFrame);
void MovePivotPoint(const lcVector3& Distance);
void RotatePivotPoint(const lcMatrix33& RotationMatrix);
2011-09-07 23:06:51 +02:00
bool CanAddControlPoint() const;
bool CanRemoveControlPoint() const;
bool InsertControlPoint(const lcVector3& WorldStart, const lcVector3& WorldEnd);
bool RemoveFocusedControlPoint();
Synthesis of Technic Universal Joints (#456) * Split synth info initialzation by type. We are going to remove the type enumeration and use a class hierarchy instead. This preparation will then be helpful. * Make Add...Parts() overrides of a virtual AddPart() function. Since we have a class hierarchy for the different synthesized pieces, we can now turn a case distinction into a virtual function call. * Move initialization based on type to derived class constructors. Move initialization of end transformations of flexible parts into class lcSynthInfoCurved. * Make GetDefaultControlPoints() virtual with overrides. * Remove obsolete enum lcSynthType. We have replaced its purpose by derived classes by now. * Initialize shock absorbers' spring part ID early. This removes the awkward early return that is needed in the if-else cascade. * Split lcSynthInfo into derived classes for curved and straight pieces. * Only curved parts have varying sections, start, middle, and end properties. Move the properties from the base class to the derived class that needs them. * Use derived classes to mark synthesized objects of different kinds. We will extend the derived classes in the upcoming commits. * PieceInfo is only needed to synthesize some hoses and shock absorbers. * Initialize edge part IDs of flexible hoses early. This removes another case distinction in AddParts(). * Verify the number of control points loaded from a model file. * Synthesize Technic universal joints. The direction of one end can be changed so that it points to the control point. * Technic universal joints need only the position of the control point. * Synthesize legacy universal joints.
2020-03-30 21:17:08 +02:00
void VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const;
2014-05-25 20:23:09 +02:00
lcGroup* GetTopGroup();
void SetGroup(lcGroup* Group)
{
mGroup = Group;
}
lcGroup* GetGroup()
{
return mGroup;
}
2014-07-06 08:04:09 +02:00
lcStep GetStepShow() const
{
return mStepShow;
}
lcStep GetStepHide() const
{
return mStepHide;
}
void SetStepHide(lcStep Step)
{
if (Step < 2)
Step = 2;
2014-07-06 08:04:09 +02:00
mStepHide = Step;
if (mStepHide <= mStepShow)
SetStepShow(mStepHide - 1);
2014-07-06 08:04:09 +02:00
}
void SetStepShow(lcStep Step)
{
if (Step == LC_STEP_MAX)
Step = LC_STEP_MAX - 1;
if (mStepShow != Step)
{
mFileLine = -1;
mStepShow = Step;
}
if (mStepHide <= mStepShow)
mStepHide = mStepShow + 1;
2014-07-06 08:04:09 +02:00
}
2011-09-07 23:06:51 +02:00
2017-12-02 21:22:04 +01:00
void SetColorCode(quint32 ColorCode)
2011-09-07 23:06:51 +02:00
{
2012-03-28 03:07:18 +02:00
mColorCode = ColorCode;
mColorIndex = lcGetColorIndex(ColorCode);
}
void SetColorIndex(int ColorIndex)
{
mColorIndex = ColorIndex;
mColorCode = lcGetColorCode(ColorIndex);
}
2011-09-07 23:06:51 +02:00
2014-08-31 02:53:12 +02:00
void SetPosition(const lcVector3& Position, lcStep Step, bool AddKey)
{
ChangeKey(mPositionKeys, Position, Step, AddKey);
}
void SetRotation(const lcMatrix33& Rotation, lcStep Step, bool AddKey)
2014-08-31 02:53:12 +02:00
{
ChangeKey(mRotationKeys, Rotation, Step, AddKey);
}
2015-12-14 19:01:17 +01:00
lcVector3 GetRotationCenter() const
{
2020-03-23 04:18:52 +01:00
const quint32 Section = GetFocusSection();
2016-04-03 01:11:39 +02:00
if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID)
{
if (mState & LC_PIECE_PIVOT_POINT_VALID)
return lcMul31(mPivotMatrix.GetTranslation(), mModelWorld);
else
return mModelWorld.GetTranslation();
}
2015-12-14 19:01:17 +01:00
else
2016-04-03 01:11:39 +02:00
{
2020-03-23 04:18:52 +01:00
const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1;
2016-04-03 01:11:39 +02:00
if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize())
{
const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform;
2016-04-03 01:11:39 +02:00
return lcMul31(Transform.GetTranslation(), mModelWorld);
}
2015-12-14 19:01:17 +01:00
return mModelWorld.GetTranslation();
2016-04-03 01:11:39 +02:00
}
2015-12-14 19:01:17 +01:00
}
2015-12-15 20:47:52 +01:00
lcMatrix33 GetRelativeRotation() const
2015-12-14 19:01:17 +01:00
{
2020-03-23 04:18:52 +01:00
const quint32 Section = GetFocusSection();
if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID)
{
if (mState & LC_PIECE_PIVOT_POINT_VALID)
return lcMatrix33(lcMul(mModelWorld, mPivotMatrix));
else
return lcMatrix33(mModelWorld);
}
2015-12-14 19:01:17 +01:00
else
{
2020-03-23 04:18:52 +01:00
const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1;
if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize())
{
const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform;
return lcMatrix33(lcMul(Transform, mModelWorld));
}
return lcMatrix33Identity();
}
2015-12-14 19:01:17 +01:00
}
void ResetPivotPoint()
{
mState &= ~LC_PIECE_PIVOT_POINT_VALID;
mPivotMatrix = lcMatrix44Identity();
2015-12-14 19:01:17 +01:00
}
public:
PieceInfo* mPieceInfo;
2012-03-28 03:07:18 +02:00
int mColorIndex;
2017-12-02 21:22:04 +01:00
quint32 mColorCode;
2012-03-28 03:07:18 +02:00
lcMatrix44 mModelWorld;
2015-12-14 19:01:17 +01:00
lcMatrix44 mPivotMatrix;
2011-09-07 23:06:51 +02:00
protected:
2016-02-19 18:53:54 +01:00
void UpdateMesh();
2015-12-14 19:01:17 +01:00
bool IsPivotPointVisible() const
{
return (mState & LC_PIECE_PIVOT_POINT_VALID) && IsFocused();
}
bool AreControlPointsVisible() const
{
return IsSelected();
}
2014-08-31 02:53:12 +02:00
lcArray<lcObjectKey<lcVector3>> mPositionKeys;
lcArray<lcObjectKey<lcMatrix33>> mRotationKeys;
2014-08-31 02:53:12 +02:00
2015-03-21 21:12:04 +01:00
int mFileLine;
2017-07-23 05:54:33 +02:00
QString mID;
2015-03-21 21:12:04 +01:00
2014-08-07 17:22:33 +02:00
lcGroup* mGroup;
2011-09-07 23:06:51 +02:00
2014-07-06 08:04:09 +02:00
lcStep mStepShow;
lcStep mStepHide;
2011-09-07 23:06:51 +02:00
2017-12-02 21:22:04 +01:00
quint32 mState;
lcArray<lcPieceControlPoint> mControlPoints;
2016-02-19 18:53:54 +01:00
lcMesh* mMesh;
2011-09-07 23:06:51 +02:00
};