Static analysis fixes.

This commit is contained in:
Leonardo Zide 2021-11-14 18:34:24 -08:00
parent 5d558b38bb
commit 7d884e6b5f
34 changed files with 365 additions and 333 deletions

View file

@ -138,7 +138,7 @@ void lcCamera::CreateName(const lcArray<lcCamera*>& Cameras)
void lcCamera::SaveLDraw(QTextStream& Stream) const void lcCamera::SaveLDraw(QTextStream& Stream) const
{ {
QLatin1String LineEnding("\r\n"); const QLatin1String LineEnding("\r\n");
Stream << QLatin1String("0 !LEOCAD CAMERA FOV ") << m_fovy << QLatin1String(" ZNEAR ") << m_zNear << QLatin1String(" ZFAR ") << m_zFar << LineEnding; Stream << QLatin1String("0 !LEOCAD CAMERA FOV ") << m_fovy << QLatin1String(" ZNEAR ") << m_zNear << QLatin1String(" ZFAR ") << m_zFar << LineEnding;
@ -400,7 +400,7 @@ void lcCamera::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance)
mUpVectorKeys.ChangeKey(mUpVector, Step, AddKey); mUpVectorKeys.ChangeKey(mUpVector, Step, AddKey);
} }
lcVector3 FrontVector(mTargetPosition - mPosition); const lcVector3 FrontVector(mTargetPosition - mPosition);
lcVector3 SideVector = lcCross(FrontVector, mUpVector); lcVector3 SideVector = lcCross(FrontVector, mUpVector);
if (fabsf(lcDot(mUpVector, SideVector)) > 0.99f) if (fabsf(lcDot(mUpVector, SideVector)) > 0.99f)
@ -415,7 +415,7 @@ void lcCamera::MoveRelative(const lcVector3& Distance, lcStep Step, bool AddKey)
if (IsSimple()) if (IsSimple())
AddKey = false; AddKey = false;
lcVector3 Relative = lcMul30(Distance, lcMatrix44Transpose(mWorldView)) * 5.0f; const lcVector3 Relative = lcMul30(Distance, lcMatrix44Transpose(mWorldView)) * 5.0f;
mPosition += Relative; mPosition += Relative;
mPositionKeys.ChangeKey(mPosition, Step, AddKey); mPositionKeys.ChangeKey(mPosition, Step, AddKey);
@ -435,8 +435,8 @@ void lcCamera::UpdatePosition(lcStep Step)
mUpVector = mUpVectorKeys.CalculateKey(Step); mUpVector = mUpVectorKeys.CalculateKey(Step);
} }
lcVector3 FrontVector(mPosition - mTargetPosition); const lcVector3 FrontVector(mPosition - mTargetPosition);
lcVector3 SideVector = lcCross(FrontVector, mUpVector); const lcVector3 SideVector = lcCross(FrontVector, mUpVector);
mUpVector = lcNormalize(lcCross(SideVector, FrontVector)); mUpVector = lcNormalize(lcCross(SideVector, FrontVector));
mWorldView = lcMatrix44LookAt(mPosition, mTargetPosition, mUpVector); mWorldView = lcMatrix44LookAt(mPosition, mTargetPosition, mUpVector);
@ -472,7 +472,7 @@ void lcCamera::DrawInterface(lcContext* Context, const lcScene& Scene) const
lcMatrix44 ViewWorldMatrix = lcMatrix44AffineInverse(mWorldView); lcMatrix44 ViewWorldMatrix = lcMatrix44AffineInverse(mWorldView);
ViewWorldMatrix.SetTranslation(lcVector3(0, 0, 0)); ViewWorldMatrix.SetTranslation(lcVector3(0, 0, 0));
lcMatrix44 CameraViewMatrix = lcMul(ViewWorldMatrix, lcMatrix44Translation(mPosition)); const lcMatrix44 CameraViewMatrix = lcMul(ViewWorldMatrix, lcMatrix44Translation(mPosition));
Context->SetWorldMatrix(CameraViewMatrix); Context->SetWorldMatrix(CameraViewMatrix);
float Verts[(12 + 8 + 8 + 3 + 4) * 3]; float Verts[(12 + 8 + 8 + 3 + 4) * 3];
@ -537,7 +537,7 @@ void lcCamera::DrawInterface(lcContext* Context, const lcScene& Scene) const
Context->SetVertexFormatPosition(3); Context->SetVertexFormatPosition(3);
Context->SetIndexBufferPointer(Indices); Context->SetIndexBufferPointer(Indices);
float LineWidth = lcGetPreferences().mLineWidth; const float LineWidth = lcGetPreferences().mLineWidth;
if (!IsSelected()) if (!IsSelected())
{ {
@ -655,8 +655,8 @@ void lcCamera::RayTest(lcObjectRayTest& ObjectRayTest) const
ObjectRayTest.Distance = Distance; ObjectRayTest.Distance = Distance;
} }
lcMatrix44 ViewWorld = lcMatrix44AffineInverse(mWorldView); const lcMatrix44 ViewWorld = lcMatrix44AffineInverse(mWorldView);
lcVector3 UpVectorPosition = lcMul31(lcVector3(0, 25, 0), ViewWorld); const lcVector3 UpVectorPosition = lcMul31(lcVector3(0, 25, 0), ViewWorld);
WorldView = mWorldView; WorldView = mWorldView;
WorldView.SetTranslation(lcMul30(-UpVectorPosition, WorldView)); WorldView.SetTranslation(lcMul30(-UpVectorPosition, WorldView));
@ -681,7 +681,7 @@ void lcCamera::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
for (int PlaneIdx = 0; PlaneIdx < 6; PlaneIdx++) for (int PlaneIdx = 0; PlaneIdx < 6; PlaneIdx++)
{ {
lcVector3 Normal = lcMul30(ObjectBoxTest.Planes[PlaneIdx], mWorldView); const lcVector3 Normal = lcMul30(ObjectBoxTest.Planes[PlaneIdx], mWorldView);
LocalPlanes[PlaneIdx] = lcVector4(Normal, ObjectBoxTest.Planes[PlaneIdx][3] - lcDot3(mWorldView[3], Normal)); LocalPlanes[PlaneIdx] = lcVector4(Normal, ObjectBoxTest.Planes[PlaneIdx][3] - lcDot3(mWorldView[3], Normal));
} }
@ -699,7 +699,7 @@ void lcCamera::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
for (int PlaneIdx = 0; PlaneIdx < 6; PlaneIdx++) for (int PlaneIdx = 0; PlaneIdx < 6; PlaneIdx++)
{ {
lcVector3 Normal = lcMul30(ObjectBoxTest.Planes[PlaneIdx], WorldView); const lcVector3 Normal = lcMul30(ObjectBoxTest.Planes[PlaneIdx], WorldView);
LocalPlanes[PlaneIdx] = lcVector4(Normal, ObjectBoxTest.Planes[PlaneIdx][3] - lcDot3(WorldView[3], Normal)); LocalPlanes[PlaneIdx] = lcVector4(Normal, ObjectBoxTest.Planes[PlaneIdx][3] - lcDot3(WorldView[3], Normal));
} }
@ -709,15 +709,15 @@ void lcCamera::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
return; return;
} }
lcMatrix44 ViewWorld = lcMatrix44AffineInverse(mWorldView); const lcMatrix44 ViewWorld = lcMatrix44AffineInverse(mWorldView);
lcVector3 UpVectorPosition = lcMul31(lcVector3(0, 25, 0), ViewWorld); const lcVector3 UpVectorPosition = lcMul31(lcVector3(0, 25, 0), ViewWorld);
WorldView = mWorldView; WorldView = mWorldView;
WorldView.SetTranslation(lcMul30(-UpVectorPosition, WorldView)); WorldView.SetTranslation(lcMul30(-UpVectorPosition, WorldView));
for (int PlaneIdx = 0; PlaneIdx < 6; PlaneIdx++) for (int PlaneIdx = 0; PlaneIdx < 6; PlaneIdx++)
{ {
lcVector3 Normal = lcMul30(ObjectBoxTest.Planes[PlaneIdx], WorldView); const lcVector3 Normal = lcMul30(ObjectBoxTest.Planes[PlaneIdx], WorldView);
LocalPlanes[PlaneIdx] = lcVector4(Normal, ObjectBoxTest.Planes[PlaneIdx][3] - lcDot3(WorldView[3], Normal)); LocalPlanes[PlaneIdx] = lcVector4(Normal, ObjectBoxTest.Planes[PlaneIdx][3] - lcDot3(WorldView[3], Normal));
} }
@ -758,23 +758,23 @@ void lcCamera::ZoomExtents(float AspectRatio, const lcVector3& Center, const std
MaxY = lcMax(MaxY, Point.y); MaxY = lcMax(MaxY, Point.y);
} }
lcVector3 ViewCenter = lcMul30(Center, mWorldView); const lcVector3 ViewCenter = lcMul30(Center, mWorldView);
float Width = qMax(fabsf(MaxX - ViewCenter.x), fabsf(ViewCenter.x - MinX)) * 2; float Width = qMax(fabsf(MaxX - ViewCenter.x), fabsf(ViewCenter.x - MinX)) * 2;
float Height = qMax(fabsf(MaxY - ViewCenter.y), fabsf(ViewCenter.y - MinY)) * 2; float Height = qMax(fabsf(MaxY - ViewCenter.y), fabsf(ViewCenter.y - MinY)) * 2;
if (Width > Height * AspectRatio) if (Width > Height * AspectRatio)
Height = Width / AspectRatio; Height = Width / AspectRatio;
float f = Height / (m_fovy * (LC_PI / 180.0f)); const float f = Height / (m_fovy * (LC_PI / 180.0f));
lcVector3 FrontVector(mTargetPosition - mPosition); const lcVector3 FrontVector(mTargetPosition - mPosition);
mPosition = Center - lcNormalize(FrontVector) * f; mPosition = Center - lcNormalize(FrontVector) * f;
mTargetPosition = Center; mTargetPosition = Center;
} }
else else
{ {
lcVector3 Position(mPosition + Center - mTargetPosition); const lcVector3 Position(mPosition + Center - mTargetPosition);
lcMatrix44 ProjectionMatrix = lcMatrix44Perspective(m_fovy, AspectRatio, m_zNear, m_zFar); const lcMatrix44 ProjectionMatrix = lcMatrix44Perspective(m_fovy, AspectRatio, m_zNear, m_zFar);
std::tie(mPosition, std::ignore) = lcZoomExtents(Position, mWorldView, ProjectionMatrix, Points.data(), Points.size()); std::tie(mPosition, std::ignore) = lcZoomExtents(Position, mWorldView, ProjectionMatrix, Points.data(), Points.size());
mTargetPosition = Center; mTargetPosition = Center;
@ -797,7 +797,7 @@ void lcCamera::ZoomRegion(float AspectRatio, const lcVector3& Position, const lc
for (int PointIdx = 0; PointIdx < 2; PointIdx++) for (int PointIdx = 0; PointIdx < 2; PointIdx++)
{ {
lcVector3 Point = lcMul30(Corners[PointIdx], mWorldView); const lcVector3 Point = lcMul30(Corners[PointIdx], mWorldView);
MinX = lcMin(MinX, Point.x); MinX = lcMin(MinX, Point.x);
MinY = lcMin(MinY, Point.y); MinY = lcMin(MinY, Point.y);
@ -811,16 +811,16 @@ void lcCamera::ZoomRegion(float AspectRatio, const lcVector3& Position, const lc
if (Width > Height * AspectRatio) if (Width > Height * AspectRatio)
Height = Width / AspectRatio; Height = Width / AspectRatio;
float f = Height / (m_fovy * (LC_PI / 180.0f)); const float f = Height / (m_fovy * (LC_PI / 180.0f));
lcVector3 FrontVector(mTargetPosition - mPosition); const lcVector3 FrontVector(mTargetPosition - mPosition);
mPosition = TargetPosition - lcNormalize(FrontVector) * f; mPosition = TargetPosition - lcNormalize(FrontVector) * f;
mTargetPosition = TargetPosition; mTargetPosition = TargetPosition;
} }
else else
{ {
lcMatrix44 WorldView = lcMatrix44LookAt(Position, TargetPosition, mUpVector); const lcMatrix44 WorldView = lcMatrix44LookAt(Position, TargetPosition, mUpVector);
lcMatrix44 ProjectionMatrix = lcMatrix44Perspective(m_fovy, AspectRatio, m_zNear, m_zFar); const lcMatrix44 ProjectionMatrix = lcMatrix44Perspective(m_fovy, AspectRatio, m_zNear, m_zFar);
std::tie(mPosition, std::ignore) = lcZoomExtents(Position, WorldView, ProjectionMatrix, Corners, 2); std::tie(mPosition, std::ignore) = lcZoomExtents(Position, WorldView, ProjectionMatrix, Corners, 2);
mTargetPosition = TargetPosition; mTargetPosition = TargetPosition;
@ -892,8 +892,8 @@ void lcCamera::Orbit(float DistanceX, float DistanceY, const lcVector3& CenterPo
Z[1] = -Z[1]; Z[1] = -Z[1];
} }
lcMatrix44 YRot(lcVector4(Z[0], Z[1], 0.0f, 0.0f), lcVector4(-Z[1], Z[0], 0.0f, 0.0f), lcVector4(0.0f, 0.0f, 1.0f, 0.0f), lcVector4(0.0f, 0.0f, 0.0f, 1.0f)); const lcMatrix44 YRot(lcVector4(Z[0], Z[1], 0.0f, 0.0f), lcVector4(-Z[1], Z[0], 0.0f, 0.0f), lcVector4(0.0f, 0.0f, 1.0f, 0.0f), lcVector4(0.0f, 0.0f, 0.0f, 1.0f));
lcMatrix44 transform = lcMul(lcMul(lcMul(lcMatrix44AffineInverse(YRot), lcMatrix44RotationY(DistanceY)), YRot), lcMatrix44RotationZ(-DistanceX)); const lcMatrix44 transform = lcMul(lcMul(lcMul(lcMatrix44AffineInverse(YRot), lcMatrix44RotationY(DistanceY)), YRot), lcMatrix44RotationZ(-DistanceX));
mPosition = lcMul31(mPosition - CenterPosition, transform) + CenterPosition; mPosition = lcMul31(mPosition - CenterPosition, transform) + CenterPosition;
mTargetPosition = lcMul31(mTargetPosition - CenterPosition, transform) + CenterPosition; mTargetPosition = lcMul31(mTargetPosition - CenterPosition, transform) + CenterPosition;
@ -912,8 +912,8 @@ void lcCamera::Orbit(float DistanceX, float DistanceY, const lcVector3& CenterPo
void lcCamera::Roll(float Distance, lcStep Step, bool AddKey) void lcCamera::Roll(float Distance, lcStep Step, bool AddKey)
{ {
lcVector3 FrontVector(mPosition - mTargetPosition); const lcVector3 FrontVector(mPosition - mTargetPosition);
lcMatrix44 Rotation = lcMatrix44FromAxisAngle(FrontVector, Distance); const lcMatrix44 Rotation = lcMatrix44FromAxisAngle(FrontVector, Distance);
mUpVector = lcMul30(mUpVector, Rotation); mUpVector = lcMul30(mUpVector, Rotation);
@ -949,7 +949,7 @@ void lcCamera::Center(const lcVector3& NewCenter, lcStep Step, bool AddKey)
mTargetPosition = NewCenter; mTargetPosition = NewCenter;
lcVector3 FrontVector(mPosition - mTargetPosition); lcVector3 FrontVector(mPosition - mTargetPosition);
lcMatrix44 Rotation = lcMatrix44FromAxisAngle(FrontVector, Roll); const lcMatrix44 Rotation = lcMatrix44FromAxisAngle(FrontVector, Roll);
lcVector3 UpVector(0, 0, 1), SideVector; lcVector3 UpVector(0, 0, 1), SideVector;
FrontVector.Normalize(); FrontVector.Normalize();
@ -1032,7 +1032,7 @@ void lcCamera::SetViewpoint(const lcVector3& Position, const lcVector3& Target,
mPosition = Position; mPosition = Position;
mTargetPosition = Target; mTargetPosition = Target;
lcVector3 Direction = Target - Position; const lcVector3 Direction = Target - Position;
lcVector3 UpVector, SideVector; lcVector3 UpVector, SideVector;
SideVector = lcCross(Direction, Up); SideVector = lcCross(Direction, Up);
UpVector = lcCross(SideVector, Direction); UpVector = lcCross(SideVector, Direction);
@ -1052,11 +1052,11 @@ void lcCamera::SetAngles(float Latitude, float Longitude, float Distance)
mTargetPosition = lcVector3(0, 0, 0); mTargetPosition = lcVector3(0, 0, 0);
mUpVector = lcVector3(0, 0, 1); mUpVector = lcVector3(0, 0, 1);
lcMatrix33 LongitudeMatrix = lcMatrix33RotationZ(LC_DTOR * Longitude); const lcMatrix33 LongitudeMatrix = lcMatrix33RotationZ(LC_DTOR * Longitude);
mPosition = lcMul(mPosition, LongitudeMatrix); mPosition = lcMul(mPosition, LongitudeMatrix);
lcVector3 SideVector = lcMul(lcVector3(-1, 0, 0), LongitudeMatrix); const lcVector3 SideVector = lcMul(lcVector3(-1, 0, 0), LongitudeMatrix);
lcMatrix33 LatitudeMatrix = lcMatrix33FromAxisAngle(SideVector, LC_DTOR * Latitude); const lcMatrix33 LatitudeMatrix = lcMatrix33FromAxisAngle(SideVector, LC_DTOR * Latitude);
mPosition = lcMul(mPosition, LatitudeMatrix) * Distance; mPosition = lcMul(mPosition, LatitudeMatrix) * Distance;
mUpVector = lcMul(mUpVector, LatitudeMatrix); mUpVector = lcMul(mUpVector, LatitudeMatrix);
@ -1070,14 +1070,14 @@ void lcCamera::SetAngles(float Latitude, float Longitude, float Distance)
void lcCamera::GetAngles(float& Latitude, float& Longitude, float& Distance) const void lcCamera::GetAngles(float& Latitude, float& Longitude, float& Distance) const
{ {
lcVector3 FrontVector(mPosition - mTargetPosition); lcVector3 FrontVector(mPosition - mTargetPosition);
lcVector3 X(1, 0, 0); const lcVector3 X(1, 0, 0);
lcVector3 Y(0, 1, 0); const lcVector3 Y(0, 1, 0);
lcVector3 Z(0, 0, 1); const lcVector3 Z(0, 0, 1);
FrontVector.Normalize(); FrontVector.Normalize();
Latitude = acos(lcDot(-FrontVector, Z)) * LC_RTOD - 90.0f; Latitude = acos(lcDot(-FrontVector, Z)) * LC_RTOD - 90.0f;
lcVector3 CameraXY = -lcNormalize(lcVector3(FrontVector.x, FrontVector.y, 0.0f)); const lcVector3 CameraXY = -lcNormalize(lcVector3(FrontVector.x, FrontVector.y, 0.0f));
Longitude = acos(lcDot(CameraXY, Y)) * LC_RTOD; Longitude = acos(lcDot(CameraXY, Y)) * LC_RTOD;
if (lcDot(CameraXY, X) > 0) if (lcDot(CameraXY, X) > 0)

View file

@ -44,7 +44,9 @@ public:
~lcCamera(); ~lcCamera();
lcCamera(const lcCamera&) = delete; lcCamera(const lcCamera&) = delete;
lcCamera(lcCamera&&) = delete;
lcCamera& operator=(const lcCamera&) = delete; lcCamera& operator=(const lcCamera&) = delete;
lcCamera& operator=(lcCamera&&) = delete;
static lcViewpoint GetViewpoint(const QString& ViewpointName); static lcViewpoint GetViewpoint(const QString& ViewpointName);
@ -261,7 +263,7 @@ public:
// d d // d d
// a = 2 atan(------) => ~ a = --- => d = af // a = 2 atan(------) => ~ a = --- => d = af
// 2f f // 2f f
float f = (mPosition - mTargetPosition).Length(); const float f = (mPosition - mTargetPosition).Length();
return (m_fovy * f) * (LC_PI / 180.0f); return (m_fovy * f) * (LC_PI / 180.0f);
} }

View file

@ -4,7 +4,7 @@
static void CopyFromQImage(const QImage& Src, Image& Dest) static void CopyFromQImage(const QImage& Src, Image& Dest)
{ {
bool Alpha = Src.hasAlphaChannel(); const bool Alpha = Src.hasAlphaChannel();
Dest.Allocate(Src.width(), Src.height(), Alpha ? LC_PIXEL_FORMAT_R8G8B8A8 : LC_PIXEL_FORMAT_R8G8B8); Dest.Allocate(Src.width(), Src.height(), Alpha ? LC_PIXEL_FORMAT_R8G8B8A8 : LC_PIXEL_FORMAT_R8G8B8);
quint8* Bytes = (quint8*)Dest.mData; quint8* Bytes = (quint8*)Dest.mData;
@ -133,7 +133,7 @@ void Image::Resize(int width, int height)
unsigned char* bits = nullptr; unsigned char* bits = nullptr;
components = GetBPP(); components = GetBPP();
int BufferSize = width * height * components; const int BufferSize = width * height * components;
if (BufferSize) if (BufferSize)
{ {
@ -168,8 +168,8 @@ bool Image::FileLoad(lcMemFile& File)
{ {
QImage Image; QImage Image;
unsigned char* Buffer = File.mBuffer + File.mPosition; const unsigned char* Buffer = File.mBuffer + File.mPosition;
size_t BufferLength = File.mFileSize - File.mPosition; const size_t BufferLength = File.mFileSize - File.mPosition;
if (!Image.loadFromData(Buffer, (int)BufferLength)) if (!Image.loadFromData(Buffer, (int)BufferLength))
return false; return false;

View file

@ -160,6 +160,11 @@ public:
lcApplication(int& Argc, char** Argv); lcApplication(int& Argc, char** Argv);
~lcApplication(); ~lcApplication();
lcApplication(const lcApplication&) = delete;
lcApplication(lcApplication&&) = delete;
lcApplication& operator=(const lcApplication&) = delete;
lcApplication& operator=(lcApplication&&) = delete;
void SetProject(Project* Project); void SetProject(Project* Project);
static lcCommandLineOptions ParseCommandLineOptions(); static lcCommandLineOptions ParseCommandLineOptions();
lcStartupMode Initialize(const QList<QPair<QString, bool>>& LibraryPaths); lcStartupMode Initialize(const QList<QPair<QString, bool>>& LibraryPaths);

View file

@ -47,7 +47,7 @@ static void lcAdjustStudStyleColors(std::vector<lcColor>& Colors, lcStudStyle St
for (lcColor& Color : Colors) for (lcColor& Color : Colors)
{ {
lcVector3 LinearColor = lcSRGBToLinear(lcVector3(Color.Value)); const lcVector3 LinearColor = lcSRGBToLinear(lcVector3(Color.Value));
const float ValueLuminescence = lcLuminescence(LinearColor); const float ValueLuminescence = lcLuminescence(LinearColor);
if (Preferences.mAutomateEdgeColor) if (Preferences.mAutomateEdgeColor)

View file

@ -54,13 +54,13 @@ void lcLoadDefaultColors(lcStudStyle StudStyle);
bool lcLoadColorFile(lcFile& File, lcStudStyle StudStyle); bool lcLoadColorFile(lcFile& File, lcStudStyle StudStyle);
int lcGetColorIndex(quint32 ColorCode); int lcGetColorIndex(quint32 ColorCode);
inline quint32 lcGetColorCodeFromExtendedColor(int Color) constexpr quint32 lcGetColorCodeFromExtendedColor(int Color)
{ {
const quint32 ConversionTable[] = { 4, 12, 2, 10, 1, 9, 14, 15, 8, 0, 6, 13, 13, 334, 36, 44, 34, 42, 33, 41, 46, 47, 7, 382, 6, 13, 11, 383 }; const quint32 ConversionTable[] = { 4, 12, 2, 10, 1, 9, 14, 15, 8, 0, 6, 13, 13, 334, 36, 44, 34, 42, 33, 41, 46, 47, 7, 382, 6, 13, 11, 383 };
return ConversionTable[Color]; return ConversionTable[Color];
} }
inline quint32 lcGetColorCodeFromOriginalColor(int Color) constexpr quint32 lcGetColorCodeFromOriginalColor(int Color)
{ {
const quint32 ConversionTable[] = { 0, 2, 4, 9, 7, 6, 22, 8, 10, 11, 14, 16, 18, 9, 21, 20, 22, 8, 10, 11 }; const quint32 ConversionTable[] = { 0, 2, 4, 9, 7, 6, 22, 8, 10, 11, 14, 16, 18, 9, 21, 20, 22, 8, 10, 11 };
return lcGetColorCodeFromExtendedColor(ConversionTable[Color]); return lcGetColorCodeFromExtendedColor(ConversionTable[Color]);

View file

@ -320,7 +320,7 @@ void lcContext::CreateShaderPrograms()
mPrograms[MaterialType].EyePositionLocation = glGetUniformLocation(Program, "EyePosition"); mPrograms[MaterialType].EyePositionLocation = glGetUniformLocation(Program, "EyePosition");
mPrograms[MaterialType].HighlightParamsLocation = glGetUniformLocation(Program, "HighlightParams"); mPrograms[MaterialType].HighlightParamsLocation = glGetUniformLocation(Program, "HighlightParams");
GLint TextureLocation = glGetUniformLocation(Program, "Texture"); const GLint TextureLocation = glGetUniformLocation(Program, "Texture");
if (TextureLocation != -1) if (TextureLocation != -1)
{ {
@ -959,7 +959,7 @@ void lcContext::SetVertexFormatPosition(int PositionSize)
void lcContext::SetVertexFormatConditional(int BufferOffset) void lcContext::SetVertexFormatConditional(int BufferOffset)
{ {
const int VertexSize = 12 * sizeof(float); constexpr int VertexSize = 12 * sizeof(float);
const char* VertexBufferPointer = mVertexBufferPointer + BufferOffset; const char* VertexBufferPointer = mVertexBufferPointer + BufferOffset;
if (gSupportsShaderObjects) if (gSupportsShaderObjects)

View file

@ -113,7 +113,9 @@ public:
~lcContext(); ~lcContext();
lcContext(const lcContext&) = delete; lcContext(const lcContext&) = delete;
lcContext(lcContext&&) = delete;
lcContext& operator=(const lcContext&) = delete; lcContext& operator=(const lcContext&) = delete;
lcContext& operator=(lcContext&&) = delete;
static bool InitializeRenderer(); static bool InitializeRenderer();
static void ShutdownRenderer(); static void ShutdownRenderer();

View file

@ -1172,7 +1172,7 @@ void lcPiecesLibrary::LoadPieceInfo(PieceInfo* Info, bool Wait, bool Priority)
Info->Load(); Info->Load();
else else
{ {
if (Info->mState == LC_PIECEINFO_UNLOADED) if (Info->mState == lcPieceInfoState::Unloaded)
{ {
Info->Load(); Info->Load();
emit PartLoaded(Info); emit PartLoaded(Info);
@ -1181,7 +1181,7 @@ void lcPiecesLibrary::LoadPieceInfo(PieceInfo* Info, bool Wait, bool Priority)
{ {
LoadLock.unlock(); LoadLock.unlock();
while (Info->mState != LC_PIECEINFO_LOADED) while (Info->mState != lcPieceInfoState::Loaded)
lcSleeper::msleep(10); lcSleeper::msleep(10);
} }
} }
@ -1218,9 +1218,9 @@ void lcPiecesLibrary::LoadQueuedPiece()
{ {
Info = mLoadQueue.takeFirst(); Info = mLoadQueue.takeFirst();
if (Info->mState == LC_PIECEINFO_UNLOADED && Info->GetRefCount() > 0) if (Info->mState == lcPieceInfoState::Unloaded && Info->GetRefCount() > 0)
{ {
Info->mState = LC_PIECEINFO_LOADING; Info->mState = lcPieceInfoState::Loading;
break; break;
} }
@ -1502,7 +1502,7 @@ void lcPiecesLibrary::UnloadUnusedParts()
for (const auto& PieceIt : mPieces) for (const auto& PieceIt : mPieces)
{ {
PieceInfo* Info = PieceIt.second; PieceInfo* Info = PieceIt.second;
if (Info->GetRefCount() == 0 && Info->mState != LC_PIECEINFO_UNLOADED) if (Info->GetRefCount() == 0 && Info->mState != lcPieceInfoState::Unloaded)
ReleasePieceInfo(Info); ReleasePieceInfo(Info);
} }
} }
@ -1583,7 +1583,7 @@ void lcPiecesLibrary::SetStudStyle(lcStudStyle StudStyle, bool Reload)
{ {
PieceInfo* Info = PieceIt.second; PieceInfo* Info = PieceIt.second;
if (Info->mState == LC_PIECEINFO_LOADED && Info->GetMesh() && Info->GetMesh()->mFlags & lcMeshFlag::HasStyleStud) if (Info->mState == lcPieceInfoState::Loaded && Info->GetMesh() && Info->GetMesh()->mFlags & lcMeshFlag::HasStyleStud)
{ {
Info->Unload(); Info->Unload();
mLoadQueue.append(Info); mLoadQueue.append(Info);

View file

@ -23,7 +23,7 @@ enum class lcStudStyle
Count Count
}; };
inline bool lcIsHighContrast(lcStudStyle StudStyle) constexpr bool lcIsHighContrast(lcStudStyle StudStyle)
{ {
return StudStyle == lcStudStyle::HighContrast || StudStyle == lcStudStyle::HighContrastLogo; return StudStyle == lcStudStyle::HighContrast || StudStyle == lcStudStyle::HighContrastLogo;
} }
@ -98,12 +98,19 @@ enum class lcLibrarySourceType
struct lcLibrarySource struct lcLibrarySource
{ {
lcLibrarySource() = default;
~lcLibrarySource() ~lcLibrarySource()
{ {
for (const auto& PrimitiveIt : Primitives) for (const auto& PrimitiveIt : Primitives)
delete PrimitiveIt.second; delete PrimitiveIt.second;
} }
lcLibrarySource(const lcLibrarySource&) = delete;
lcLibrarySource(lcLibrarySource&&) = delete;
lcLibrarySource& operator=(const lcLibrarySource&) = delete;
lcLibrarySource& operator=(lcLibrarySource&&) = delete;
lcLibrarySourceType Type; lcLibrarySourceType Type;
std::map<std::string, lcLibraryPrimitive*> Primitives; std::map<std::string, lcLibraryPrimitive*> Primitives;
}; };
@ -117,7 +124,9 @@ public:
~lcPiecesLibrary(); ~lcPiecesLibrary();
lcPiecesLibrary(const lcPiecesLibrary&) = delete; lcPiecesLibrary(const lcPiecesLibrary&) = delete;
lcPiecesLibrary(lcPiecesLibrary&&) = delete;
lcPiecesLibrary& operator=(const lcPiecesLibrary&) = delete; lcPiecesLibrary& operator=(const lcPiecesLibrary&) = delete;
lcPiecesLibrary& operator=(lcPiecesLibrary&&) = delete;
bool Load(const QString& LibraryPath, bool ShowProgress); bool Load(const QString& LibraryPath, bool ShowProgress);
void LoadColors(); void LoadColors();

View file

@ -66,7 +66,7 @@ public:
mActiveView = ActiveView; mActiveView = ActiveView;
} }
void RemoveView(lcView* View) void RemoveView(const lcView* View)
{ {
if (View == mActiveView) if (View == mActiveView)
mActiveView = nullptr; mActiveView = nullptr;

View file

@ -819,10 +819,8 @@ inline lcMatrix33 lcMatrix33RotationY(const float Radians)
inline lcMatrix33 lcMatrix33RotationZ(const float Radians) inline lcMatrix33 lcMatrix33RotationZ(const float Radians)
{ {
float s, c; float s = sinf(Radians);
float c = cosf(Radians);
s = sinf(Radians);
c = cosf(Radians);
lcMatrix33 m; lcMatrix33 m;
@ -835,27 +833,25 @@ inline lcMatrix33 lcMatrix33RotationZ(const float Radians)
inline lcMatrix33 lcMatrix33FromAxisAngle(const lcVector3& Axis, const float Radians) inline lcMatrix33 lcMatrix33FromAxisAngle(const lcVector3& Axis, const float Radians)
{ {
float s, c, mag, xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c; float s = sinf(Radians);
float c = cosf(Radians);
s = sinf(Radians); float mag = Axis.Length();
c = cosf(Radians);
mag = Axis.Length();
if (mag == 0.0f) if (mag == 0.0f)
return lcMatrix33Identity(); return lcMatrix33Identity();
lcVector3 Normal = Axis * (1.0f / mag); lcVector3 Normal = Axis * (1.0f / mag);
xx = Normal[0] * Normal[0]; float xx = Normal[0] * Normal[0];
yy = Normal[1] * Normal[1]; float yy = Normal[1] * Normal[1];
zz = Normal[2] * Normal[2]; float zz = Normal[2] * Normal[2];
xy = Normal[0] * Normal[1]; float xy = Normal[0] * Normal[1];
yz = Normal[1] * Normal[2]; float yz = Normal[1] * Normal[2];
zx = Normal[2] * Normal[0]; float zx = Normal[2] * Normal[0];
xs = Normal[0] * s; float xs = Normal[0] * s;
ys = Normal[1] * s; float ys = Normal[1] * s;
zs = Normal[2] * s; float zs = Normal[2] * s;
one_c = 1.0f - c; float one_c = 1.0f - c;
lcMatrix33 m; lcMatrix33 m;

View file

@ -191,7 +191,7 @@ bool lcMesh::MinIntersectDist(const lcVector3& Start, const lcVector3& End, floa
if (!lcBoundingBoxRayIntersectDistance(mBoundingBox.Min, mBoundingBox.Max, Start, End, &Distance, nullptr) || (Distance >= MinDistance)) if (!lcBoundingBoxRayIntersectDistance(mBoundingBox.Min, mBoundingBox.Max, Start, End, &Distance, nullptr) || (Distance >= MinDistance))
return false; return false;
lcVertex* const Verts = (lcVertex*)mVertexData; const lcVertex* const Verts = (lcVertex*)mVertexData;
bool Hit = false; bool Hit = false;
lcVector3 Intersection; lcVector3 Intersection;

View file

@ -76,7 +76,9 @@ public:
~lcMesh(); ~lcMesh();
lcMesh(const lcMesh&) = delete; lcMesh(const lcMesh&) = delete;
lcMesh(lcMesh&&) = delete;
lcMesh& operator=(const lcMesh&) = delete; lcMesh& operator=(const lcMesh&) = delete;
lcMesh& operator=(lcMesh&&) = delete;
void Create(quint16 (&NumSections)[LC_NUM_MESH_LODS], int VertexCount, int TexturedVertexCount, int ConditionalVertexCount, int IndexCount); void Create(quint16 (&NumSections)[LC_NUM_MESH_LODS], int VertexCount, int TexturedVertexCount, int ConditionalVertexCount, int IndexCount);
void CreateBox(); void CreateBox();

View file

@ -12,16 +12,16 @@ static void lcCheckTexCoordsWrap(const lcVector4& Plane2, const lcVector3 (&Posi
lcVector2& TexCoords2 = TexCoords[1]; lcVector2& TexCoords2 = TexCoords[1];
lcVector2& TexCoords3 = TexCoords[2]; lcVector2& TexCoords3 = TexCoords[2];
float u12 = fabsf(TexCoords1.x - TexCoords2.x); const float u12 = fabsf(TexCoords1.x - TexCoords2.x);
float u13 = fabsf(TexCoords1.x - TexCoords3.x); const float u13 = fabsf(TexCoords1.x - TexCoords3.x);
float u23 = fabsf(TexCoords2.x - TexCoords3.x); const float u23 = fabsf(TexCoords2.x - TexCoords3.x);
if (u12 < 0.5f && u13 < 0.5f && u23 < 0.5f) if (u12 < 0.5f && u13 < 0.5f && u23 < 0.5f)
return; return;
float Dot1 = fabsf(lcDot(Plane2, lcVector4(Positions[0], 1.0f))); const float Dot1 = fabsf(lcDot(Plane2, lcVector4(Positions[0], 1.0f)));
float Dot2 = fabsf(lcDot(Plane2, lcVector4(Positions[1], 1.0f))); const float Dot2 = fabsf(lcDot(Plane2, lcVector4(Positions[1], 1.0f)));
float Dot3 = fabsf(lcDot(Plane2, lcVector4(Positions[2], 1.0f))); const float Dot3 = fabsf(lcDot(Plane2, lcVector4(Positions[2], 1.0f)));
if (Dot1 > Dot2) if (Dot1 > Dot2)
{ {
@ -89,11 +89,11 @@ static void lcCheckTexCoordsPole(const lcVector4& FrontPlane, const lcVector4& P
else else
return; return;
lcVector3 OppositeEdge = Positions[EdgeIndex2] - Positions[EdgeIndex1]; const lcVector3 OppositeEdge = Positions[EdgeIndex2] - Positions[EdgeIndex1];
lcVector3 SideEdge = Positions[PoleIndex] - Positions[EdgeIndex1]; const lcVector3 SideEdge = Positions[PoleIndex] - Positions[EdgeIndex1];
float OppositeLength = lcLength(OppositeEdge); const float OppositeLength = lcLength(OppositeEdge);
float Projection = lcDot(OppositeEdge, SideEdge) / (OppositeLength * OppositeLength); const float Projection = lcDot(OppositeEdge, SideEdge) / (OppositeLength * OppositeLength);
TexCoords[PoleIndex].x = TexCoords[EdgeIndex1].x + (TexCoords[EdgeIndex2].x - TexCoords[EdgeIndex1].x) * Projection; TexCoords[PoleIndex].x = TexCoords[EdgeIndex1].x + (TexCoords[EdgeIndex2].x - TexCoords[EdgeIndex1].x) * Projection;
} }
@ -108,18 +108,18 @@ static void lcResequenceQuad(int* Indices, int a, int b, int c, int d)
static void lcTestQuad(int* QuadIndices, const lcVector3* Vertices) static void lcTestQuad(int* QuadIndices, const lcVector3* Vertices)
{ {
lcVector3 v01 = Vertices[1] - Vertices[0]; const lcVector3 v01 = Vertices[1] - Vertices[0];
lcVector3 v02 = Vertices[2] - Vertices[0]; const lcVector3 v02 = Vertices[2] - Vertices[0];
lcVector3 v03 = Vertices[3] - Vertices[0]; const lcVector3 v03 = Vertices[3] - Vertices[0];
lcVector3 cp1 = lcCross(v01, v02); const lcVector3 cp1 = lcCross(v01, v02);
lcVector3 cp2 = lcCross(v02, v03); const lcVector3 cp2 = lcCross(v02, v03);
if (lcDot(cp1, cp2) > 0.0f) if (lcDot(cp1, cp2) > 0.0f)
return; return;
lcVector3 v12 = Vertices[2] - Vertices[1]; const lcVector3 v12 = Vertices[2] - Vertices[1];
lcVector3 v13 = Vertices[3] - Vertices[1]; const lcVector3 v13 = Vertices[3] - Vertices[1];
lcVector3 v23 = Vertices[3] - Vertices[2]; const lcVector3 v23 = Vertices[3] - Vertices[2];
if (lcDot(lcCross(v12, v01), lcCross(v01, v13)) > 0.0f) if (lcDot(lcCross(v12, v01), lcCross(v01, v13)) > 0.0f)
{ {
@ -137,7 +137,7 @@ static void lcTestQuad(int* QuadIndices, const lcVector3* Vertices)
} }
} }
const float lcDistanceEpsilon = 0.01f; // Maximum value for 50591.dat constexpr float lcDistanceEpsilon = 0.01f; // Maximum value for 50591.dat
static bool lcCompareVertices(const lcVector3& Position1, const lcVector3& Position2) static bool lcCompareVertices(const lcVector3& Position1, const lcVector3& Position2)
{ {
@ -146,7 +146,7 @@ static bool lcCompareVertices(const lcVector3& Position1, const lcVector3& Posit
lcMeshLoaderSection* lcMeshLoaderTypeData::AddSection(lcMeshPrimitiveType PrimitiveType, lcMeshLoaderMaterial* Material) lcMeshLoaderSection* lcMeshLoaderTypeData::AddSection(lcMeshPrimitiveType PrimitiveType, lcMeshLoaderMaterial* Material)
{ {
for (std::unique_ptr<lcMeshLoaderSection>& Section : mSections) for (const std::unique_ptr<lcMeshLoaderSection>& Section : mSections)
if (Section->mMaterial == Material && Section->mPrimitiveType == PrimitiveType) if (Section->mMaterial == Material && Section->mPrimitiveType == PrimitiveType)
return Section.get(); return Section.get();
@ -226,7 +226,7 @@ quint32 lcMeshLoaderTypeData::AddConditionalVertex(const lcVector3(&Position)[4]
void lcMeshLoaderTypeData::ProcessLine(int LineType, lcMeshLoaderMaterial* Material, bool WindingCCW, lcVector3 (&Vertices)[4], bool Optimize) void lcMeshLoaderTypeData::ProcessLine(int LineType, lcMeshLoaderMaterial* Material, bool WindingCCW, lcVector3 (&Vertices)[4], bool Optimize)
{ {
lcMeshPrimitiveType PrimitiveTypes[4] = { LC_MESH_LINES, LC_MESH_TRIANGLES, LC_MESH_TRIANGLES, LC_MESH_CONDITIONAL_LINES }; constexpr lcMeshPrimitiveType PrimitiveTypes[4] = { LC_MESH_LINES, LC_MESH_TRIANGLES, LC_MESH_TRIANGLES, LC_MESH_CONDITIONAL_LINES };
lcMeshPrimitiveType PrimitiveType = PrimitiveTypes[LineType - 2]; lcMeshPrimitiveType PrimitiveType = PrimitiveTypes[LineType - 2];
if (Material->Type != lcMeshLoaderMaterialType::Solid && PrimitiveType == LC_MESH_TRIANGLES) if (Material->Type != lcMeshLoaderMaterialType::Solid && PrimitiveType == LC_MESH_TRIANGLES)
@ -324,7 +324,7 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l
for (const lcMeshLoaderVertex& DataVertex : DataVertices) for (const lcMeshLoaderVertex& DataVertex : DataVertices)
{ {
lcVector3 Position = lcMul31(DataVertex.Position, Transform); const lcVector3 Position = lcMul31(DataVertex.Position, Transform);
int Index; int Index;
if (DataVertex.NormalWeight == 0.0f) if (DataVertex.NormalWeight == 0.0f)
@ -352,7 +352,7 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l
Position[2] = lcMul31(DataVertex.Position[2], Transform); Position[2] = lcMul31(DataVertex.Position[2], Transform);
Position[3] = lcMul31(DataVertex.Position[3], Transform); Position[3] = lcMul31(DataVertex.Position[3], Transform);
int Index = AddConditionalVertex(Position); const int Index = AddConditionalVertex(Position);
ConditionalRemap.Add(Index); ConditionalRemap.Add(Index);
} }
@ -386,12 +386,12 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l
if (PrimitiveType == LC_MESH_CONDITIONAL_LINES) if (PrimitiveType == LC_MESH_CONDITIONAL_LINES)
{ {
for (quint32 Index : SrcSection->mIndices) for (const quint32 Index : SrcSection->mIndices)
DstSection->mIndices.Add(ConditionalRemap[Index]); DstSection->mIndices.Add(ConditionalRemap[Index]);
} }
else if (!InvertWinding || (PrimitiveType == LC_MESH_LINES)) else if (!InvertWinding || (PrimitiveType == LC_MESH_LINES))
{ {
for (quint32 Index : SrcSection->mIndices) for (const quint32 Index : SrcSection->mIndices)
DstSection->mIndices.Add(IndexRemap[Index]); DstSection->mIndices.Add(IndexRemap[Index]);
} }
else else
@ -429,7 +429,7 @@ void lcMeshLoaderTypeData::AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeDat
} }
mConditionalVertices.AllocGrow(Data.mConditionalVertices.GetSize()); mConditionalVertices.AllocGrow(Data.mConditionalVertices.GetSize());
quint32 BaseConditional = mConditionalVertices.GetSize(); const quint32 BaseConditional = mConditionalVertices.GetSize();
for (const lcMeshLoaderConditionalVertex& DataVertex : Data.mConditionalVertices) for (const lcMeshLoaderConditionalVertex& DataVertex : Data.mConditionalVertices)
{ {
@ -472,12 +472,12 @@ void lcMeshLoaderTypeData::AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeDat
if (PrimitiveType == LC_MESH_CONDITIONAL_LINES) if (PrimitiveType == LC_MESH_CONDITIONAL_LINES)
{ {
for (quint32 Index : SrcSection->mIndices) for (const quint32 Index : SrcSection->mIndices)
DstSection->mIndices.Add(BaseConditional + Index); DstSection->mIndices.Add(BaseConditional + Index);
} }
else if (!InvertWinding || (PrimitiveType == LC_MESH_LINES)) else if (!InvertWinding || (PrimitiveType == LC_MESH_LINES))
{ {
for (quint32 Index : SrcSection->mIndices) for (const quint32 Index : SrcSection->mIndices)
DstSection->mIndices.Add(BaseIndex + Index); DstSection->mIndices.Add(BaseIndex + Index);
} }
else else
@ -507,7 +507,7 @@ void lcLibraryMeshData::AddIndices(lcMeshDataType MeshDataType, lcMeshPrimitiveT
{ {
lcMeshLoaderSection* Section = mData[MeshDataType].AddSection(PrimitiveType, GetMaterial(ColorCode)); lcMeshLoaderSection* Section = mData[MeshDataType].AddSection(PrimitiveType, GetMaterial(ColorCode));
lcArray<quint32>& Indices = Section->mIndices; lcArray<quint32>& Indices = Section->mIndices;
int CurrentSize = Indices.GetSize(); const int CurrentSize = Indices.GetSize();
Indices.SetSize(CurrentSize + IndexCount); Indices.SetSize(CurrentSize + IndexCount);
@ -538,7 +538,7 @@ void lcLibraryMeshData::AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Dat
lcMeshLoaderMaterial* lcLibraryMeshData::GetMaterial(quint32 ColorCode) lcMeshLoaderMaterial* lcLibraryMeshData::GetMaterial(quint32 ColorCode)
{ {
for (std::unique_ptr<lcMeshLoaderMaterial>& Material : mMaterials) for (const std::unique_ptr<lcMeshLoaderMaterial>& Material : mMaterials)
if (Material->Type == lcMeshLoaderMaterialType::Solid && Material->Color == ColorCode) if (Material->Type == lcMeshLoaderMaterialType::Solid && Material->Color == ColorCode)
return Material.get(); return Material.get();
@ -553,7 +553,7 @@ lcMeshLoaderMaterial* lcLibraryMeshData::GetMaterial(quint32 ColorCode)
lcMeshLoaderMaterial* lcLibraryMeshData::GetTexturedMaterial(quint32 ColorCode, const lcMeshLoaderTextureMap& TextureMap) lcMeshLoaderMaterial* lcLibraryMeshData::GetTexturedMaterial(quint32 ColorCode, const lcMeshLoaderTextureMap& TextureMap)
{ {
for (std::unique_ptr<lcMeshLoaderMaterial>& Material : mMaterials) for (const std::unique_ptr<lcMeshLoaderMaterial>& Material : mMaterials)
{ {
if (Material->Type != TextureMap.Type || Material->Color != ColorCode) if (Material->Type != TextureMap.Type || Material->Color != ColorCode)
continue; continue;
@ -617,8 +617,8 @@ static bool lcMeshLoaderFinalSectionCompare(const lcMeshLoaderFinalSection& a, c
} }
} }
bool TranslucentA = lcIsColorTranslucent(a.Color); const bool TranslucentA = lcIsColorTranslucent(a.Color);
bool TranslucentB = lcIsColorTranslucent(b.Color); const bool TranslucentB = lcIsColorTranslucent(b.Color);
if (TranslucentA != TranslucentB) if (TranslucentA != TranslucentB)
return !TranslucentA; return !TranslucentA;
@ -653,7 +653,7 @@ void lcLibraryMeshData::GeneratePlanarTexcoords(lcMeshLoaderSection* Section, co
for (int EdgeIdx = 0; EdgeIdx < 2; EdgeIdx++) for (int EdgeIdx = 0; EdgeIdx < 2; EdgeIdx++)
{ {
lcVector3 Normal = Material->Points[EdgeIdx + 1] - Material->Points[0]; lcVector3 Normal = Material->Points[EdgeIdx + 1] - Material->Points[0];
float Length = lcLength(Normal); const float Length = lcLength(Normal);
Normal /= Length; Normal /= Length;
Planes[EdgeIdx].x = Normal.x / Length; Planes[EdgeIdx].x = Normal.x / Length;
@ -666,7 +666,7 @@ void lcLibraryMeshData::GeneratePlanarTexcoords(lcMeshLoaderSection* Section, co
{ {
const lcMeshLoaderVertex& SrcVertex = Data.mVertices[Index]; const lcMeshLoaderVertex& SrcVertex = Data.mVertices[Index];
lcVector2 TexCoords(lcDot3(SrcVertex.Position, Planes[0]) + Planes[0].w, lcDot3(SrcVertex.Position, Planes[1]) + Planes[1].w); const lcVector2 TexCoords(lcDot3(SrcVertex.Position, Planes[0]) + Planes[0].w, lcDot3(SrcVertex.Position, Planes[1]) + Planes[1].w);
Index = AddTexturedVertex(SrcVertex.Position, SrcVertex.Normal, TexCoords); Index = AddTexturedVertex(SrcVertex.Position, SrcVertex.Normal, TexCoords);
} }
@ -741,12 +741,12 @@ void lcLibraryMeshData::GenerateSphericalTexcoords(lcMeshLoaderSection* Section,
for (int CornerIndex = 0; CornerIndex < 3; CornerIndex++) for (int CornerIndex = 0; CornerIndex < 3; CornerIndex++)
{ {
lcVector3 VertexDir = Positions[CornerIndex] - Center; const lcVector3 VertexDir = Positions[CornerIndex] - Center;
float DotPlane1 = lcDot(lcVector4(Positions[CornerIndex], 1.0f), Plane1); const float DotPlane1 = lcDot(lcVector4(Positions[CornerIndex], 1.0f), Plane1);
lcVector3 PointInPlane1 = Positions[CornerIndex] - lcVector3(Plane1) * DotPlane1; const lcVector3 PointInPlane1 = Positions[CornerIndex] - lcVector3(Plane1) * DotPlane1;
float DotFrontPlane = lcDot(lcVector4(PointInPlane1, 1.0f), FrontPlane); const float DotFrontPlane = lcDot(lcVector4(PointInPlane1, 1.0f), FrontPlane);
float DotPlane2 = lcDot(lcVector4(PointInPlane1, 1.0f), Plane2); const float DotPlane2 = lcDot(lcVector4(PointInPlane1, 1.0f), Plane2);
const float AngleX = atan2f(DotPlane2, DotFrontPlane) / LC_PI * Angle1; const float AngleX = atan2f(DotPlane2, DotFrontPlane) / LC_PI * Angle1;
TexCoords[CornerIndex].x = 0.5f + 0.5f * AngleX; TexCoords[CornerIndex].x = 0.5f + 0.5f * AngleX;
@ -767,7 +767,7 @@ void lcLibraryMeshData::GenerateTexturedVertices()
{ {
for (lcMeshLoaderTypeData& Data : mData) for (lcMeshLoaderTypeData& Data : mData)
{ {
for (std::unique_ptr<lcMeshLoaderSection>& Section : Data.mSections) for (const std::unique_ptr<lcMeshLoaderSection>& Section : Data.mSections)
{ {
switch (Section->mMaterial->Type) switch (Section->mMaterial->Type)
{ {
@ -834,14 +834,14 @@ lcMesh* lcLibraryMeshData::CreateMesh()
strcpy(FinalSection.Name, Section->mMaterial->Name); strcpy(FinalSection.Name, Section->mMaterial->Name);
}; };
for (std::unique_ptr<lcMeshLoaderSection>& Section : mData[LC_MESHDATA_SHARED].mSections) for (const std::unique_ptr<lcMeshLoaderSection>& Section : mData[LC_MESHDATA_SHARED].mSections)
{ {
NumIndices += Section->mIndices.GetSize(); NumIndices += Section->mIndices.GetSize();
AddFinalSection(Section.get(), FinalSections[LodIdx]); AddFinalSection(Section.get(), FinalSections[LodIdx]);
} }
for (std::unique_ptr<lcMeshLoaderSection>& Section : mData[LodIdx].mSections) for (const std::unique_ptr<lcMeshLoaderSection>& Section : mData[LodIdx].mSections)
{ {
NumIndices += Section->mIndices.GetSize(); NumIndices += Section->mIndices.GetSize();
@ -942,7 +942,7 @@ void lcLibraryMeshData::WriteSections(lcMesh* Mesh, const lcArray<lcMeshLoaderFi
IndexType* Index = (IndexType*)Mesh->mIndexData + NumIndices; IndexType* Index = (IndexType*)Mesh->mIndexData + NumIndices;
auto AddSection = [this, &DstSection, &Index, &BaseVertices, &BaseConditionalVertices](lcMeshLoaderSection* SrcSection, lcMeshDataType SrcDataType) const auto AddSection = [this, &DstSection, &Index, &BaseVertices, &BaseConditionalVertices](lcMeshLoaderSection* SrcSection, lcMeshDataType SrcDataType)
{ {
switch (DstSection.PrimitiveType) switch (DstSection.PrimitiveType)
{ {
@ -979,13 +979,13 @@ void lcLibraryMeshData::WriteSections(lcMesh* Mesh, const lcArray<lcMeshLoaderFi
DstSection.NumIndices += SrcSection->mIndices.GetSize(); DstSection.NumIndices += SrcSection->mIndices.GetSize();
}; };
for (std::unique_ptr<lcMeshLoaderSection>& Section : mData[LC_MESHDATA_SHARED].mSections) for (const std::unique_ptr<lcMeshLoaderSection>& Section : mData[LC_MESHDATA_SHARED].mSections)
if (FinalSection.PrimitiveType == Section->mPrimitiveType && FinalSection.Color == Section->mMaterial->Color && !strcmp(FinalSection.Name, Section->mMaterial->Name)) if (FinalSection.PrimitiveType == Section->mPrimitiveType && FinalSection.Color == Section->mMaterial->Color && !strcmp(FinalSection.Name, Section->mMaterial->Name))
AddSection(Section.get(), LC_MESHDATA_SHARED); AddSection(Section.get(), LC_MESHDATA_SHARED);
const lcMeshDataType MeshDataType = (LodIdx == LC_MESH_LOD_LOW) ? LC_MESHDATA_LOW : LC_MESHDATA_HIGH; const lcMeshDataType MeshDataType = (LodIdx == LC_MESH_LOD_LOW) ? LC_MESHDATA_LOW : LC_MESHDATA_HIGH;
for (std::unique_ptr<lcMeshLoaderSection>& Section : mData[MeshDataType].mSections) for (const std::unique_ptr<lcMeshLoaderSection>& Section : mData[MeshDataType].mSections)
if (FinalSection.PrimitiveType == Section->mPrimitiveType && FinalSection.Color == Section->mMaterial->Color && !strcmp(FinalSection.Name, Section->mMaterial->Name)) if (FinalSection.PrimitiveType == Section->mPrimitiveType && FinalSection.Color == Section->mMaterial->Color && !strcmp(FinalSection.Name, Section->mMaterial->Name))
AddSection(Section.get(), MeshDataType); AddSection(Section.get(), MeshDataType);
@ -1053,7 +1053,7 @@ void lcLibraryMeshData::UpdateMeshBoundingBox(lcMesh* Mesh)
} }
template<typename IndexType> template<typename IndexType>
void lcLibraryMeshData::UpdateMeshSectionBoundingBox(lcMesh* Mesh, lcMeshSection& Section, lcVector3& SectionMin, lcVector3& SectionMax) void lcLibraryMeshData::UpdateMeshSectionBoundingBox(const lcMesh* Mesh, const lcMeshSection& Section, lcVector3& SectionMin, lcVector3& SectionMax)
{ {
const IndexType* IndexBuffer = reinterpret_cast<IndexType*>(static_cast<char*>(Mesh->mIndexData) + Section.IndexOffset); const IndexType* IndexBuffer = reinterpret_cast<IndexType*>(static_cast<char*>(Mesh->mIndexData) + Section.IndexOffset);
@ -1386,7 +1386,7 @@ bool lcMeshLoader::ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform
IncludeTransform = lcMul(IncludeTransform, CurrentTransform); IncludeTransform = lcMul(IncludeTransform, CurrentTransform);
bool Mirror = IncludeTransform.Determinant() < 0.0f; bool Mirror = IncludeTransform.Determinant() < 0.0f;
auto FileCallback = [this, &IncludeTransform, &ColorCode, &Mirror, &InvertNext, &MeshDataType](lcFile& File) const auto FileCallback = [this, &IncludeTransform, &ColorCode, &Mirror, &InvertNext, &MeshDataType](lcFile& File)
{ {
ReadMeshData(File, IncludeTransform, ColorCode, Mirror ^ InvertNext, MeshDataType); ReadMeshData(File, IncludeTransform, ColorCode, Mirror ^ InvertNext, MeshDataType);
}; };

View file

@ -208,7 +208,7 @@ protected:
static void UpdateMeshBoundingBox(lcMesh* Mesh); static void UpdateMeshBoundingBox(lcMesh* Mesh);
template<typename IndexType> template<typename IndexType>
static void UpdateMeshSectionBoundingBox(lcMesh* Mesh, lcMeshSection& Section, lcVector3& SectionMin, lcVector3& SectionMax); static void UpdateMeshSectionBoundingBox(const lcMesh* Mesh, const lcMeshSection& Section, lcVector3& SectionMin, lcVector3& SectionMax);
}; };
class lcMeshLoader class lcMeshLoader

View file

@ -39,7 +39,7 @@ void lcModelProperties::SaveDefaults()
void lcModelProperties::SaveLDraw(QTextStream& Stream) const void lcModelProperties::SaveLDraw(QTextStream& Stream) const
{ {
QLatin1String LineEnding("\r\n"); const QLatin1String LineEnding("\r\n");
Stream << QLatin1String("0 ") << mDescription << LineEnding; Stream << QLatin1String("0 ") << mDescription << LineEnding;
Stream << QLatin1String("0 Name: ") << mModelName << LineEnding; Stream << QLatin1String("0 Name: ") << mModelName << LineEnding;
@ -61,7 +61,7 @@ bool lcModelProperties::ParseLDrawHeader(QString Line, bool FirstLine)
QString Token; QString Token;
LineStream >> Token; LineStream >> Token;
int StartPos = LineStream.pos(); const int StartPos = LineStream.pos();
LineStream >> Token; LineStream >> Token;
if (Token == QLatin1String("!LEOCAD")) if (Token == QLatin1String("!LEOCAD"))
@ -139,7 +139,7 @@ lcModel::~lcModel()
bool lcModel::GetPieceWorldMatrix(lcPiece* Piece, lcMatrix44& ParentWorldMatrix) const bool lcModel::GetPieceWorldMatrix(lcPiece* Piece, lcMatrix44& ParentWorldMatrix) const
{ {
for (lcPiece* ModelPiece : mPieces) for (const lcPiece* ModelPiece : mPieces)
{ {
if (ModelPiece == Piece) if (ModelPiece == Piece)
{ {
@ -147,7 +147,7 @@ bool lcModel::GetPieceWorldMatrix(lcPiece* Piece, lcMatrix44& ParentWorldMatrix)
return true; return true;
} }
PieceInfo* Info = ModelPiece->mPieceInfo; const PieceInfo* Info = ModelPiece->mPieceInfo;
if (Info->IsModel()) if (Info->IsModel())
{ {
@ -169,7 +169,7 @@ bool lcModel::IncludesModel(const lcModel* Model) const
if (Model == this) if (Model == this)
return true; return true;
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->mPieceInfo->IncludesModel(Model)) if (Piece->mPieceInfo->IncludesModel(Model))
return true; return true;
@ -235,7 +235,7 @@ void lcModel::UpdatePieceInfo(std::vector<lcModel*>& UpdatedModels)
mPieceInfo->SetModel(this, false, nullptr, false); mPieceInfo->SetModel(this, false, nullptr, false);
UpdatedModels.push_back(this); UpdatedModels.push_back(this);
lcMesh* Mesh = mPieceInfo->GetMesh(); const lcMesh* Mesh = mPieceInfo->GetMesh();
if (mPieces.IsEmpty() && !Mesh) if (mPieces.IsEmpty() && !Mesh)
{ {
@ -265,7 +265,7 @@ void lcModel::UpdatePieceInfo(std::vector<lcModel*>& UpdatedModels)
void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const
{ {
QLatin1String LineEnding("\r\n"); const QLatin1String LineEnding("\r\n");
mProperties.SaveLDraw(Stream); mProperties.SaveLDraw(Stream);
@ -333,7 +333,7 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const
while (!CurrentGroups.IsEmpty()) while (!CurrentGroups.IsEmpty())
{ {
lcGroup* Group = CurrentGroups[CurrentGroups.GetSize() - 1]; lcGroup* Group = CurrentGroups[CurrentGroups.GetSize() - 1];
int Index = PieceParents.FindIndex(Group); const int Index = PieceParents.FindIndex(Group);
if (Index == -1) if (Index == -1)
{ {
@ -376,7 +376,7 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const
Stream << QLatin1String("0 !LEOCAD SYNTH CONTROL_POINT"); Stream << QLatin1String("0 !LEOCAD SYNTH CONTROL_POINT");
const float* FloatMatrix = ControlPoint.Transform; const float* FloatMatrix = ControlPoint.Transform;
float Numbers[13] = { FloatMatrix[12], -FloatMatrix[14], FloatMatrix[13], FloatMatrix[0], -FloatMatrix[8], FloatMatrix[4], -FloatMatrix[2], FloatMatrix[10], -FloatMatrix[6], FloatMatrix[1], -FloatMatrix[9], FloatMatrix[5], ControlPoint.Scale }; const float Numbers[13] = { FloatMatrix[12], -FloatMatrix[14], FloatMatrix[13], FloatMatrix[0], -FloatMatrix[8], FloatMatrix[4], -FloatMatrix[2], FloatMatrix[10], -FloatMatrix[6], FloatMatrix[1], -FloatMatrix[9], FloatMatrix[5], ControlPoint.Scale };
for (int NumberIdx = 0; NumberIdx < 13; NumberIdx++) for (int NumberIdx = 0; NumberIdx < 13; NumberIdx++)
Stream << ' ' << lcFormatValue(Numbers[NumberIdx], NumberIdx < 3 ? 4 : 6); Stream << ' ' << lcFormatValue(Numbers[NumberIdx], NumberIdx < 3 ? 4 : 6);
@ -419,11 +419,11 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const
Stream << QLatin1String("0 !LEOCAD GROUP END\r\n"); Stream << QLatin1String("0 !LEOCAD GROUP END\r\n");
} }
for (lcCamera* Camera : mCameras) for (const lcCamera* Camera : mCameras)
if (!SelectedOnly || Camera->IsSelected()) if (!SelectedOnly || Camera->IsSelected())
Camera->SaveLDraw(Stream); Camera->SaveLDraw(Stream);
for (lcLight* Light : mLights) for (const lcLight* Light : mLights)
if (!SelectedOnly || Light->IsSelected()) if (!SelectedOnly || Light->IsSelected())
Light->SaveLDraw(Stream); Light->SaveLDraw(Stream);
@ -436,7 +436,7 @@ int lcModel::SplitMPD(QIODevice& Device)
while (!Device.atEnd()) while (!Device.atEnd())
{ {
qint64 Pos = Device.pos(); const qint64 Pos = Device.pos();
QString OriginalLine = Device.readLine(); QString OriginalLine = Device.readLine();
QString Line = OriginalLine.trimmed(); QString Line = OriginalLine.trimmed();
QTextStream LineStream(&Line, QIODevice::ReadOnly); QTextStream LineStream(&Line, QIODevice::ReadOnly);
@ -487,7 +487,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
while (!Device.atEnd()) while (!Device.atEnd())
{ {
qint64 Pos = Device.pos(); const qint64 Pos = Device.pos();
QString OriginalLine = Device.readLine(); QString OriginalLine = Device.readLine();
QString Line = OriginalLine.trimmed(); QString Line = OriginalLine.trimmed();
QTextStream LineStream(&Line, QIODevice::ReadOnly); QTextStream LineStream(&Line, QIODevice::ReadOnly);
@ -649,9 +649,9 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
PieceInfo* Info = Library->FindPiece(PartId.toLatin1().constData(), Project, true, true); PieceInfo* Info = Library->FindPiece(PartId.toLatin1().constData(), Project, true, true);
float* Matrix = IncludeTransform; const float* Matrix = IncludeTransform;
lcMatrix44 Transform(lcVector4(Matrix[0], Matrix[2], -Matrix[1], 0.0f), lcVector4(Matrix[8], Matrix[10], -Matrix[9], 0.0f), const lcMatrix44 Transform(lcVector4(Matrix[0], Matrix[2], -Matrix[1], 0.0f), lcVector4(Matrix[8], Matrix[10], -Matrix[9], 0.0f),
lcVector4(-Matrix[4], -Matrix[6], Matrix[5], 0.0f), lcVector4(Matrix[12], Matrix[14], -Matrix[13], 1.0f)); lcVector4(-Matrix[4], -Matrix[6], Matrix[5], 0.0f), lcVector4(Matrix[12], Matrix[14], -Matrix[13], 1.0f));
Piece->SetFileLine(mFileLines.size()); Piece->SetFileLine(mFileLines.size());
Piece->SetPieceInfo(Info, PartId, false); Piece->SetPieceInfo(Info, PartId, false);
@ -710,7 +710,7 @@ bool lcModel::LoadBinary(lcFile* file)
if (fv == 0.0f) if (fv == 0.0f)
{ {
lconv *loc = localeconv(); const lconv *loc = localeconv();
id[8] = loc->decimal_point[0]; id[8] = loc->decimal_point[0];
sscanf(&id[7], "%f", &fv); sscanf(&id[7], "%f", &fv);
@ -740,7 +740,7 @@ bool lcModel::LoadBinary(lcFile* file)
file->ReadS32(&count, 1); file->ReadS32(&count, 1);
lcPiecesLibrary* Library = lcGetPiecesLibrary(); lcPiecesLibrary* Library = lcGetPiecesLibrary();
int FirstNewPiece = mPieces.GetSize(); const int FirstNewPiece = mPieces.GetSize();
while (count--) while (count--)
{ {
@ -824,7 +824,7 @@ bool lcModel::LoadBinary(lcFile* file)
if (fv >= 0.5f) if (fv >= 0.5f)
{ {
int NumGroups = mGroups.GetSize(); const int NumGroups = mGroups.GetSize();
file->ReadS32(&count, 1); file->ReadS32(&count, 1);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
@ -1009,7 +1009,7 @@ bool lcModel::LoadInventory(const QByteArray& Inventory)
Value = ((Value < 0.0f) ? floor((Value - 5.0f) / 10.0f) : ceil((Value + 5.0f) / 10.0f)) * 10.0f; Value = ((Value < 0.0f) ? floor((Value - 5.0f) / 10.0f) : ceil((Value + 5.0f) / 10.0f)) * 10.0f;
}; };
const float TargetHeight = 800.0f; constexpr float TargetHeight = 800.0f;
float CurrentX = 0.0f; float CurrentX = 0.0f;
float CurrentY = 0.0f; float CurrentY = 0.0f;
float ColumnWidth = 0.0f; float ColumnWidth = 0.0f;
@ -1022,8 +1022,8 @@ bool lcModel::LoadInventory(const QByteArray& Inventory)
RoundBounds(BoundingBox.Max.x); RoundBounds(BoundingBox.Max.x);
RoundBounds(BoundingBox.Max.y); RoundBounds(BoundingBox.Max.y);
float PieceWidth = BoundingBox.Max.x - BoundingBox.Min.x; const float PieceWidth = BoundingBox.Max.x - BoundingBox.Min.x;
float PieceHeight = BoundingBox.Max.y - BoundingBox.Min.y; const float PieceHeight = BoundingBox.Max.y - BoundingBox.Min.y;
if (CurrentY + PieceHeight > TargetHeight) if (CurrentY + PieceHeight > TargetHeight)
{ {
@ -1170,7 +1170,7 @@ void lcModel::DuplicateSelectedPieces()
while (!GroupName.isEmpty()) while (!GroupName.isEmpty())
{ {
QChar Last = GroupName[GroupName.size() - 1]; const QChar Last = GroupName[GroupName.size() - 1];
if (Last.isDigit()) if (Last.isDigit())
GroupName.chop(1); GroupName.chop(1);
else else
@ -1221,7 +1221,7 @@ void lcModel::PaintSelectedPieces()
SetSelectedPiecesColorIndex(gMainWindow->mColorIndex); SetSelectedPiecesColorIndex(gMainWindow->mColorIndex);
} }
void lcModel::GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const void lcModel::GetScene(lcScene* Scene, const lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const
{ {
if (mPieceInfo) if (mPieceInfo)
mPieceInfo->AddRenderMesh(*Scene); mPieceInfo->AddRenderMesh(*Scene);
@ -1230,18 +1230,18 @@ void lcModel::GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight
{ {
if (Piece->IsVisible(mCurrentStep)) if (Piece->IsVisible(mCurrentStep))
{ {
lcStep StepShow = Piece->GetStepShow(); const lcStep StepShow = Piece->GetStepShow();
Piece->AddMainModelRenderMeshes(Scene, AllowHighlight && StepShow == mCurrentStep, AllowFade && StepShow < mCurrentStep); Piece->AddMainModelRenderMeshes(Scene, AllowHighlight && StepShow == mCurrentStep, AllowFade && StepShow < mCurrentStep);
} }
} }
if (Scene->GetDrawInterface() && !Scene->GetActiveSubmodelInstance()) if (Scene->GetDrawInterface() && !Scene->GetActiveSubmodelInstance())
{ {
for (lcCamera* Camera : mCameras) for (const lcCamera* Camera : mCameras)
if (Camera != ViewCamera && Camera->IsVisible()) if (Camera != ViewCamera && Camera->IsVisible())
Scene->AddInterfaceObject(Camera); Scene->AddInterfaceObject(Camera);
for (lcLight* Light : mLights) for (const lcLight* Light : mLights)
if (Light->IsVisible()) if (Light->IsVisible())
Scene->AddInterfaceObject(Light); Scene->AddInterfaceObject(Light);
} }
@ -1249,14 +1249,14 @@ void lcModel::GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight
void lcModel::AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const void lcModel::AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->IsVisibleInSubModel()) if (Piece->IsVisibleInSubModel())
Piece->AddSubModelRenderMeshes(Scene, WorldMatrix, DefaultColorIndex, RenderMeshState, ParentActive); Piece->AddSubModelRenderMeshes(Scene, WorldMatrix, DefaultColorIndex, RenderMeshState, ParentActive);
} }
QImage lcModel::GetStepImage(bool Zoom, int Width, int Height, lcStep Step) QImage lcModel::GetStepImage(bool Zoom, int Width, int Height, lcStep Step)
{ {
lcView* ActiveView = gMainWindow->GetActiveView(); const lcView* ActiveView = gMainWindow->GetActiveView();
const lcStep CurrentStep = mCurrentStep; const lcStep CurrentStep = mCurrentStep;
lcCamera* Camera = ActiveView->GetCamera(); lcCamera* Camera = ActiveView->GetCamera();
@ -1353,12 +1353,12 @@ QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step, quint32 BackgroundC
float OrthoSize = 200.0f; float OrthoSize = 200.0f;
lcMatrix44 ProjectionMatrix = lcMatrix44Ortho(-OrthoSize, OrthoSize, -OrthoSize, OrthoSize, -5000.0f, 5000.0f); lcMatrix44 ProjectionMatrix = lcMatrix44Ortho(-OrthoSize, OrthoSize, -OrthoSize, OrthoSize, -5000.0f, 5000.0f);
lcMatrix44 ViewMatrix = lcMatrix44LookAt(lcVector3(-100.0f, -100.0f, 75.0f), lcVector3(0.0f, 0.0f, 0.0f), lcVector3(0.0f, 0.0f, 1.0f)); const lcMatrix44 ViewMatrix = lcMatrix44LookAt(lcVector3(-100.0f, -100.0f, 75.0f), lcVector3(0.0f, 0.0f, 0.0f), lcVector3(0.0f, 0.0f, 1.0f));
const int Viewport[4] = { 0, 0, ThumbnailSize, ThumbnailSize }; const int Viewport[4] = { 0, 0, ThumbnailSize, ThumbnailSize };
float ExtraPixels = 0.0f; float ExtraPixels = 0.0f;
for (lcPartsListImage& Image : Images) for (const lcPartsListImage& Image : Images)
{ {
const PieceInfo* Info = Image.Info; const PieceInfo* Info = Image.Info;
const lcBoundingBox& BoundingBox = Info->GetBoundingBox(); const lcBoundingBox& BoundingBox = Info->GetBoundingBox();
@ -1418,9 +1418,9 @@ QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step, quint32 BackgroundC
auto CalculateImageBounds = [](lcPartsListImage& Image) auto CalculateImageBounds = [](lcPartsListImage& Image)
{ {
QImage& Thumbnail = Image.Thumbnail; const QImage& Thumbnail = Image.Thumbnail;
int Width = Thumbnail.width(); const int Width = Thumbnail.width();
int Height = Thumbnail.height(); const int Height = Thumbnail.height();
int MinX = Width; int MinX = Width;
int MinY = Height; int MinY = Height;
@ -1451,12 +1451,12 @@ QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step, quint32 BackgroundC
DummyPainter.setFont(Font); DummyPainter.setFont(Font);
QFontMetrics FontMetrics = DummyPainter.fontMetrics(); QFontMetrics FontMetrics = DummyPainter.fontMetrics();
int Ascent = FontMetrics.ascent(); const int Ascent = FontMetrics.ascent();
int CurrentHeight = 0; int CurrentHeight = 0;
int ImageWidth = MaxWidth; int ImageWidth = MaxWidth;
for (lcPartsListImage& Image : Images) for (const lcPartsListImage& Image : Images)
CurrentHeight = qMax(Image.Bounds.height() + Ascent, CurrentHeight); CurrentHeight = qMax(Image.Bounds.height() + Ascent, CurrentHeight);
for (;;) for (;;)
@ -1465,14 +1465,14 @@ QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step, quint32 BackgroundC
int CurrentX = 0; int CurrentX = 0;
int CurrentY = 0; int CurrentY = 0;
int ColumnWidth = 0; int ColumnWidth = 0;
int Spacing = 20; constexpr int Spacing = 20;
int NextHeightIncrease = INT_MAX; int NextHeightIncrease = INT_MAX;
for (lcPartsListImage& Image : Images) for (lcPartsListImage& Image : Images)
{ {
if (CurrentY + Image.Bounds.height() + Ascent > CurrentHeight) if (CurrentY + Image.Bounds.height() + Ascent > CurrentHeight)
{ {
int NeededSpace = Image.Bounds.height() + Ascent - (CurrentHeight - CurrentY); const int NeededSpace = Image.Bounds.height() + Ascent - (CurrentHeight - CurrentY);
NextHeightIncrease = qMin(NeededSpace, NextHeightIncrease); NextHeightIncrease = qMin(NeededSpace, NextHeightIncrease);
CurrentY = 0; CurrentY = 0;
@ -1502,9 +1502,9 @@ QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step, quint32 BackgroundC
Painter.setFont(Font); Painter.setFont(Font);
Painter.setPen(TextColor); Painter.setPen(TextColor);
for (lcPartsListImage& Image : Images) for (const lcPartsListImage& Image : Images)
{ {
QPoint Position = Image.Position + QPoint(20, 20); const QPoint Position = Image.Position + QPoint(20, 20);
Painter.drawImage(Position, Image.Thumbnail, Image.Bounds); Painter.drawImage(Position, Image.Thumbnail, Image.Bounds);
Painter.drawText(QPoint(Position.x(), Position.y() + Image.Bounds.height() + Ascent), QString::number(Image.Count) + 'x'); Painter.drawText(QPoint(Position.x(), Position.y() + Image.Bounds.height() + Ascent), QString::number(Image.Count) + 'x');
} }
@ -1541,33 +1541,33 @@ void lcModel::SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Z
void lcModel::RayTest(lcObjectRayTest& ObjectRayTest) const void lcModel::RayTest(lcObjectRayTest& ObjectRayTest) const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->IsVisible(mCurrentStep) && (!ObjectRayTest.IgnoreSelected || !Piece->IsSelected())) if (Piece->IsVisible(mCurrentStep) && (!ObjectRayTest.IgnoreSelected || !Piece->IsSelected()))
Piece->RayTest(ObjectRayTest); Piece->RayTest(ObjectRayTest);
if (ObjectRayTest.PiecesOnly) if (ObjectRayTest.PiecesOnly)
return; return;
for (lcCamera* Camera : mCameras) for (const lcCamera* Camera : mCameras)
if (Camera != ObjectRayTest.ViewCamera && Camera->IsVisible() && (!ObjectRayTest.IgnoreSelected || !Camera->IsSelected())) if (Camera != ObjectRayTest.ViewCamera && Camera->IsVisible() && (!ObjectRayTest.IgnoreSelected || !Camera->IsSelected()))
Camera->RayTest(ObjectRayTest); Camera->RayTest(ObjectRayTest);
for (lcLight* Light : mLights) for (const lcLight* Light : mLights)
if (Light->IsVisible() && (!ObjectRayTest.IgnoreSelected || !Light->IsSelected())) if (Light->IsVisible() && (!ObjectRayTest.IgnoreSelected || !Light->IsSelected()))
Light->RayTest(ObjectRayTest); Light->RayTest(ObjectRayTest);
} }
void lcModel::BoxTest(lcObjectBoxTest& ObjectBoxTest) const void lcModel::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->IsVisible(mCurrentStep)) if (Piece->IsVisible(mCurrentStep))
Piece->BoxTest(ObjectBoxTest); Piece->BoxTest(ObjectBoxTest);
for (lcCamera* Camera : mCameras) for (const lcCamera* Camera : mCameras)
if (Camera != ObjectBoxTest.ViewCamera && Camera->IsVisible()) if (Camera != ObjectBoxTest.ViewCamera && Camera->IsVisible())
Camera->BoxTest(ObjectBoxTest); Camera->BoxTest(ObjectBoxTest);
for (lcLight* Light : mLights) for (const lcLight* Light : mLights)
if (Light->IsVisible()) if (Light->IsVisible())
Light->BoxTest(ObjectBoxTest); Light->BoxTest(ObjectBoxTest);
} }
@ -1576,11 +1576,11 @@ bool lcModel::SubModelMinIntersectDist(const lcVector3& WorldStart, const lcVect
{ {
bool MinIntersect = false; bool MinIntersect = false;
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
{ {
lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse(Piece->mModelWorld); const lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse(Piece->mModelWorld);
lcVector3 Start = lcMul31(WorldStart, InverseWorldMatrix); const lcVector3 Start = lcMul31(WorldStart, InverseWorldMatrix);
lcVector3 End = lcMul31(WorldEnd, InverseWorldMatrix); const lcVector3 End = lcMul31(WorldEnd, InverseWorldMatrix);
if (Piece->IsVisibleInSubModel() && Piece->mPieceInfo->MinIntersectDist(Start, End, MinDistance)) // todo: this should check for piece->mMesh first if (Piece->IsVisibleInSubModel() && Piece->mPieceInfo->MinIntersectDist(Start, End, MinDistance)) // todo: this should check for piece->mMesh first
MinIntersect = true; MinIntersect = true;
@ -1591,7 +1591,7 @@ bool lcModel::SubModelMinIntersectDist(const lcVector3& WorldStart, const lcVect
bool lcModel::SubModelBoxTest(const lcVector4 Planes[6]) const bool lcModel::SubModelBoxTest(const lcVector4 Planes[6]) const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->IsVisibleInSubModel() && Piece->mPieceInfo->BoxTest(Piece->mModelWorld, Planes)) if (Piece->IsVisibleInSubModel() && Piece->mPieceInfo->BoxTest(Piece->mModelWorld, Planes))
return true; return true;
@ -1600,14 +1600,14 @@ bool lcModel::SubModelBoxTest(const lcVector4 Planes[6]) const
void lcModel::SubModelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const void lcModel::SubModelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->IsVisibleInSubModel()) if (Piece->IsVisibleInSubModel())
Piece->SubModelCompareBoundingBox(WorldMatrix, Min, Max); Piece->SubModelCompareBoundingBox(WorldMatrix, Min, Max);
} }
void lcModel::SubModelAddBoundingBoxPoints(const lcMatrix44& WorldMatrix, std::vector<lcVector3>& Points) const void lcModel::SubModelAddBoundingBoxPoints(const lcMatrix44& WorldMatrix, std::vector<lcVector3>& Points) const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->IsVisibleInSubModel()) if (Piece->IsVisibleInSubModel())
Piece->SubModelAddBoundingBoxPoints(WorldMatrix, Points); Piece->SubModelAddBoundingBoxPoints(WorldMatrix, Points);
} }
@ -1710,7 +1710,7 @@ void lcModel::ShowFirstStep()
void lcModel::ShowLastStep() void lcModel::ShowLastStep()
{ {
lcStep LastStep = GetLastStep(); const lcStep LastStep = GetLastStep();
if (mCurrentStep == LastStep) if (mCurrentStep == LastStep)
return; return;
@ -1738,7 +1738,7 @@ lcStep lcModel::GetLastStep() const
{ {
lcStep Step = 1; lcStep Step = 1;
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
Step = lcMax(Step, Piece->GetStepShow()); Step = lcMax(Step, Piece->GetStepShow());
return Step; return Step;
@ -1977,10 +1977,10 @@ void lcModel::ShowEditGroupsDialog()
QString lcModel::GetGroupName(const QString& Prefix) QString lcModel::GetGroupName(const QString& Prefix)
{ {
int Length = Prefix.length(); const int Length = Prefix.length();
int Max = 0; int Max = 0;
for (lcGroup* Group : mGroups) for (const lcGroup* Group : mGroups)
{ {
const QString& Name = Group->mName; const QString& Name = Group->mName;
@ -2084,7 +2084,7 @@ lcVector3 lcModel::SnapPosition(const lcVector3& Distance) const
if (SnapZ != 0.0f) if (SnapZ != 0.0f)
{ {
int i = (int)(NewDistance[2] / SnapZ); int i = (int)(NewDistance[2] / SnapZ);
float Leftover = NewDistance[2] - (SnapZ * i); const float Leftover = NewDistance[2] - (SnapZ * i);
if (Leftover > SnapZ / 2) if (Leftover > SnapZ / 2)
i++; i++;
@ -2099,7 +2099,7 @@ lcVector3 lcModel::SnapPosition(const lcVector3& Distance) const
lcVector3 lcModel::SnapRotation(const lcVector3& Angles) const lcVector3 lcModel::SnapRotation(const lcVector3& Angles) const
{ {
float AngleSnap = gMainWindow->GetAngleSnap(); const float AngleSnap = gMainWindow->GetAngleSnap();
lcVector3 NewAngles(Angles); lcVector3 NewAngles(Angles);
if (AngleSnap != 0.0f) if (AngleSnap != 0.0f)
@ -2119,7 +2119,7 @@ lcMatrix33 lcModel::GetRelativeRotation() const
{ {
if (gMainWindow->GetRelativeTransform()) if (gMainWindow->GetRelativeTransform())
{ {
lcObject* Focus = GetFocusObject(); const lcObject* Focus = GetFocusObject();
if (Focus && Focus->IsPiece()) if (Focus && Focus->IsPiece())
return ((lcPiece*)Focus)->GetRelativeRotation(); return ((lcPiece*)Focus)->GetRelativeRotation();
@ -2189,11 +2189,11 @@ void lcModel::AddPiece(lcPiece* Piece)
void lcModel::InsertPiece(lcPiece* Piece, int Index) void lcModel::InsertPiece(lcPiece* Piece, int Index)
{ {
PieceInfo* Info = Piece->mPieceInfo; const PieceInfo* Info = Piece->mPieceInfo;
if (!Info->IsModel()) if (!Info->IsModel())
{ {
lcMesh* Mesh = Info->GetMesh(); const lcMesh* Mesh = Info->GetMesh();
if (Mesh && Mesh->mVertexCacheOffset == -1) if (Mesh && Mesh->mVertexCacheOffset == -1)
lcGetPiecesLibrary()->mBuffersDirty = true; lcGetPiecesLibrary()->mBuffersDirty = true;
@ -2394,7 +2394,7 @@ void lcModel::SetPieceSteps(const QList<QPair<lcPiece*, lcStep>>& PieceSteps)
if (Piece != PieceStep.first || Piece->GetStepShow() != PieceStep.second) if (Piece != PieceStep.first || Piece->GetStepShow() != PieceStep.second)
{ {
Piece = PieceStep.first; Piece = PieceStep.first;
lcStep Step = PieceStep.second; const lcStep Step = PieceStep.second;
mPieces[PieceIdx] = Piece; mPieces[PieceIdx] = Piece;
Piece->SetStepShow(Step); Piece->SetStepShow(Step);
@ -2641,7 +2641,7 @@ void lcModel::MoveSelectedObjects(const lcVector3& PieceDistance, const lcVector
if (ObjectDistance.LengthSquared() >= 0.001f && !AlternateButtonDrag) if (ObjectDistance.LengthSquared() >= 0.001f && !AlternateButtonDrag)
{ {
lcVector3 TransformedObjectDistance = lcMul(ObjectDistance, RelativeRotation); const lcVector3 TransformedObjectDistance = lcMul(ObjectDistance, RelativeRotation);
for (lcCamera* Camera : mCameras) for (lcCamera* Camera : mCameras)
{ {
@ -2742,7 +2742,7 @@ void lcModel::RotateSelectedPieces(const lcVector3& Angles, bool Relative, bool
if (Relative) if (Relative)
{ {
lcMatrix33 RelativeRotation = Piece->GetRelativeRotation(); const lcMatrix33 RelativeRotation = Piece->GetRelativeRotation();
WorldToFocusMatrix = lcMatrix33AffineInverse(RelativeRotation); WorldToFocusMatrix = lcMatrix33AffineInverse(RelativeRotation);
RelativeRotationMatrix = lcMul(RotationMatrix, RelativeRotation); RelativeRotationMatrix = lcMul(RotationMatrix, RelativeRotation);
} }
@ -2778,11 +2778,11 @@ void lcModel::ScaleSelectedPieces(const float Scale, bool Update, bool Checkpoin
return; return;
lcPiece* Piece = (lcPiece*)Focus; lcPiece* Piece = (lcPiece*)Focus;
quint32 Section = Piece->GetFocusSection(); const quint32 Section = Piece->GetFocusSection();
if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST && Section <= LC_PIECE_SECTION_CONTROL_POINT_LAST) if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST && Section <= LC_PIECE_SECTION_CONTROL_POINT_LAST)
{ {
int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST;
Piece->SetControlPointScale(ControlPointIndex, Scale); Piece->SetControlPointScale(ControlPointIndex, Scale);
if (Update) if (Update)
@ -3003,7 +3003,7 @@ void lcModel::SetCameraName(lcCamera* Camera, const QString& Name)
bool lcModel::AnyPiecesSelected() const bool lcModel::AnyPiecesSelected() const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->IsSelected()) if (Piece->IsSelected())
return true; return true;
@ -3012,15 +3012,15 @@ bool lcModel::AnyPiecesSelected() const
bool lcModel::AnyObjectsSelected() const bool lcModel::AnyObjectsSelected() const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->IsSelected()) if (Piece->IsSelected())
return true; return true;
for (lcCamera* Camera : mCameras) for (const lcCamera* Camera : mCameras)
if (Camera->IsSelected()) if (Camera->IsSelected())
return true; return true;
for (lcLight* Light : mLights) for (const lcLight* Light : mLights)
if (Light->IsSelected()) if (Light->IsSelected())
return true; return true;
@ -3046,7 +3046,7 @@ lcObject* lcModel::GetFocusObject() const
lcModel* lcModel::GetFirstSelectedSubmodel() const lcModel* lcModel::GetFirstSelectedSubmodel() const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->IsSelected() && Piece->mPieceInfo->IsModel()) if (Piece->IsSelected() && Piece->mPieceInfo->IsModel())
return Piece->mPieceInfo->GetModel(); return Piece->mPieceInfo->GetModel();
@ -3055,7 +3055,7 @@ lcModel* lcModel::GetFirstSelectedSubmodel() const
void lcModel::GetSubModels(lcArray<lcModel*>& SubModels) const void lcModel::GetSubModels(lcArray<lcModel*>& SubModels) const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
{ {
if (Piece->mPieceInfo->IsModel()) if (Piece->mPieceInfo->IsModel())
{ {
@ -3068,13 +3068,13 @@ void lcModel::GetSubModels(lcArray<lcModel*>& SubModels) const
bool lcModel::GetMoveRotateTransform(lcVector3& Center, lcMatrix33& RelativeRotation) const bool lcModel::GetMoveRotateTransform(lcVector3& Center, lcMatrix33& RelativeRotation) const
{ {
bool Relative = gMainWindow->GetRelativeTransform(); const bool Relative = gMainWindow->GetRelativeTransform();
int NumSelected = 0; int NumSelected = 0;
Center = lcVector3(0.0f, 0.0f, 0.0f); Center = lcVector3(0.0f, 0.0f, 0.0f);
RelativeRotation = lcMatrix33Identity(); RelativeRotation = lcMatrix33Identity();
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
{ {
if (!Piece->IsSelected()) if (!Piece->IsSelected())
continue; continue;
@ -3090,7 +3090,7 @@ bool lcModel::GetMoveRotateTransform(lcVector3& Center, lcMatrix33& RelativeRota
NumSelected++; NumSelected++;
} }
for (lcCamera* Camera : mCameras) for (const lcCamera* Camera : mCameras)
{ {
if (!Camera->IsSelected()) if (!Camera->IsSelected())
continue; continue;
@ -3108,7 +3108,7 @@ bool lcModel::GetMoveRotateTransform(lcVector3& Center, lcMatrix33& RelativeRota
NumSelected += 3; NumSelected += 3;
} }
for (lcLight* Light : mLights) for (const lcLight* Light : mLights)
{ {
if (!Light->IsSelected()) if (!Light->IsSelected())
continue; continue;
@ -3189,7 +3189,7 @@ lcVector3 lcModel::GetSelectionOrModelCenter() const
bool lcModel::GetFocusPosition(lcVector3& Position) const bool lcModel::GetFocusPosition(lcVector3& Position) const
{ {
lcObject* FocusObject = GetFocusObject(); const lcObject* FocusObject = GetFocusObject();
if (FocusObject) if (FocusObject)
{ {
@ -3263,7 +3263,7 @@ lcBoundingBox lcModel::GetAllPiecesBoundingBox() const
Box.Min = lcVector3(FLT_MAX, FLT_MAX, FLT_MAX); Box.Min = lcVector3(FLT_MAX, FLT_MAX, FLT_MAX);
Box.Max = lcVector3(-FLT_MAX, -FLT_MAX, -FLT_MAX); Box.Max = lcVector3(-FLT_MAX, -FLT_MAX, -FLT_MAX);
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
Piece->CompareBoundingBox(Box.Min, Box.Max); Piece->CompareBoundingBox(Box.Min, Box.Max);
} }
else else
@ -3278,7 +3278,7 @@ bool lcModel::GetVisiblePiecesBoundingBox(lcVector3& Min, lcVector3& Max) const
Min = lcVector3(FLT_MAX, FLT_MAX, FLT_MAX); Min = lcVector3(FLT_MAX, FLT_MAX, FLT_MAX);
Max = lcVector3(-FLT_MAX, -FLT_MAX, -FLT_MAX); Max = lcVector3(-FLT_MAX, -FLT_MAX, -FLT_MAX);
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
{ {
if (Piece->IsVisible(mCurrentStep)) if (Piece->IsVisible(mCurrentStep))
{ {
@ -3294,7 +3294,7 @@ std::vector<lcVector3> lcModel::GetPiecesBoundingBoxPoints() const
{ {
std::vector<lcVector3> Points; std::vector<lcVector3> Points;
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
if (Piece->IsVisible(mCurrentStep)) if (Piece->IsVisible(mCurrentStep))
Piece->SubModelAddBoundingBoxPoints(lcMatrix44Identity(), Points); Piece->SubModelAddBoundingBoxPoints(lcMatrix44Identity(), Points);
@ -3303,7 +3303,7 @@ std::vector<lcVector3> lcModel::GetPiecesBoundingBoxPoints() const
void lcModel::GetPartsList(int DefaultColorIndex, bool ScanSubModels, bool AddSubModels, lcPartsList& PartsList) const void lcModel::GetPartsList(int DefaultColorIndex, bool ScanSubModels, bool AddSubModels, lcPartsList& PartsList) const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
{ {
if (!Piece->IsVisibleInSubModel()) if (!Piece->IsVisibleInSubModel())
continue; continue;
@ -3319,7 +3319,7 @@ void lcModel::GetPartsList(int DefaultColorIndex, bool ScanSubModels, bool AddSu
void lcModel::GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcPartsList& PartsList) const void lcModel::GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcPartsList& PartsList) const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
{ {
if (Piece->GetStepShow() != Step || Piece->IsHidden()) if (Piece->GetStepShow() != Step || Piece->IsHidden())
continue; continue;
@ -3335,7 +3335,7 @@ void lcModel::GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcPartsLis
void lcModel::GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector<lcModelPartsEntry>& ModelParts) const void lcModel::GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector<lcModelPartsEntry>& ModelParts) const
{ {
for (lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
Piece->GetModelParts(WorldMatrix, DefaultColorIndex, ModelParts); Piece->GetModelParts(WorldMatrix, DefaultColorIndex, ModelParts);
} }
@ -3432,10 +3432,10 @@ void lcModel::GetSelectionInformation(int* Flags, lcArray<lcObject*>& Selection,
} }
} }
lcArray<lcObject*> lcModel::GetSelectionModePieces(lcPiece* SelectedPiece) const lcArray<lcObject*> lcModel::GetSelectionModePieces(const lcPiece* SelectedPiece) const
{ {
PieceInfo* Info = SelectedPiece->mPieceInfo; const PieceInfo* Info = SelectedPiece->mPieceInfo;
int ColorIndex = SelectedPiece->GetColorIndex(); const int ColorIndex = SelectedPiece->GetColorIndex();
lcArray<lcObject*> Pieces; lcArray<lcObject*> Pieces;
switch (gMainWindow->GetSelectionMode()) switch (gMainWindow->GetSelectionMode())
@ -3497,11 +3497,11 @@ void lcModel::FocusOrDeselectObject(const lcObjectSection& ObjectSection)
{ {
lcObject* FocusObject = GetFocusObject(); lcObject* FocusObject = GetFocusObject();
lcObject* Object = ObjectSection.Object; lcObject* Object = ObjectSection.Object;
quint32 Section = ObjectSection.Section; const quint32 Section = ObjectSection.Section;
if (Object) if (Object)
{ {
bool WasSelected = Object->IsSelected(); const bool WasSelected = Object->IsSelected();
if (!Object->IsFocused(Section)) if (!Object->IsFocused(Section))
{ {
@ -3513,7 +3513,7 @@ void lcModel::FocusOrDeselectObject(const lcObjectSection& ObjectSection)
else else
Object->SetFocused(Section, false); Object->SetFocused(Section, false);
bool IsSelected = Object->IsSelected(); const bool IsSelected = Object->IsSelected();
if (Object->IsPiece() && (WasSelected != IsSelected)) if (Object->IsPiece() && (WasSelected != IsSelected))
{ {
@ -3594,7 +3594,7 @@ void lcModel::AddToSelection(const lcArray<lcObject*>& Objects, bool EnableSelec
{ {
for (lcObject* Object : Objects) for (lcObject* Object : Objects)
{ {
bool WasSelected = Object->IsSelected(); const bool WasSelected = Object->IsSelected();
Object->SetSelected(true); Object->SetSelected(true);
if (Object->IsPiece()) if (Object->IsPiece())
@ -3621,7 +3621,7 @@ void lcModel::RemoveFromSelection(const lcArray<lcObject*>& Objects)
{ {
for (lcObject* SelectedObject : Objects) for (lcObject* SelectedObject : Objects)
{ {
bool WasSelected = SelectedObject->IsSelected(); const bool WasSelected = SelectedObject->IsSelected();
SelectedObject->SetSelected(false); SelectedObject->SetSelected(false);
if (WasSelected && SelectedObject->IsPiece()) if (WasSelected && SelectedObject->IsPiece())
@ -3657,7 +3657,7 @@ void lcModel::RemoveFromSelection(const lcObjectSection& ObjectSection)
if (!SelectedObject) if (!SelectedObject)
return; return;
bool WasSelected = SelectedObject->IsSelected(); const bool WasSelected = SelectedObject->IsSelected();
if (SelectedObject->IsFocused(ObjectSection.Section)) if (SelectedObject->IsFocused(ObjectSection.Section))
SelectedObject->SetSelected(ObjectSection.Section, false); SelectedObject->SetSelected(ObjectSection.Section, false);
@ -4073,8 +4073,8 @@ void lcModel::UpdateCameraTool(const lcVector3& Position)
void lcModel::UpdateMoveTool(const lcVector3& Distance, bool AllowRelative, bool AlternateButtonDrag) void lcModel::UpdateMoveTool(const lcVector3& Distance, bool AllowRelative, bool AlternateButtonDrag)
{ {
lcVector3 PieceDistance = SnapPosition(Distance) - SnapPosition(mMouseToolDistance); const lcVector3 PieceDistance = SnapPosition(Distance) - SnapPosition(mMouseToolDistance);
lcVector3 ObjectDistance = Distance - mMouseToolDistance; const lcVector3 ObjectDistance = Distance - mMouseToolDistance;
MoveSelectedObjects(PieceDistance, ObjectDistance, AllowRelative, AlternateButtonDrag, true, false); MoveSelectedObjects(PieceDistance, ObjectDistance, AllowRelative, AlternateButtonDrag, true, false);
mMouseToolDistance = Distance; mMouseToolDistance = Distance;
@ -4085,7 +4085,7 @@ void lcModel::UpdateMoveTool(const lcVector3& Distance, bool AllowRelative, bool
void lcModel::UpdateRotateTool(const lcVector3& Angles, bool AlternateButtonDrag) void lcModel::UpdateRotateTool(const lcVector3& Angles, bool AlternateButtonDrag)
{ {
lcVector3 Delta = SnapRotation(Angles) - SnapRotation(mMouseToolDistance); const lcVector3 Delta = SnapRotation(Angles) - SnapRotation(mMouseToolDistance);
RotateSelectedPieces(Delta, true, AlternateButtonDrag, false, false); RotateSelectedPieces(Delta, true, AlternateButtonDrag, false, false);
mMouseToolDistance = Angles; mMouseToolDistance = Angles;
@ -4161,12 +4161,12 @@ void lcModel::PaintToolClicked(lcObject* Object)
} }
} }
void lcModel::ColorPickerToolClicked(lcObject* Object) void lcModel::ColorPickerToolClicked(const lcObject* Object)
{ {
if (!Object || !Object->IsPiece()) if (!Object || !Object->IsPiece())
return; return;
lcPiece* Piece = (lcPiece*)Object; const lcPiece* Piece = (lcPiece*)Object;
gMainWindow->SetColorIndex(Piece->GetColorIndex()); gMainWindow->SetColorIndex(Piece->GetColorIndex());
} }
@ -4266,7 +4266,7 @@ void lcModel::ZoomExtents(lcCamera* Camera, float Aspect)
Max = lcMax(Point, Max); Max = lcMax(Point, Max);
} }
lcVector3 Center = (Min + Max) / 2.0f; const lcVector3 Center = (Min + Max) / 2.0f;
Camera->ZoomExtents(Aspect, Center, Points, mCurrentStep, gMainWindow ? gMainWindow->GetAddKeys() : false); Camera->ZoomExtents(Aspect, Center, Points, mCurrentStep, gMainWindow ? gMainWindow->GetAddKeys() : false);
@ -4362,7 +4362,7 @@ void lcModel::ShowArrayDialog()
lcVector3 Position; lcVector3 Position;
lcVector3 RotationAngles = Dialog.mRotations[0] * Step1 + Dialog.mRotations[1] * Step2 + Dialog.mRotations[2] * Step3; lcVector3 RotationAngles = Dialog.mRotations[0] * Step1 + Dialog.mRotations[1] * Step2 + Dialog.mRotations[2] * Step3;
lcVector3 Offset = Dialog.mOffsets[0] * Step1 + Dialog.mOffsets[1] * Step2 + Dialog.mOffsets[2] * Step3; const lcVector3 Offset = Dialog.mOffsets[0] * Step1 + Dialog.mOffsets[1] * Step2 + Dialog.mOffsets[2] * Step3;
for (lcPiece* Piece : mPieces) for (lcPiece* Piece : mPieces)
{ {

View file

@ -80,7 +80,9 @@ public:
~lcModel(); ~lcModel();
lcModel(const lcModel&) = delete; lcModel(const lcModel&) = delete;
lcModel(lcModel&&) = delete;
lcModel& operator=(const lcModel&) = delete; lcModel& operator=(const lcModel&) = delete;
lcModel& operator=(lcModel&&) = delete;
Project* GetProject() const Project* GetProject() const
{ {
@ -229,7 +231,7 @@ public:
void DuplicateSelectedPieces(); void DuplicateSelectedPieces();
void PaintSelectedPieces(); void PaintSelectedPieces();
void GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const; void GetScene(lcScene* Scene, const lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const;
void AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const; void AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
QImage GetStepImage(bool Zoom, int Width, int Height, lcStep Step); QImage GetStepImage(bool Zoom, int Width, int Height, lcStep Step);
QImage GetPartsListImage(int MaxWidth, lcStep Step, quint32 BackgroundColor, QFont Font, QColor TextColor) const; QImage GetPartsListImage(int MaxWidth, lcStep Step, quint32 BackgroundColor, QFont Font, QColor TextColor) const;
@ -264,7 +266,7 @@ public:
void GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcPartsList& PartsList) const; void GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcPartsList& PartsList) const;
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector<lcModelPartsEntry>& ModelParts) const; void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector<lcModelPartsEntry>& ModelParts) const;
void GetSelectionInformation(int* Flags, lcArray<lcObject*>& Selection, lcObject** Focus) const; void GetSelectionInformation(int* Flags, lcArray<lcObject*>& Selection, lcObject** Focus) const;
lcArray<lcObject*> GetSelectionModePieces(lcPiece* SelectedPiece) const; lcArray<lcObject*> GetSelectionModePieces(const lcPiece* SelectedPiece) const;
void FocusOrDeselectObject(const lcObjectSection& ObjectSection); void FocusOrDeselectObject(const lcObjectSection& ObjectSection);
void ClearSelection(bool UpdateInterface); void ClearSelection(bool UpdateInterface);
@ -309,7 +311,7 @@ public:
void UpdateScaleTool(const float Scale); void UpdateScaleTool(const float Scale);
void EraserToolClicked(lcObject* Object); void EraserToolClicked(lcObject* Object);
void PaintToolClicked(lcObject* Object); void PaintToolClicked(lcObject* Object);
void ColorPickerToolClicked(lcObject* Object); void ColorPickerToolClicked(const lcObject* Object);
void UpdateZoomTool(lcCamera* Camera, float Mouse); void UpdateZoomTool(lcCamera* Camera, float Mouse);
void UpdatePanTool(lcCamera* Camera, const lcVector3& Distance); void UpdatePanTool(lcCamera* Camera, const lcVector3& Distance);
void UpdateOrbitTool(lcCamera* Camera, float MouseX, float MouseY); void UpdateOrbitTool(lcCamera* Camera, float MouseX, float MouseY);

View file

@ -366,7 +366,7 @@ void lcPartSelectionListModel::RequestPreview(int InfoIndex)
PieceInfo* Info = mParts[InfoIndex].first; PieceInfo* Info = mParts[InfoIndex].first;
lcGetPiecesLibrary()->LoadPieceInfo(Info, false, false); lcGetPiecesLibrary()->LoadPieceInfo(Info, false, false);
if (Info->mState == LC_PIECEINFO_LOADED) if (Info->mState == lcPieceInfoState::Loaded)
DrawPreview(InfoIndex); DrawPreview(InfoIndex);
else else
mRequestedPreviews.push_back(InfoIndex); mRequestedPreviews.push_back(InfoIndex);

View file

@ -108,7 +108,9 @@ public:
~lcView(); ~lcView();
lcView(const lcView&) = delete; lcView(const lcView&) = delete;
lcView(lcView&&) = delete;
lcView& operator=(const lcView&) = delete; lcView& operator=(const lcView&) = delete;
lcView& operator=(lcView&&) = delete;
static lcFindReplaceParams& GetFindReplaceParams() static lcFindReplaceParams& GetFindReplaceParams()
{ {

View file

@ -60,7 +60,7 @@ lcMatrix44 lcViewSphere::GetProjectionMatrix() const
void lcViewSphere::CreateResources(lcContext* Context) void lcViewSphere::CreateResources(lcContext* Context)
{ {
const int ImageSize = 128; constexpr int ImageSize = 128;
mTexture = new lcTexture(); mTexture = new lcTexture();
const QString ViewNames[6] = const QString ViewNames[6] =
@ -120,7 +120,7 @@ void lcViewSphere::CreateResources(lcContext* Context)
lcMatrix44(lcVector4(1.0f, 0.0f, 0.0f, 0.0f), lcVector4(0.0f, -1.0f, 0.0f, 0.0f), lcVector4(0.0f, 0.0f, 1.0f, 0.0f), lcVector4(0.0f, 0.0f, -1.0f, 1.0f)), lcMatrix44(lcVector4(1.0f, 0.0f, 0.0f, 0.0f), lcVector4(0.0f, -1.0f, 0.0f, 0.0f), lcVector4(0.0f, 0.0f, 1.0f, 0.0f), lcVector4(0.0f, 0.0f, -1.0f, 1.0f)),
}; };
const float Step = 2.0f / mSubdivisions; constexpr float Step = 2.0f / mSubdivisions;
lcVector3* CurVert = Verts; lcVector3* CurVert = Verts;
for (int FaceIdx = 0; FaceIdx < 6; FaceIdx++) for (int FaceIdx = 0; FaceIdx < 6; FaceIdx++)
@ -129,8 +129,8 @@ void lcViewSphere::CreateResources(lcContext* Context)
{ {
for (int x = 0; x <= mSubdivisions; x++) for (int x = 0; x <= mSubdivisions; x++)
{ {
lcVector3 Vert = lcMul31(lcVector3(Step * x - 1.0f, Step * y - 1.0f, 0.0f), Transforms[FaceIdx]); const lcVector3 Vert = lcMul31(lcVector3(Step * x - 1.0f, Step * y - 1.0f, 0.0f), Transforms[FaceIdx]);
lcVector3 Vert2 = Vert * Vert; const lcVector3 Vert2 = Vert * Vert;
*CurVert++ = lcVector3(Vert.x * sqrt(1.0 - 0.5 * (Vert2.y + Vert2.z) + Vert2.y * Vert2.z / 3.0), *CurVert++ = lcVector3(Vert.x * sqrt(1.0 - 0.5 * (Vert2.y + Vert2.z) + Vert2.y * Vert2.z / 3.0),
Vert.y * sqrt(1.0 - 0.5 * (Vert2.z + Vert2.x) + Vert2.z * Vert2.x / 3.0), Vert.y * sqrt(1.0 - 0.5 * (Vert2.z + Vert2.x) + Vert2.z * Vert2.x / 3.0),

View file

@ -64,7 +64,7 @@ bool lcZipFile::OpenWrite(const QString& FileName)
quint64 lcZipFile::SearchCentralDir() quint64 lcZipFile::SearchCentralDir()
{ {
quint64 SizeFile, MaxBack, BackRead, PosFound; quint64 SizeFile, MaxBack, BackRead, PosFound;
const int CommentBufferSize = 1024; constexpr int CommentBufferSize = 1024;
quint8 buf[CommentBufferSize + 4]; quint8 buf[CommentBufferSize + 4];
SizeFile = mFile->GetLength(); SizeFile = mFile->GetLength();

View file

@ -58,7 +58,7 @@ void lcLight::CreateName(const lcArray<lcLight*>& Lights)
{ {
bool Found = false; bool Found = false;
for (lcLight* Light : Lights) for (const lcLight* Light : Lights)
{ {
if (Light->GetName() == mName) if (Light->GetName() == mName)
{ {
@ -74,7 +74,7 @@ void lcLight::CreateName(const lcArray<lcLight*>& Lights)
int MaxLightNumber = 0; int MaxLightNumber = 0;
const QLatin1String Prefix("Light "); const QLatin1String Prefix("Light ");
for (lcLight* Light : Lights) for (const lcLight* Light : Lights)
{ {
QString LightName = Light->GetName(); QString LightName = Light->GetName();
@ -175,7 +175,7 @@ void lcLight::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
for (int PlaneIdx = 0; PlaneIdx < 6; PlaneIdx++) for (int PlaneIdx = 0; PlaneIdx < 6; PlaneIdx++)
{ {
lcVector3 Normal = lcMul30(ObjectBoxTest.Planes[PlaneIdx], mWorldLight); const lcVector3 Normal = lcMul30(ObjectBoxTest.Planes[PlaneIdx], mWorldLight);
LocalPlanes[PlaneIdx] = lcVector4(Normal, ObjectBoxTest.Planes[PlaneIdx][3] - lcDot3(mWorldLight[3], Normal)); LocalPlanes[PlaneIdx] = lcVector4(Normal, ObjectBoxTest.Planes[PlaneIdx][3] - lcDot3(mWorldLight[3], Normal));
} }
@ -193,7 +193,7 @@ void lcLight::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
for (int PlaneIdx = 0; PlaneIdx < 6; PlaneIdx++) for (int PlaneIdx = 0; PlaneIdx < 6; PlaneIdx++)
{ {
lcVector3 Normal = lcMul30(ObjectBoxTest.Planes[PlaneIdx], WorldTarget); const lcVector3 Normal = lcMul30(ObjectBoxTest.Planes[PlaneIdx], WorldTarget);
LocalPlanes[PlaneIdx] = lcVector4(Normal, ObjectBoxTest.Planes[PlaneIdx][3] - lcDot3(WorldTarget[3], Normal)); LocalPlanes[PlaneIdx] = lcVector4(Normal, ObjectBoxTest.Planes[PlaneIdx][3] - lcDot3(WorldTarget[3], Normal));
} }
@ -318,7 +318,7 @@ void lcLight::DrawSpotLight(lcContext* Context) const
LightMatrix = lcMatrix44AffineInverse(LightMatrix); LightMatrix = lcMatrix44AffineInverse(LightMatrix);
LightMatrix.SetTranslation(lcVector3(0, 0, 0)); LightMatrix.SetTranslation(lcVector3(0, 0, 0));
lcMatrix44 LightViewMatrix = lcMul(LightMatrix, lcMatrix44Translation(mPosition)); const lcMatrix44 LightViewMatrix = lcMul(LightMatrix, lcMatrix44Translation(mPosition));
Context->SetWorldMatrix(LightViewMatrix); Context->SetWorldMatrix(LightViewMatrix);
float Verts[(20 + 8 + 2 + 16) * 3]; float Verts[(20 + 8 + 2 + 16) * 3];
@ -375,7 +375,7 @@ void lcLight::DrawSpotLight(lcContext* Context) const
Context->SetVertexFormatPosition(3); Context->SetVertexFormatPosition(3);
Context->SetIndexBufferPointer(Indices); Context->SetIndexBufferPointer(Indices);
float LineWidth = lcGetPreferences().mLineWidth; const float LineWidth = lcGetPreferences().mLineWidth;
if (!IsSelected()) if (!IsSelected())
{ {
@ -436,10 +436,10 @@ void lcLight::DrawSpotLight(lcContext* Context) const
void lcLight::DrawPointLight(lcContext* Context) const void lcLight::DrawPointLight(lcContext* Context) const
{ {
const int Slices = 6; constexpr int Slices = 6;
const int NumIndices = 3 * Slices + 6 * Slices * (Slices - 2) + 3 * Slices; constexpr int NumIndices = 3 * Slices + 6 * Slices * (Slices - 2) + 3 * Slices;
const int NumVertices = (Slices - 1) * Slices + 2; constexpr int NumVertices = (Slices - 1) * Slices + 2;
const float Radius = LC_LIGHT_SPHERE_RADIUS; constexpr float Radius = LC_LIGHT_SPHERE_RADIUS;
lcVector3 Vertices[NumVertices]; lcVector3 Vertices[NumVertices];
quint16 Indices[NumIndices]; quint16 Indices[NumIndices];
@ -450,13 +450,13 @@ void lcLight::DrawPointLight(lcContext* Context) const
for (int i = 1; i < Slices; i++ ) for (int i = 1; i < Slices; i++ )
{ {
float r0 = Radius * sinf(i * (LC_PI / Slices)); const float r0 = Radius * sinf(i * (LC_PI / Slices));
float z0 = Radius * cosf(i * (LC_PI / Slices)); const float z0 = Radius * cosf(i * (LC_PI / Slices));
for (int j = 0; j < Slices; j++) for (int j = 0; j < Slices; j++)
{ {
float x0 = r0 * sinf(j * (LC_2PI / Slices)); const float x0 = r0 * sinf(j * (LC_2PI / Slices));
float y0 = r0 * cosf(j * (LC_2PI / Slices)); const float y0 = r0 * cosf(j * (LC_2PI / Slices));
*Vertex++ = lcVector3(x0, y0, z0); *Vertex++ = lcVector3(x0, y0, z0);
} }

View file

@ -53,7 +53,9 @@ public:
~MinifigWizard(); ~MinifigWizard();
MinifigWizard(const MinifigWizard&) = delete; MinifigWizard(const MinifigWizard&) = delete;
MinifigWizard(MinifigWizard&&) = delete;
MinifigWizard& operator=(const MinifigWizard&) = delete; MinifigWizard& operator=(const MinifigWizard&) = delete;
MinifigWizard& operator=(MinifigWizard&&) = delete;
lcModel* GetModel() const lcModel* GetModel() const
{ {

View file

@ -41,7 +41,7 @@ template void lcObjectKeyArray<lcMatrix33>::RemoveTime(lcStep Start, lcStep Time
template<typename T> template<typename T>
void lcObjectKeyArray<T>::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const void lcObjectKeyArray<T>::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const
{ {
const int Count = sizeof(T) / sizeof(float); constexpr int Count = sizeof(T) / sizeof(float);
for (const lcObjectKey<T>& Key : mKeys) for (const lcObjectKey<T>& Key : mKeys)
{ {
@ -60,10 +60,10 @@ void lcObjectKeyArray<T>::LoadKeysLDraw(QTextStream& Stream)
QString Token; QString Token;
Stream >> Token; Stream >> Token;
int Step = Token.toInt(); const int Step = Token.toInt();
T Value; T Value;
const int Count = sizeof(T) / sizeof(float); constexpr int Count = sizeof(T) / sizeof(float);
for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++) for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++)
Stream >> ((float*)&Value)[ValueIdx]; Stream >> ((float*)&Value)[ValueIdx];

View file

@ -88,7 +88,9 @@ public:
virtual ~lcObject(); virtual ~lcObject();
lcObject(const lcObject&) = delete; lcObject(const lcObject&) = delete;
lcObject(lcObject&&) = delete;
lcObject& operator=(const lcObject&) = delete; lcObject& operator=(const lcObject&) = delete;
lcObject& operator=(lcObject&&) = delete;
public: public:
bool IsPiece() const bool IsPiece() const

View file

@ -15,7 +15,7 @@
#include "lc_qutils.h" #include "lc_qutils.h"
#include "lc_synth.h" #include "lc_synth.h"
#define LC_PIECE_CONTROL_POINT_SIZE 10.0f constexpr float LC_PIECE_CONTROL_POINT_SIZE = 10.0f;
lcPiece::lcPiece(PieceInfo* Info) lcPiece::lcPiece(PieceInfo* Info)
: lcObject(lcObjectType::Piece) : lcObject(lcObjectType::Piece)
@ -87,7 +87,7 @@ void lcPiece::SetPieceInfo(PieceInfo* Info, const QString& ID, bool Wait)
delete mMesh; delete mMesh;
mMesh = nullptr; mMesh = nullptr;
lcSynthInfo* SynthInfo = mPieceInfo ? mPieceInfo->GetSynthInfo() : nullptr; const lcSynthInfo* SynthInfo = mPieceInfo ? mPieceInfo->GetSynthInfo() : nullptr;
if (SynthInfo) if (SynthInfo)
{ {
@ -103,7 +103,7 @@ void lcPiece::UpdateID()
void lcPiece::SaveLDraw(QTextStream& Stream) const void lcPiece::SaveLDraw(QTextStream& Stream) const
{ {
QLatin1String LineEnding("\r\n"); const QLatin1String LineEnding("\r\n");
if (mStepHide != LC_STEP_MAX) if (mStepHide != LC_STEP_MAX)
Stream << QLatin1String("0 !LEOCAD PIECE STEP_HIDE ") << mStepHide << LineEnding; Stream << QLatin1String("0 !LEOCAD PIECE STEP_HIDE ") << mStepHide << LineEnding;
@ -114,7 +114,7 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const
if (mPivotPointValid) if (mPivotPointValid)
{ {
const float* PivotMatrix = mPivotMatrix; const float* PivotMatrix = mPivotMatrix;
float PivotNumbers[12] = { PivotMatrix[12], -PivotMatrix[14], PivotMatrix[13], PivotMatrix[0], -PivotMatrix[8], PivotMatrix[4], -PivotMatrix[2], PivotMatrix[10], -PivotMatrix[6], PivotMatrix[1], -PivotMatrix[9], PivotMatrix[5] }; const float PivotNumbers[12] = { PivotMatrix[12], -PivotMatrix[14], PivotMatrix[13], PivotMatrix[0], -PivotMatrix[8], PivotMatrix[4], -PivotMatrix[2], PivotMatrix[10], -PivotMatrix[6], PivotMatrix[1], -PivotMatrix[9], PivotMatrix[5] };
Stream << QLatin1String("0 !LEOCAD PIECE PIVOT "); Stream << QLatin1String("0 !LEOCAD PIECE PIVOT ");
@ -133,7 +133,7 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const
Stream << "1 " << mColorCode << ' '; Stream << "1 " << mColorCode << ' ';
const float* Matrix = mModelWorld; const float* Matrix = mModelWorld;
float Numbers[12] = { Matrix[12], -Matrix[14], Matrix[13], Matrix[0], -Matrix[8], Matrix[4], -Matrix[2], Matrix[10], -Matrix[6], Matrix[1], -Matrix[9], Matrix[5] }; const float Numbers[12] = { Matrix[12], -Matrix[14], Matrix[13], Matrix[0], -Matrix[8], Matrix[4], -Matrix[2], Matrix[10], -Matrix[6], Matrix[1], -Matrix[9], Matrix[5] };
for (int NumberIdx = 0; NumberIdx < 12; NumberIdx++) for (int NumberIdx = 0; NumberIdx < 12; NumberIdx++)
Stream << lcFormatValue(Numbers[NumberIdx], NumberIdx < 3 ? 4 : 6) << ' '; Stream << lcFormatValue(Numbers[NumberIdx], NumberIdx < 3 ? 4 : 6) << ' ';
@ -158,8 +158,8 @@ bool lcPiece::ParseLDrawLine(QTextStream& Stream)
for (int TokenIdx = 0; TokenIdx < 12; TokenIdx++) for (int TokenIdx = 0; TokenIdx < 12; TokenIdx++)
Stream >> PivotNumbers[TokenIdx]; Stream >> PivotNumbers[TokenIdx];
lcMatrix44 PivotMatrix(lcVector4( PivotNumbers[3], PivotNumbers[9], -PivotNumbers[6], 0.0f), lcVector4(PivotNumbers[5], PivotNumbers[11], -PivotNumbers[8], 0.0f), const lcMatrix44 PivotMatrix(lcVector4( PivotNumbers[3], PivotNumbers[9], -PivotNumbers[6], 0.0f), lcVector4(PivotNumbers[5], PivotNumbers[11], -PivotNumbers[8], 0.0f),
lcVector4(-PivotNumbers[4], -PivotNumbers[10], PivotNumbers[7], 0.0f), lcVector4(PivotNumbers[0], PivotNumbers[2], -PivotNumbers[1], 1.0f)); lcVector4(-PivotNumbers[4], -PivotNumbers[10], PivotNumbers[7], 0.0f), lcVector4(PivotNumbers[0], PivotNumbers[2], -PivotNumbers[1], 1.0f));
mPivotMatrix = PivotMatrix; mPivotMatrix = PivotMatrix;
mPivotPointValid = true; mPivotPointValid = true;
@ -463,9 +463,9 @@ void lcPiece::RemoveTime(lcStep Start, lcStep Time)
void lcPiece::RayTest(lcObjectRayTest& ObjectRayTest) const void lcPiece::RayTest(lcObjectRayTest& ObjectRayTest) const
{ {
lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse(mModelWorld); const lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse(mModelWorld);
lcVector3 Start = lcMul31(ObjectRayTest.Start, InverseWorldMatrix); const lcVector3 Start = lcMul31(ObjectRayTest.Start, InverseWorldMatrix);
lcVector3 End = lcMul31(ObjectRayTest.End, InverseWorldMatrix); const lcVector3 End = lcMul31(ObjectRayTest.End, InverseWorldMatrix);
if (mMesh) if (mMesh)
{ {
@ -483,14 +483,14 @@ void lcPiece::RayTest(lcObjectRayTest& ObjectRayTest) const
if (AreControlPointsVisible()) if (AreControlPointsVisible())
{ {
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);
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 (int ControlPointIdx = 0; ControlPointIdx < mControlPoints.GetSize(); ControlPointIdx++)
{ {
lcMatrix44 InverseTransform = lcMatrix44AffineInverse(mControlPoints[ControlPointIdx].Transform); const lcMatrix44 InverseTransform = lcMatrix44AffineInverse(mControlPoints[ControlPointIdx].Transform);
lcVector3 PointStart = lcMul31(Start, InverseTransform); const lcVector3 PointStart = lcMul31(Start, InverseTransform);
lcVector3 PointEnd = lcMul31(End, InverseTransform); const lcVector3 PointEnd = lcMul31(End, InverseTransform);
float Distance; float Distance;
if (!lcBoundingBoxRayIntersectDistance(Min, Max, PointStart, PointEnd, &Distance, nullptr) || (Distance >= ObjectRayTest.Distance)) if (!lcBoundingBoxRayIntersectDistance(Min, Max, PointStart, PointEnd, &Distance, nullptr) || (Distance >= ObjectRayTest.Distance))
@ -511,7 +511,7 @@ void lcPiece::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const
{ {
float LineWidth = lcGetPreferences().mLineWidth; const float LineWidth = lcGetPreferences().mLineWidth;
Context->SetLineWidth(2.0f * LineWidth); Context->SetLineWidth(2.0f * LineWidth);
const lcBoundingBox& BoundingBox = GetBoundingBox(); const lcBoundingBox& BoundingBox = GetBoundingBox();
@ -554,7 +554,7 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const
{ Min[0], Min[1], Min[2] }, { Min[0], Min[1], Min[2] + Edge[2] }, { Min[0], Min[1], Min[2] }, { Min[0], Min[1], Min[2] + Edge[2] },
}; };
lcMatrix44 WorldMatrix = Scene.ApplyActiveSubmodelTransform(mModelWorld); const lcMatrix44 WorldMatrix = Scene.ApplyActiveSubmodelTransform(mModelWorld);
Context->SetMaterial(lcMaterialType::UnlitColor); Context->SetMaterial(lcMaterialType::UnlitColor);
Context->SetWorldMatrix(WorldMatrix); Context->SetWorldMatrix(WorldMatrix);
@ -570,8 +570,8 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const
if (IsPivotPointVisible()) if (IsPivotPointVisible())
{ {
const float Size = 5.0f; constexpr float Size = 5.0f;
const float Verts[8 * 3] = constexpr float Verts[8 * 3] =
{ {
-Size, -Size, -Size, -Size, Size, -Size, Size, Size, -Size, Size, -Size, -Size, -Size, -Size, -Size, -Size, Size, -Size, Size, Size, -Size, Size, -Size, -Size,
-Size, -Size, Size, -Size, Size, Size, Size, Size, Size, Size, -Size, Size -Size, -Size, Size, -Size, Size, Size, Size, Size, Size, Size, -Size, Size
@ -660,7 +660,7 @@ void lcPiece::AddMainModelRenderMeshes(lcScene* Scene, bool Highlight, bool Fade
if (Scene->GetDrawInterface()) if (Scene->GetDrawInterface())
{ {
lcPiece* ActiveSubmodelInstance = Scene->GetActiveSubmodelInstance(); const lcPiece* ActiveSubmodelInstance = Scene->GetActiveSubmodelInstance();
if (!ActiveSubmodelInstance) if (!ActiveSubmodelInstance)
RenderMeshState = IsFocused() ? lcRenderMeshState::Focused : (IsSelected() ? lcRenderMeshState::Selected : RenderMeshState); RenderMeshState = IsFocused() ? lcRenderMeshState::Focused : (IsSelected() ? lcRenderMeshState::Selected : RenderMeshState);
@ -686,7 +686,7 @@ void lcPiece::AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMat
if (ColorIndex == gDefaultColor) if (ColorIndex == gDefaultColor)
ColorIndex = DefaultColorIndex; ColorIndex = DefaultColorIndex;
lcPiece* ActiveSubmodelInstance = Scene->GetActiveSubmodelInstance(); const lcPiece* ActiveSubmodelInstance = Scene->GetActiveSubmodelInstance();
if (ActiveSubmodelInstance == this) if (ActiveSubmodelInstance == this)
RenderMeshState = lcRenderMeshState::Default; RenderMeshState = lcRenderMeshState::Default;
@ -724,11 +724,11 @@ void lcPiece::SubModelAddBoundingBoxPoints(const lcMatrix44& WorldMatrix, std::v
void lcPiece::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance) void lcPiece::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance)
{ {
quint32 Section = GetFocusSection(); const quint32 Section = GetFocusSection();
if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID) if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID)
{ {
lcVector3 Position = mModelWorld.GetTranslation() + Distance; const lcVector3 Position = mModelWorld.GetTranslation() + Distance;
SetPosition(Position, Step, AddKey); SetPosition(Position, Step, AddKey);
@ -736,11 +736,11 @@ void lcPiece::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance)
} }
else else
{ {
int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST;
if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize())
{ {
lcMatrix33 InverseWorldMatrix = lcMatrix33AffineInverse(lcMatrix33(mModelWorld)); const lcMatrix33 InverseWorldMatrix = lcMatrix33AffineInverse(lcMatrix33(mModelWorld));
lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform;
Transform.SetTranslation(Transform.GetTranslation() + lcMul(Distance, InverseWorldMatrix)); Transform.SetTranslation(Transform.GetTranslation() + lcMul(Distance, InverseWorldMatrix));
@ -752,17 +752,17 @@ void lcPiece::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance)
void lcPiece::Rotate(lcStep Step, bool AddKey, const lcMatrix33& RotationMatrix, const lcVector3& Center, const lcMatrix33& RotationFrame) void lcPiece::Rotate(lcStep Step, bool AddKey, const lcMatrix33& RotationMatrix, const lcVector3& Center, const lcMatrix33& RotationFrame)
{ {
quint32 Section = GetFocusSection(); const quint32 Section = GetFocusSection();
if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID) if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID)
{ {
lcVector3 Distance = mModelWorld.GetTranslation() - Center; lcVector3 Distance = mModelWorld.GetTranslation() - Center;
lcMatrix33 LocalToWorldMatrix = lcMatrix33(mModelWorld); const lcMatrix33 LocalToWorldMatrix = lcMatrix33(mModelWorld);
lcMatrix33 LocalToFocusMatrix = lcMul(LocalToWorldMatrix, RotationFrame); const lcMatrix33 LocalToFocusMatrix = lcMul(LocalToWorldMatrix, RotationFrame);
lcMatrix33 NewLocalToWorldMatrix = lcMul(LocalToFocusMatrix, RotationMatrix); lcMatrix33 NewLocalToWorldMatrix = lcMul(LocalToFocusMatrix, RotationMatrix);
lcMatrix33 WorldToLocalMatrix = lcMatrix33AffineInverse(LocalToWorldMatrix); const lcMatrix33 WorldToLocalMatrix = lcMatrix33AffineInverse(LocalToWorldMatrix);
Distance = lcMul(Distance, WorldToLocalMatrix); Distance = lcMul(Distance, WorldToLocalMatrix);
Distance = lcMul(Distance, NewLocalToWorldMatrix); Distance = lcMul(Distance, NewLocalToWorldMatrix);
@ -774,15 +774,15 @@ void lcPiece::Rotate(lcStep Step, bool AddKey, const lcMatrix33& RotationMatrix,
} }
else else
{ {
int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST;
if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize())
{ {
lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform;
lcMatrix33 PieceWorldMatrix(mModelWorld); const lcMatrix33 PieceWorldMatrix(mModelWorld);
lcMatrix33 LocalToWorldMatrix = lcMul(lcMatrix33(Transform), PieceWorldMatrix); const lcMatrix33 LocalToWorldMatrix = lcMul(lcMatrix33(Transform), PieceWorldMatrix);
lcMatrix33 LocalToFocusMatrix = lcMul(LocalToWorldMatrix, RotationFrame); const lcMatrix33 LocalToFocusMatrix = lcMul(LocalToWorldMatrix, RotationFrame);
lcMatrix33 NewLocalToWorldMatrix = lcMul(lcMul(LocalToFocusMatrix, RotationMatrix), lcMatrix33AffineInverse(PieceWorldMatrix)); lcMatrix33 NewLocalToWorldMatrix = lcMul(lcMul(LocalToFocusMatrix, RotationMatrix), lcMatrix33AffineInverse(PieceWorldMatrix));
NewLocalToWorldMatrix.Orthonormalize(); NewLocalToWorldMatrix.Orthonormalize();
@ -816,14 +816,15 @@ void lcPiece::RotatePivotPoint(const lcMatrix33& RotationMatrix)
quint32 lcPiece::GetAllowedTransforms() const quint32 lcPiece::GetAllowedTransforms() const
{ {
const quint32 Move = LC_OBJECT_TRANSFORM_MOVE_X | LC_OBJECT_TRANSFORM_MOVE_Y | LC_OBJECT_TRANSFORM_MOVE_Z; constexpr quint32 Move = LC_OBJECT_TRANSFORM_MOVE_X | LC_OBJECT_TRANSFORM_MOVE_Y | LC_OBJECT_TRANSFORM_MOVE_Z;
const quint32 Rotate = LC_OBJECT_TRANSFORM_ROTATE_X | LC_OBJECT_TRANSFORM_ROTATE_Y | LC_OBJECT_TRANSFORM_ROTATE_Z; constexpr quint32 Rotate = LC_OBJECT_TRANSFORM_ROTATE_X | LC_OBJECT_TRANSFORM_ROTATE_Y | LC_OBJECT_TRANSFORM_ROTATE_Z;
quint32 Section = GetFocusSection(); const quint32 Section = GetFocusSection();
if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID) if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID)
return Move | Rotate; return Move | Rotate;
lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo(); const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo();
if (SynthInfo) if (SynthInfo)
{ {
if (SynthInfo->IsUnidirectional()) if (SynthInfo->IsUnidirectional())
@ -844,13 +845,13 @@ bool lcPiece::CanAddControlPoint() const
if (mControlPoints.GetSize() >= LC_MAX_CONTROL_POINTS) if (mControlPoints.GetSize() >= LC_MAX_CONTROL_POINTS)
return false; return false;
lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo(); const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo();
return SynthInfo && SynthInfo->CanAddControlPoints(); return SynthInfo && SynthInfo->CanAddControlPoints();
} }
bool lcPiece::CanRemoveControlPoint() const bool lcPiece::CanRemoveControlPoint() 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.GetSize() > 2;
} }
@ -859,12 +860,12 @@ bool lcPiece::InsertControlPoint(const lcVector3& WorldStart, const lcVector3& W
if (!CanAddControlPoint()) if (!CanAddControlPoint())
return false; return false;
lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse(mModelWorld); const lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse(mModelWorld);
lcVector3 Start = lcMul31(WorldStart, InverseWorldMatrix); const lcVector3 Start = lcMul31(WorldStart, InverseWorldMatrix);
lcVector3 End = lcMul31(WorldEnd, InverseWorldMatrix); const lcVector3 End = lcMul31(WorldEnd, InverseWorldMatrix);
lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo(); const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo();
int ControlPointIndex = SynthInfo->InsertControlPoint(mControlPoints, Start, End); const int ControlPointIndex = SynthInfo->InsertControlPoint(mControlPoints, Start, End);
if (ControlPointIndex) if (ControlPointIndex)
{ {
@ -879,7 +880,7 @@ bool lcPiece::InsertControlPoint(const lcVector3& WorldStart, const lcVector3& W
bool lcPiece::RemoveFocusedControlPoint() bool lcPiece::RemoveFocusedControlPoint()
{ {
int ControlPointIndex = GetFocusSection() - LC_PIECE_SECTION_CONTROL_POINT_FIRST; const int ControlPointIndex = GetFocusSection() - LC_PIECE_SECTION_CONTROL_POINT_FIRST;
if (ControlPointIndex < 0 || ControlPointIndex >= mControlPoints.GetSize() || mControlPoints.GetSize() <= 2) if (ControlPointIndex < 0 || ControlPointIndex >= mControlPoints.GetSize() || mControlPoints.GetSize() <= 2)
return false; return false;
@ -895,7 +896,8 @@ bool lcPiece::RemoveFocusedControlPoint()
void lcPiece::VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const void lcPiece::VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) const
{ {
lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo(); const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo();
if (!SynthInfo) if (!SynthInfo)
{ {
ControlPoints.RemoveAll(); ControlPoints.RemoveAll();
@ -960,7 +962,7 @@ void lcPiece::CompareBoundingBox(lcVector3& Min, lcVector3& Max) const
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
lcVector3 Point = lcMul31(Points[i], mModelWorld); const lcVector3 Point = lcMul31(Points[i], mModelWorld);
Min = lcMin(Point, Min); Min = lcMin(Point, Min);
Max = lcMax(Point, Max); Max = lcMax(Point, Max);
@ -975,8 +977,8 @@ lcGroup* lcPiece::GetTopGroup()
void lcPiece::UpdatePosition(lcStep Step) void lcPiece::UpdatePosition(lcStep Step)
{ {
lcVector3 Position = mPositionKeys.CalculateKey(Step); const lcVector3 Position = mPositionKeys.CalculateKey(Step);
lcMatrix33 Rotation = mRotationKeys.CalculateKey(Step); const lcMatrix33 Rotation = mRotationKeys.CalculateKey(Step);
mModelWorld = lcMatrix44(Rotation, Position); mModelWorld = lcMatrix44(Rotation, Position);
} }
@ -984,6 +986,6 @@ void lcPiece::UpdatePosition(lcStep Step)
void lcPiece::UpdateMesh() void lcPiece::UpdateMesh()
{ {
delete mMesh; delete mMesh;
lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo(); const lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo();
mMesh = SynthInfo ? SynthInfo->CreateMesh(mControlPoints) : nullptr; mMesh = SynthInfo ? SynthInfo->CreateMesh(mControlPoints) : nullptr;
} }

View file

@ -18,20 +18,24 @@ PieceInfo::PieceInfo()
{ {
mZipFileType = lcZipFileType::Count; mZipFileType = lcZipFileType::Count;
mZipFileIndex = -1; mZipFileIndex = -1;
mState = LC_PIECEINFO_UNLOADED; mFolderType = -1;
mFolderIndex = -1;
mState = lcPieceInfoState::Unloaded;
mRefCount = 0; mRefCount = 0;
mType = lcPieceInfoType::Part; mType = lcPieceInfoType::Part;
mMesh = nullptr; mMesh = nullptr;
mModel = nullptr; mModel = nullptr;
mProject = nullptr; mProject = nullptr;
mSynthInfo = nullptr; mSynthInfo = nullptr;
mFileName[0] = 0;
m_strDescription[0] = 0;
} }
PieceInfo::~PieceInfo() PieceInfo::~PieceInfo()
{ {
delete mSynthInfo; delete mSynthInfo;
if (mState == LC_PIECEINFO_LOADED) if (mState == lcPieceInfoState::Loaded)
Unload(); Unload();
} }
@ -99,7 +103,7 @@ void PieceInfo::CreateProject(Project* Project, const char* PieceName)
{ {
mType = lcPieceInfoType::Project; mType = lcPieceInfoType::Project;
mProject = Project; mProject = Project;
mState = LC_PIECEINFO_LOADED; mState = lcPieceInfoState::Loaded;
} }
strncpy(mFileName, PieceName, sizeof(mFileName) - 1); strncpy(mFileName, PieceName, sizeof(mFileName) - 1);
@ -143,7 +147,7 @@ void PieceInfo::Load()
{ {
if (!IsModel() && !IsProject()) if (!IsModel() && !IsProject())
{ {
mState = LC_PIECEINFO_LOADING; // todo: mutex lock when changing load state mState = lcPieceInfoState::Loading; // todo: mutex lock when changing load state
if (IsPlaceholder()) if (IsPlaceholder())
{ {
@ -154,7 +158,7 @@ void PieceInfo::Load()
lcGetPiecesLibrary()->LoadPieceData(this); lcGetPiecesLibrary()->LoadPieceData(this);
} }
mState = LC_PIECEINFO_LOADED; mState = lcPieceInfoState::Loaded;
} }
void PieceInfo::ReleaseMesh() void PieceInfo::ReleaseMesh()
@ -180,7 +184,7 @@ void PieceInfo::ReleaseMesh()
void PieceInfo::Unload() void PieceInfo::Unload()
{ {
ReleaseMesh(); ReleaseMesh();
mState = LC_PIECEINFO_UNLOADED; mState = lcPieceInfoState::Unloaded;
mModel = nullptr; mModel = nullptr;
if (IsModel()) if (IsModel())
@ -368,7 +372,7 @@ void PieceInfo::CompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
lcVector3 Point = lcMul31(Points[i], WorldMatrix); const lcVector3 Point = lcMul31(Points[i], WorldMatrix);
Min = lcMin(Point, Min); Min = lcMin(Point, Min);
Max = lcMax(Point, Max); Max = lcMax(Point, Max);

View file

@ -14,11 +14,11 @@ enum class lcPieceInfoType
#define LC_PIECE_NAME_LEN 256 #define LC_PIECE_NAME_LEN 256
enum lcPieceInfoState enum class lcPieceInfoState
{ {
LC_PIECEINFO_UNLOADED, Unloaded,
LC_PIECEINFO_LOADING, Loading,
LC_PIECEINFO_LOADED Loaded
}; };
struct lcModelPartsEntry struct lcModelPartsEntry

View file

@ -35,7 +35,9 @@ public:
~Project(); ~Project();
Project(const Project&) = delete; Project(const Project&) = delete;
Project(Project&&) = delete;
Project& operator=(const Project&) = delete; Project& operator=(const Project&) = delete;
Project& operator=(Project&&) = delete;
const lcArray<lcModel*>& GetModels() const const lcArray<lcModel*>& GetModels() const
{ {

View file

@ -115,7 +115,7 @@ bool TexFont::Initialize(lcContext* Context)
unsigned char ExpandedData[sizeof(TextureData) * 8 * 2]; unsigned char ExpandedData[sizeof(TextureData) * 8 * 2];
for (unsigned int TexelIdx = 0; TexelIdx < sizeof(TextureData) * 8; TexelIdx++) for (unsigned int TexelIdx = 0; TexelIdx < sizeof(TextureData) * 8; TexelIdx++)
{ {
unsigned char Texel = TextureData[TexelIdx / 8] & (1 << (TexelIdx % 8)) ? 255 : 0; const unsigned char Texel = TextureData[TexelIdx / 8] & (1 << (TexelIdx % 8)) ? 255 : 0;
ExpandedData[TexelIdx * 2] = ExpandedData[TexelIdx * 2 + 1] = Texel; ExpandedData[TexelIdx * 2] = ExpandedData[TexelIdx * 2 + 1] = Texel;
} }
@ -167,7 +167,7 @@ void TexFont::GetStringDimensions(int* cx, int* cy, const char* Text) const
void TexFont::PrintText(lcContext* Context, float Left, float Top, float Z, const char* Text) const void TexFont::PrintText(lcContext* Context, float Left, float Top, float Z, const char* Text) const
{ {
size_t Length = strlen(Text); const size_t Length = strlen(Text);
if (!Length) if (!Length)
return; return;
@ -233,13 +233,13 @@ void TexFont::GetTriangles(const lcMatrix44& Transform, const char* Text, float*
for (const char* ch = Text; *ch; ch++) for (const char* ch = Text; *ch; ch++)
{ {
int Glyph = *ch; const int Glyph = *ch;
Width += mGlyphs[Glyph].width; Width += mGlyphs[Glyph].width;
} }
float Left = -Width / 2.0f; float Left = -Width / 2.0f;
float Top = mFontHeight / 2.0f; const float Top = mFontHeight / 2.0f;
float Z = 0.0f; const float Z = 0.0f;
while (*Text) while (*Text)
{ {

View file

@ -7,7 +7,7 @@
QString lcFormatValue(float Value, int Precision) QString lcFormatValue(float Value, int Precision)
{ {
QString String = QString::number(Value, 'f', Precision); QString String = QString::number(Value, 'f', Precision);
int Dot = String.indexOf('.'); const int Dot = String.indexOf('.');
if (Dot != -1) if (Dot != -1)
{ {
@ -54,33 +54,33 @@ lcQTreeWidgetColumnStretcher::lcQTreeWidgetColumnStretcher(QTreeWidget *treeWidg
lcQTreeWidgetColumnStretcher::eventFilter(parent(), &fake); lcQTreeWidgetColumnStretcher::eventFilter(parent(), &fake);
} }
bool lcQTreeWidgetColumnStretcher::eventFilter(QObject *obj, QEvent *ev) bool lcQTreeWidgetColumnStretcher::eventFilter(QObject* Object, QEvent* Event)
{ {
if (obj == parent()) if (Object == parent())
{ {
if (ev->type() == QEvent::Show) if (Event->type() == QEvent::Show)
{ {
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(obj); QHeaderView* HeaderView = qobject_cast<QHeaderView*>(Object);
for (int i = 0; i < HeaderView->count(); ++i) for (int i = 0; i < HeaderView->count(); ++i)
HeaderView->setSectionResizeMode(i, QHeaderView::Interactive); HeaderView->setSectionResizeMode(i, QHeaderView::Interactive);
} }
else if (ev->type() == QEvent::Hide) else if (Event->type() == QEvent::Hide)
{ {
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(obj); QHeaderView* HeaderView = qobject_cast<QHeaderView*>(Object);
for (int i = 0; i < HeaderView->count(); ++i) for (int i = 0; i < HeaderView->count(); ++i)
HeaderView->setSectionResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents); HeaderView->setSectionResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents);
} }
else if (ev->type() == QEvent::Resize) else if (Event->type() == QEvent::Resize)
{ {
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(obj); QHeaderView* HeaderView = qobject_cast<QHeaderView*>(Object);
if (HeaderView->sectionResizeMode(m_columnToStretch) == QHeaderView::Interactive) if (HeaderView->sectionResizeMode(m_columnToStretch) == QHeaderView::Interactive)
{ {
QResizeEvent *re = static_cast<QResizeEvent*>(ev); const QResizeEvent* ResizeEvent = reinterpret_cast<QResizeEvent*>(Event);
int diff = re->size().width() - re->oldSize().width() ; const int Diff = ResizeEvent->size().width() - ResizeEvent->oldSize().width() ;
HeaderView->resizeSection(m_columnToStretch, qMax(32, HeaderView->sectionSize(1) + diff)); HeaderView->resizeSection(m_columnToStretch, qMax(32, HeaderView->sectionSize(1) + Diff));
} }
} }
} }

View file

@ -28,9 +28,9 @@ public:
QFontMetrics FontMetrics(font()); QFontMetrics FontMetrics(font());
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int Width = FontMetrics.horizontalAdvance(QLatin1Char('x')) * 10; const int Width = FontMetrics.horizontalAdvance(QLatin1Char('x')) * 10;
#else #else
int Width = FontMetrics.width(QLatin1Char('x')) * 10; const int Width = FontMetrics.width(QLatin1Char('x')) * 10;
#endif #endif
return QLineEdit::sizeHint() - QSize(Width, 0); return QLineEdit::sizeHint() - QSize(Width, 0);
@ -46,8 +46,8 @@ protected:
{ {
if (Event->type() == QEvent::ShortcutOverride) if (Event->type() == QEvent::ShortcutOverride)
{ {
QKeyEvent* KeyEvent = (QKeyEvent*)Event; const QKeyEvent* KeyEvent = (QKeyEvent*)Event;
int Key = KeyEvent->key(); const int Key = KeyEvent->key();
if (KeyEvent->modifiers() == Qt::NoModifier && Key >= Qt::Key_A && Key <= Qt::Key_Z) if (KeyEvent->modifiers() == Qt::NoModifier && Key >= Qt::Key_A && Key <= Qt::Key_Z)
Event->accept(); Event->accept();

View file

@ -9,7 +9,7 @@ char* strcasestr(const char *s, const char *find)
if ((c = *find++) != 0) if ((c = *find++) != 0)
{ {
c = tolower((unsigned char)c); c = tolower((unsigned char)c);
int len = (int)strlen(find); const int len = (int)strlen(find);
do do
{ {
do do