mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
Added const qualifiers.
This commit is contained in:
parent
66bed1a8f0
commit
7275c4256d
17 changed files with 226 additions and 226 deletions
|
@ -26,7 +26,7 @@ void lcGroup::CreateName(const lcArray<lcGroup*>& Groups)
|
||||||
if (!mName.isEmpty())
|
if (!mName.isEmpty())
|
||||||
{
|
{
|
||||||
bool Found = false;
|
bool Found = false;
|
||||||
for (lcGroup* Group : Groups)
|
for (const lcGroup* const Group : Groups)
|
||||||
{
|
{
|
||||||
if (Group->mName == mName)
|
if (Group->mName == mName)
|
||||||
{
|
{
|
||||||
|
@ -41,9 +41,9 @@ void lcGroup::CreateName(const lcArray<lcGroup*>& Groups)
|
||||||
|
|
||||||
int Max = 0;
|
int Max = 0;
|
||||||
QString Prefix = QApplication::tr("Group #");
|
QString Prefix = QApplication::tr("Group #");
|
||||||
int Length = Prefix.length();
|
const int Length = Prefix.length();
|
||||||
|
|
||||||
for (lcGroup* Group : Groups)
|
for (const lcGroup* const Group : Groups)
|
||||||
{
|
{
|
||||||
const QString& Name = Group->mName;
|
const QString& Name = Group->mName;
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ public:
|
||||||
{
|
{
|
||||||
if ((mLength + Grow) > mAlloc)
|
if ((mLength + Grow) > mAlloc)
|
||||||
{
|
{
|
||||||
size_t NewSize = ((mLength + Grow + mGrow - 1) / mGrow) * mGrow;
|
const size_t NewSize = ((mLength + Grow + mGrow - 1) / mGrow) * mGrow;
|
||||||
T* NewData = new T[NewSize];
|
T* NewData = new T[NewSize];
|
||||||
|
|
||||||
for (int i = 0; i < mLength; i++)
|
for (int i = 0; i < mLength; i++)
|
||||||
|
|
|
@ -55,13 +55,13 @@ bool lcLoadColorFile(lcFile& File);
|
||||||
int lcGetColorIndex(quint32 ColorCode);
|
int lcGetColorIndex(quint32 ColorCode);
|
||||||
int lcGetBrickLinkColor(int ColorIndex);
|
int lcGetBrickLinkColor(int ColorIndex);
|
||||||
|
|
||||||
inline quint32 lcGetColorCodeFromExtendedColor(int Color)
|
inline constexpr quint32 lcGetColorCodeFromExtendedColor(int Color)
|
||||||
{
|
{
|
||||||
const int ConverstionTable[] = { 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 int ConverstionTable[] = { 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 ConverstionTable[Color];
|
return ConverstionTable[Color];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline quint32 lcGetColorCodeFromOriginalColor(int Color)
|
inline constexpr quint32 lcGetColorCodeFromOriginalColor(int Color)
|
||||||
{
|
{
|
||||||
const int ConverstionTable[] = { 0, 2, 4, 9, 7, 6, 22, 8, 10, 11, 14, 16, 18, 9, 21, 20, 22, 8, 10, 11 };
|
const int ConverstionTable[] = { 0, 2, 4, 9, 7, 6, 22, 8, 10, 11, 14, 16, 18, 9, 21, 20, 22, 8, 10, 11 };
|
||||||
return lcGetColorCodeFromExtendedColor(ConverstionTable[Color]);
|
return lcGetColorCodeFromExtendedColor(ConverstionTable[Color]);
|
||||||
|
|
|
@ -102,7 +102,7 @@ void lcContext::CreateShaderPrograms()
|
||||||
" LC_SHADER_PRECISION float Diffuse = min(abs(dot(Normal, LightDirection)) * 0.6 + 0.65, 1.0);\n"
|
" LC_SHADER_PRECISION float Diffuse = min(abs(dot(Normal, LightDirection)) * 0.6 + 0.65, 1.0);\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* VertexShaders[static_cast<int>(lcMaterialType::Count)] =
|
const char* const VertexShaders[static_cast<int>(lcMaterialType::Count)] =
|
||||||
{
|
{
|
||||||
":/resources/shaders/unlit_color_vs.glsl", // UnlitColor
|
":/resources/shaders/unlit_color_vs.glsl", // UnlitColor
|
||||||
":/resources/shaders/unlit_texture_modulate_vs.glsl", // UnlitTextureModulate
|
":/resources/shaders/unlit_texture_modulate_vs.glsl", // UnlitTextureModulate
|
||||||
|
@ -113,7 +113,7 @@ void lcContext::CreateShaderPrograms()
|
||||||
":/resources/shaders/fakelit_texture_decal_vs.glsl" // FakeLitTextureDecal
|
":/resources/shaders/fakelit_texture_decal_vs.glsl" // FakeLitTextureDecal
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* FragmentShaders[static_cast<int>(lcMaterialType::Count)] =
|
const char* const FragmentShaders[static_cast<int>(lcMaterialType::Count)] =
|
||||||
{
|
{
|
||||||
":/resources/shaders/unlit_color_ps.glsl", // UnlitColor
|
":/resources/shaders/unlit_color_ps.glsl", // UnlitColor
|
||||||
":/resources/shaders/unlit_texture_modulate_ps.glsl", // UnlitTextureModulate
|
":/resources/shaders/unlit_texture_modulate_ps.glsl", // UnlitTextureModulate
|
||||||
|
@ -124,7 +124,7 @@ void lcContext::CreateShaderPrograms()
|
||||||
":/resources/shaders/fakelit_texture_decal_ps.glsl" // FakeLitTextureDecal
|
":/resources/shaders/fakelit_texture_decal_ps.glsl" // FakeLitTextureDecal
|
||||||
};
|
};
|
||||||
|
|
||||||
auto LoadShader = [ShaderPrefix](const char* FileName, GLuint ShaderType) -> GLuint
|
const auto LoadShader = [ShaderPrefix](const char* FileName, GLuint ShaderType) -> GLuint
|
||||||
{
|
{
|
||||||
QResource Resource(FileName);
|
QResource Resource(FileName);
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ void lcContext::CreateShaderPrograms()
|
||||||
Data = ShaderPrefix + Data;
|
Data = ShaderPrefix + Data;
|
||||||
const char* Source = Data.constData();
|
const char* Source = Data.constData();
|
||||||
|
|
||||||
GLuint Shader = glCreateShader(ShaderType);
|
const GLuint Shader = glCreateShader(ShaderType);
|
||||||
glShaderSource(Shader, 1, &Source, nullptr);
|
glShaderSource(Shader, 1, &Source, nullptr);
|
||||||
glCompileShader(Shader);
|
glCompileShader(Shader);
|
||||||
|
|
||||||
|
@ -167,8 +167,8 @@ void lcContext::CreateShaderPrograms()
|
||||||
|
|
||||||
for (int MaterialType = 0; MaterialType < static_cast<int>(lcMaterialType::Count); MaterialType++)
|
for (int MaterialType = 0; MaterialType < static_cast<int>(lcMaterialType::Count); MaterialType++)
|
||||||
{
|
{
|
||||||
GLuint VertexShader = LoadShader(VertexShaders[MaterialType], GL_VERTEX_SHADER);
|
const GLuint VertexShader = LoadShader(VertexShaders[MaterialType], GL_VERTEX_SHADER);
|
||||||
GLuint FragmentShader = LoadShader(FragmentShaders[MaterialType], GL_FRAGMENT_SHADER);
|
const GLuint FragmentShader = LoadShader(FragmentShaders[MaterialType], GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
GLuint Program = glCreateProgram();
|
GLuint Program = glCreateProgram();
|
||||||
|
|
||||||
|
@ -505,7 +505,7 @@ void lcContext::SetColorIndex(int ColorIndex)
|
||||||
|
|
||||||
void lcContext::SetColorIndexTinted(int ColorIndex, lcInterfaceColor InterfaceColor, float Weight)
|
void lcContext::SetColorIndexTinted(int ColorIndex, lcInterfaceColor InterfaceColor, float Weight)
|
||||||
{
|
{
|
||||||
lcVector3 Color(gColorList[ColorIndex].Value * Weight + gInterfaceColors[InterfaceColor] * (1.0f - Weight));
|
const lcVector3 Color(gColorList[ColorIndex].Value * Weight + gInterfaceColors[InterfaceColor] * (1.0f - Weight));
|
||||||
SetColor(lcVector4(Color, gColorList[ColorIndex].Value.w));
|
SetColor(lcVector4(Color, gColorList[ColorIndex].Value.w));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,7 +686,7 @@ void lcContext::GetRenderFramebufferImage(const std::pair<lcFramebuffer, lcFrame
|
||||||
{
|
{
|
||||||
const int Width = RenderFramebuffer.first.mWidth;
|
const int Width = RenderFramebuffer.first.mWidth;
|
||||||
const int Height = RenderFramebuffer.first.mHeight;
|
const int Height = RenderFramebuffer.first.mHeight;
|
||||||
GLuint SavedFramebuffer = mFramebufferObject;
|
const GLuint SavedFramebuffer = mFramebufferObject;
|
||||||
|
|
||||||
if (RenderFramebuffer.second.IsValid())
|
if (RenderFramebuffer.second.IsValid())
|
||||||
{
|
{
|
||||||
|
@ -866,7 +866,7 @@ void lcContext::SetVertexBuffer(lcVertexBuffer VertexBuffer)
|
||||||
{
|
{
|
||||||
if (gSupportsVertexBufferObject)
|
if (gSupportsVertexBufferObject)
|
||||||
{
|
{
|
||||||
GLuint VertexBufferObject = VertexBuffer.Object;
|
const GLuint VertexBufferObject = VertexBuffer.Object;
|
||||||
mVertexBufferPointer = nullptr;
|
mVertexBufferPointer = nullptr;
|
||||||
|
|
||||||
if (VertexBufferObject != mVertexBufferObject)
|
if (VertexBufferObject != mVertexBufferObject)
|
||||||
|
@ -897,7 +897,7 @@ void lcContext::SetVertexBufferPointer(const void* VertexBuffer)
|
||||||
|
|
||||||
void lcContext::SetVertexFormatPosition(int PositionSize)
|
void lcContext::SetVertexFormatPosition(int PositionSize)
|
||||||
{
|
{
|
||||||
int VertexSize = PositionSize * sizeof(float);
|
const int VertexSize = PositionSize * sizeof(float);
|
||||||
char* VertexBufferPointer = mVertexBufferPointer;
|
char* VertexBufferPointer = mVertexBufferPointer;
|
||||||
|
|
||||||
if (gSupportsShaderObjects)
|
if (gSupportsShaderObjects)
|
||||||
|
@ -956,7 +956,7 @@ void lcContext::SetVertexFormatPosition(int PositionSize)
|
||||||
|
|
||||||
void lcContext::SetVertexFormat(int BufferOffset, int PositionSize, int NormalSize, int TexCoordSize, int ColorSize, bool EnableNormals)
|
void lcContext::SetVertexFormat(int BufferOffset, int PositionSize, int NormalSize, int TexCoordSize, int ColorSize, bool EnableNormals)
|
||||||
{
|
{
|
||||||
int VertexSize = (PositionSize + TexCoordSize + ColorSize) * sizeof(float) + NormalSize * sizeof(quint32);
|
const int VertexSize = (PositionSize + TexCoordSize + ColorSize) * sizeof(float) + NormalSize * sizeof(quint32);
|
||||||
char* VertexBufferPointer = mVertexBufferPointer + BufferOffset;
|
char* VertexBufferPointer = mVertexBufferPointer + BufferOffset;
|
||||||
|
|
||||||
if (gSupportsShaderObjects)
|
if (gSupportsShaderObjects)
|
||||||
|
@ -1100,7 +1100,7 @@ void lcContext::SetIndexBuffer(lcIndexBuffer IndexBuffer)
|
||||||
{
|
{
|
||||||
if (gSupportsVertexBufferObject)
|
if (gSupportsVertexBufferObject)
|
||||||
{
|
{
|
||||||
GLuint IndexBufferObject = IndexBuffer.Object;
|
const GLuint IndexBufferObject = IndexBuffer.Object;
|
||||||
mIndexBufferPointer = nullptr;
|
mIndexBufferPointer = nullptr;
|
||||||
|
|
||||||
if (IndexBufferObject != mIndexBufferObject)
|
if (IndexBufferObject != mIndexBufferObject)
|
||||||
|
@ -1128,12 +1128,12 @@ void lcContext::SetIndexBufferPointer(const void* IndexBuffer)
|
||||||
|
|
||||||
void lcContext::BindMesh(const lcMesh* Mesh)
|
void lcContext::BindMesh(const lcMesh* Mesh)
|
||||||
{
|
{
|
||||||
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
const lcPiecesLibrary* const Library = lcGetPiecesLibrary();
|
||||||
|
|
||||||
if (Mesh->mVertexCacheOffset != -1)
|
if (Mesh->mVertexCacheOffset != -1)
|
||||||
{
|
{
|
||||||
GLuint VertexBufferObject = Library->mVertexBuffer.Object;
|
const GLuint VertexBufferObject = Library->mVertexBuffer.Object;
|
||||||
GLuint IndexBufferObject = Library->mIndexBuffer.Object;
|
const GLuint IndexBufferObject = Library->mIndexBuffer.Object;
|
||||||
|
|
||||||
if (VertexBufferObject != mVertexBufferObject)
|
if (VertexBufferObject != mVertexBufferObject)
|
||||||
{
|
{
|
||||||
|
@ -1192,7 +1192,7 @@ void lcContext::FlushState()
|
||||||
|
|
||||||
if (mViewMatrixDirty)
|
if (mViewMatrixDirty)
|
||||||
{
|
{
|
||||||
lcMatrix44 InverseViewMatrix = lcMatrix44AffineInverse(mViewMatrix);
|
const lcMatrix44 InverseViewMatrix = lcMatrix44AffineInverse(mViewMatrix);
|
||||||
lcVector3 ViewPosition = lcMul30(-mViewMatrix.GetTranslation(), InverseViewMatrix);
|
lcVector3 ViewPosition = lcMul30(-mViewMatrix.GetTranslation(), InverseViewMatrix);
|
||||||
|
|
||||||
if (Program.LightPositionLocation != -1)
|
if (Program.LightPositionLocation != -1)
|
||||||
|
|
|
@ -167,7 +167,7 @@ public:
|
||||||
|
|
||||||
QString ReadQString()
|
QString ReadQString()
|
||||||
{
|
{
|
||||||
quint32 Size = ReadU32();
|
const quint32 Size = ReadU32();
|
||||||
char* Buffer = new char[Size];
|
char* Buffer = new char[Size];
|
||||||
ReadBuffer(Buffer, Size);
|
ReadBuffer(Buffer, Size);
|
||||||
QString String = QString::fromUtf8(Buffer, Size);
|
QString String = QString::fromUtf8(Buffer, Size);
|
||||||
|
@ -545,7 +545,7 @@ public:
|
||||||
|
|
||||||
char* ReadLine(char* Buffer, size_t BufferSize) override
|
char* ReadLine(char* Buffer, size_t BufferSize) override
|
||||||
{
|
{
|
||||||
qint64 LineLength = mFile.readLine(Buffer, BufferSize);
|
const qint64 LineLength = mFile.readLine(Buffer, BufferSize);
|
||||||
return LineLength != -1 ? Buffer : nullptr;
|
return LineLength != -1 ? Buffer : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -498,7 +498,7 @@ void lcPiecesLibrary::ReadArchiveDescriptions(const QString& OfficialFileName, c
|
||||||
bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress)
|
bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress)
|
||||||
{
|
{
|
||||||
const QLatin1String BaseFolders[LC_NUM_FOLDERTYPES] = { QLatin1String("unofficial/"), QLatin1String("") };
|
const QLatin1String BaseFolders[LC_NUM_FOLDERTYPES] = { QLatin1String("unofficial/"), QLatin1String("") };
|
||||||
const int NumBaseFolders = LC_ARRAY_COUNT(BaseFolders);
|
constexpr int NumBaseFolders = LC_ARRAY_COUNT(BaseFolders);
|
||||||
|
|
||||||
QFileInfoList FileLists[NumBaseFolders];
|
QFileInfoList FileLists[NumBaseFolders];
|
||||||
|
|
||||||
|
@ -561,7 +561,7 @@ bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress)
|
||||||
if (BaseFolderIdx == 0)
|
if (BaseFolderIdx == 0)
|
||||||
mHasUnofficial = true;
|
mHasUnofficial = true;
|
||||||
|
|
||||||
bool SubFile = SubFileDirectories[DirectoryIdx];
|
const bool SubFile = SubFileDirectories[DirectoryIdx];
|
||||||
mPrimitives[Name] = new lcLibraryPrimitive(std::move(FileName), strchr(FileString, '/') + 1, LC_NUM_ZIPFILES, 0, !SubFile && (memcmp(Name, "STU", 3) == 0), SubFile);
|
mPrimitives[Name] = new lcLibraryPrimitive(std::move(FileName), strchr(FileString, '/') + 1, LC_NUM_ZIPFILES, 0, !SubFile && (memcmp(Name, "STU", 3) == 0), SubFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -705,7 +705,7 @@ void lcPiecesLibrary::ReadDirectoryDescriptions(const QFileInfoList (&FileLists)
|
||||||
{
|
{
|
||||||
const char* FileName = *(const char**)CachedDescription;
|
const char* FileName = *(const char**)CachedDescription;
|
||||||
const char* Description = FileName + strlen(FileName) + 1;
|
const char* Description = FileName + strlen(FileName) + 1;
|
||||||
uint64_t CachedFileTime = *(uint64_t*)(Description + strlen(Description) + 1 + 4 + 1);
|
const uint64_t CachedFileTime = *(uint64_t*)(Description + strlen(Description) + 1 + 4 + 1);
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
|
||||||
quint64 FileTime = FileLists[Info->mFolderType][Info->mFolderIndex].lastModified().toMSecsSinceEpoch();
|
quint64 FileTime = FileLists[Info->mFolderType][Info->mFolderIndex].lastModified().toMSecsSinceEpoch();
|
||||||
|
@ -851,7 +851,7 @@ bool lcPiecesLibrary::ReadArchiveCacheFile(const QString& FileName, lcMemFile& C
|
||||||
CacheFile.SetLength(UncompressedSize);
|
CacheFile.SetLength(UncompressedSize);
|
||||||
CacheFile.Seek(0, SEEK_SET);
|
CacheFile.Seek(0, SEEK_SET);
|
||||||
|
|
||||||
const int CHUNK = 16384;
|
constexpr int CHUNK = 16384;
|
||||||
int ret;
|
int ret;
|
||||||
unsigned have;
|
unsigned have;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
|
@ -918,8 +918,8 @@ bool lcPiecesLibrary::WriteArchiveCacheFile(const QString& FileName, lcMemFile&
|
||||||
if (!File.open(QIODevice::WriteOnly))
|
if (!File.open(QIODevice::WriteOnly))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
quint32 CacheVersion = LC_LIBRARY_CACHE_VERSION;
|
constexpr quint32 CacheVersion = LC_LIBRARY_CACHE_VERSION;
|
||||||
quint32 CacheFlags = LC_LIBRARY_CACHE_ARCHIVE;
|
constexpr quint32 CacheFlags = LC_LIBRARY_CACHE_ARCHIVE;
|
||||||
|
|
||||||
if (File.write((char*)&CacheVersion, sizeof(CacheVersion)) == -1)
|
if (File.write((char*)&CacheVersion, sizeof(CacheVersion)) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
@ -930,12 +930,12 @@ bool lcPiecesLibrary::WriteArchiveCacheFile(const QString& FileName, lcMemFile&
|
||||||
if (File.write((char*)&mArchiveCheckSum, sizeof(mArchiveCheckSum)) == -1)
|
if (File.write((char*)&mArchiveCheckSum, sizeof(mArchiveCheckSum)) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
quint32 UncompressedSize = (quint32)CacheFile.GetLength();
|
const quint32 UncompressedSize = (quint32)CacheFile.GetLength();
|
||||||
|
|
||||||
if (File.write((char*)&UncompressedSize, sizeof(UncompressedSize)) == -1)
|
if (File.write((char*)&UncompressedSize, sizeof(UncompressedSize)) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const size_t BufferSize = 16384;
|
constexpr size_t BufferSize = 16384;
|
||||||
char WriteBuffer[BufferSize];
|
char WriteBuffer[BufferSize];
|
||||||
z_stream Stream;
|
z_stream Stream;
|
||||||
quint32 Crc32 = 0;
|
quint32 Crc32 = 0;
|
||||||
|
@ -1015,15 +1015,15 @@ bool lcPiecesLibrary::WriteDirectoryCacheFile(const QString& FileName, lcMemFile
|
||||||
if (!File.open(QIODevice::WriteOnly))
|
if (!File.open(QIODevice::WriteOnly))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
quint32 CacheVersion = LC_LIBRARY_CACHE_VERSION;
|
constexpr quint32 CacheVersion = LC_LIBRARY_CACHE_VERSION;
|
||||||
if (File.write((char*)&CacheVersion, sizeof(CacheVersion)) == -1)
|
if (File.write((char*)&CacheVersion, sizeof(CacheVersion)) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
quint32 CacheFlags = LC_LIBRARY_CACHE_DIRECTORY;
|
constexpr quint32 CacheFlags = LC_LIBRARY_CACHE_DIRECTORY;
|
||||||
if (File.write((char*)&CacheFlags, sizeof(CacheFlags)) == -1)
|
if (File.write((char*)&CacheFlags, sizeof(CacheFlags)) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
quint32 UncompressedSize = (quint32)CacheFile.GetLength();
|
const quint32 UncompressedSize = (quint32)CacheFile.GetLength();
|
||||||
if (File.write((char*)&UncompressedSize, sizeof(UncompressedSize)) == -1)
|
if (File.write((char*)&UncompressedSize, sizeof(UncompressedSize)) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1065,15 +1065,15 @@ bool lcPiecesLibrary::SaveArchiveCacheIndex(const QString& FileName)
|
||||||
{
|
{
|
||||||
lcMemFile IndexFile;
|
lcMemFile IndexFile;
|
||||||
|
|
||||||
quint32 NumFiles = (quint32)mPieces.size();
|
const quint32 NumFiles = (quint32)mPieces.size();
|
||||||
|
|
||||||
if (IndexFile.WriteBuffer((char*)&NumFiles, sizeof(NumFiles)) == 0)
|
if (IndexFile.WriteBuffer((char*)&NumFiles, sizeof(NumFiles)) == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (const auto& PieceIt : mPieces)
|
for (const auto& PieceIt : mPieces)
|
||||||
{
|
{
|
||||||
PieceInfo* Info = PieceIt.second;
|
const PieceInfo* Info = PieceIt.second;
|
||||||
quint8 Length = (quint8)strlen(Info->m_strDescription);
|
const quint8 Length = (quint8)strlen(Info->m_strDescription);
|
||||||
|
|
||||||
if (IndexFile.WriteBuffer((char*)&Length, sizeof(Length)) == 0)
|
if (IndexFile.WriteBuffer((char*)&Length, sizeof(Length)) == 0)
|
||||||
return false;
|
return false;
|
||||||
|
@ -1117,7 +1117,7 @@ bool lcPiecesLibrary::SaveCachePiece(PieceInfo* Info)
|
||||||
{
|
{
|
||||||
lcMemFile MeshData;
|
lcMemFile MeshData;
|
||||||
|
|
||||||
qint32 Flags = mStudLogo;
|
const qint32 Flags = mStudLogo;
|
||||||
if (MeshData.WriteBuffer((char*)&Flags, sizeof(Flags)) == 0)
|
if (MeshData.WriteBuffer((char*)&Flags, sizeof(Flags)) == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1425,7 +1425,7 @@ void lcPiecesLibrary::UpdateBuffers(lcContext* Context)
|
||||||
|
|
||||||
for (const auto& PieceIt : mPieces)
|
for (const auto& PieceIt : mPieces)
|
||||||
{
|
{
|
||||||
PieceInfo* Info = PieceIt.second;
|
const PieceInfo* const Info = PieceIt.second;
|
||||||
lcMesh* Mesh = Info->IsPlaceholder() ? gPlaceholderMesh : Info->GetMesh();
|
lcMesh* Mesh = Info->IsPlaceholder() ? gPlaceholderMesh : Info->GetMesh();
|
||||||
|
|
||||||
if (!Mesh)
|
if (!Mesh)
|
||||||
|
@ -1631,7 +1631,7 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
|
||||||
|
|
||||||
if (Primitive->mStud)
|
if (Primitive->mStud)
|
||||||
{
|
{
|
||||||
bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
|
const bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
|
||||||
if (OpenStud || !strcmp(Primitive->mName,"stud.dat"))
|
if (OpenStud || !strcmp(Primitive->mName,"stud.dat"))
|
||||||
{
|
{
|
||||||
Primitive->mMeshData.mHasLogoStud = true;
|
Primitive->mMeshData.mHasLogoStud = true;
|
||||||
|
@ -1675,7 +1675,7 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
|
||||||
{
|
{
|
||||||
if (Primitive->mStud)
|
if (Primitive->mStud)
|
||||||
{
|
{
|
||||||
bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
|
const bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
|
||||||
if (OpenStud || !strcmp(Primitive->mName,"stud.dat"))
|
if (OpenStud || !strcmp(Primitive->mName,"stud.dat"))
|
||||||
{
|
{
|
||||||
Primitive->mMeshData.mHasLogoStud = true;
|
Primitive->mMeshData.mHasLogoStud = true;
|
||||||
|
@ -1779,7 +1779,7 @@ void lcPiecesLibrary::GetCategoryEntries(const char* CategoryKeywords, bool Grou
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check if this piece has already been added to this category by one of its children.
|
// Check if this piece has already been added to this category by one of its children.
|
||||||
int Index = GroupedPieces.FindIndex(Info);
|
const int Index = GroupedPieces.FindIndex(Info);
|
||||||
|
|
||||||
if (Index == -1)
|
if (Index == -1)
|
||||||
SinglePieces.Add(Info);
|
SinglePieces.Add(Info);
|
||||||
|
|
|
@ -204,7 +204,7 @@ public:
|
||||||
|
|
||||||
View* GetActiveView() const
|
View* GetActiveView() const
|
||||||
{
|
{
|
||||||
lcModelTabWidget* CurrentTab = mModelTabWidget ? (lcModelTabWidget*)mModelTabWidget->currentWidget() : nullptr;
|
const lcModelTabWidget* const CurrentTab = mModelTabWidget ? (lcModelTabWidget*)mModelTabWidget->currentWidget() : nullptr;
|
||||||
return CurrentTab ? CurrentTab->GetActiveView() : nullptr;
|
return CurrentTab ? CurrentTab->GetActiveView() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,13 +212,13 @@ public:
|
||||||
|
|
||||||
lcModel* GetCurrentTabModel() const
|
lcModel* GetCurrentTabModel() const
|
||||||
{
|
{
|
||||||
lcModelTabWidget* CurrentTab = (lcModelTabWidget*)mModelTabWidget->currentWidget();
|
const lcModelTabWidget* const CurrentTab = (lcModelTabWidget*)mModelTabWidget->currentWidget();
|
||||||
return CurrentTab ? CurrentTab->GetModel() : nullptr;
|
return CurrentTab ? CurrentTab->GetModel() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lcArray<View*>* GetViewsForModel(lcModel* Model) const
|
const lcArray<View*>* GetViewsForModel(const lcModel* Model) const
|
||||||
{
|
{
|
||||||
lcModelTabWidget* TabWidget = GetTabWidgetForModel(Model);
|
const lcModelTabWidget* const TabWidget = GetTabWidgetForModel(Model);
|
||||||
return TabWidget ? TabWidget->GetViews() : nullptr;
|
return TabWidget ? TabWidget->GetViews() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ public:
|
||||||
{
|
{
|
||||||
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx);
|
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx);
|
||||||
|
|
||||||
int ViewIndex = TabWidget->GetViews()->FindIndex(View);
|
const int ViewIndex = TabWidget->GetViews()->FindIndex(View);
|
||||||
if (ViewIndex != -1)
|
if (ViewIndex != -1)
|
||||||
return TabWidget;
|
return TabWidget;
|
||||||
}
|
}
|
||||||
|
@ -376,7 +376,7 @@ protected:
|
||||||
|
|
||||||
bool OpenProjectFile(const QString& FileName);
|
bool OpenProjectFile(const QString& FileName);
|
||||||
|
|
||||||
lcModelTabWidget* GetTabWidgetForModel(lcModel* Model) const
|
lcModelTabWidget* GetTabWidgetForModel(const lcModel* Model) const
|
||||||
{
|
{
|
||||||
for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); TabIdx++)
|
for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); TabIdx++)
|
||||||
{
|
{
|
||||||
|
|
150
common/lc_math.h
150
common/lc_math.h
|
@ -448,7 +448,7 @@ inline QDataStream& operator >> (QDataStream& Stream, lcVector4& v)
|
||||||
|
|
||||||
inline void lcVector3::Normalize()
|
inline void lcVector3::Normalize()
|
||||||
{
|
{
|
||||||
float InvLength = 1.0f / Length();
|
const float InvLength = 1.0f / Length();
|
||||||
|
|
||||||
x *= InvLength;
|
x *= InvLength;
|
||||||
y *= InvLength;
|
y *= InvLength;
|
||||||
|
@ -680,13 +680,13 @@ inline lcVector4 lcMul4(const lcVector4& a, const lcMatrix44& b)
|
||||||
|
|
||||||
inline lcMatrix33 lcMul(const lcMatrix33& a, const lcMatrix33& b)
|
inline lcMatrix33 lcMul(const lcMatrix33& a, const lcMatrix33& b)
|
||||||
{
|
{
|
||||||
lcVector3 Col0(b.r[0][0], b.r[1][0], b.r[2][0]);
|
const lcVector3 Col0(b.r[0][0], b.r[1][0], b.r[2][0]);
|
||||||
lcVector3 Col1(b.r[0][1], b.r[1][1], b.r[2][1]);
|
const lcVector3 Col1(b.r[0][1], b.r[1][1], b.r[2][1]);
|
||||||
lcVector3 Col2(b.r[0][2], b.r[1][2], b.r[2][2]);
|
const lcVector3 Col2(b.r[0][2], b.r[1][2], b.r[2][2]);
|
||||||
|
|
||||||
lcVector3 Ret0(lcDot(a.r[0], Col0), lcDot(a.r[0], Col1), lcDot(a.r[0], Col2));
|
const lcVector3 Ret0(lcDot(a.r[0], Col0), lcDot(a.r[0], Col1), lcDot(a.r[0], Col2));
|
||||||
lcVector3 Ret1(lcDot(a.r[1], Col0), lcDot(a.r[1], Col1), lcDot(a.r[1], Col2));
|
const lcVector3 Ret1(lcDot(a.r[1], Col0), lcDot(a.r[1], Col1), lcDot(a.r[1], Col2));
|
||||||
lcVector3 Ret2(lcDot(a.r[2], Col0), lcDot(a.r[2], Col1), lcDot(a.r[2], Col2));
|
const lcVector3 Ret2(lcDot(a.r[2], Col0), lcDot(a.r[2], Col1), lcDot(a.r[2], Col2));
|
||||||
|
|
||||||
return lcMatrix33(Ret0, Ret1, Ret2);
|
return lcMatrix33(Ret0, Ret1, Ret2);
|
||||||
}
|
}
|
||||||
|
@ -1101,8 +1101,8 @@ inline lcVector4 lcMatrix44ToAxisAngle(const lcMatrix44& m)
|
||||||
if (m.Determinant() < 0.0f)
|
if (m.Determinant() < 0.0f)
|
||||||
Rows[0] *= -1.0f;
|
Rows[0] *= -1.0f;
|
||||||
|
|
||||||
float Trace = Rows[0][0] + Rows[1][1] + Rows[2][2];
|
const float Trace = Rows[0][0] + Rows[1][1] + Rows[2][2];
|
||||||
float Cos = 0.5f * (Trace - 1.0f);
|
const float Cos = 0.5f * (Trace - 1.0f);
|
||||||
lcVector4 rot;
|
lcVector4 rot;
|
||||||
|
|
||||||
rot[3] = acosf(lcClamp(Cos, -1.0f, 1.0f)); // in [0,PI]
|
rot[3] = acosf(lcClamp(Cos, -1.0f, 1.0f)); // in [0,PI]
|
||||||
|
@ -1358,10 +1358,10 @@ inline lcMatrix44 lcMatrix44Inverse(const lcMatrix44& m)
|
||||||
r0[4] = s * (r0[4] - r1[4] * m0), r0[5] = s * (r0[5] - r1[5] * m0),
|
r0[4] = s * (r0[4] - r1[4] * m0), r0[5] = s * (r0[5] - r1[5] * m0),
|
||||||
r0[6] = s * (r0[6] - r1[6] * m0), r0[7] = s * (r0[7] - r1[7] * m0);
|
r0[6] = s * (r0[6] - r1[6] * m0), r0[7] = s * (r0[7] - r1[7] * m0);
|
||||||
|
|
||||||
lcVector4 Row0(r0[4], r1[4], r2[4], r3[4]);
|
const lcVector4 Row0(r0[4], r1[4], r2[4], r3[4]);
|
||||||
lcVector4 Row1(r0[5], r1[5], r2[5], r3[5]);
|
const lcVector4 Row1(r0[5], r1[5], r2[5], r3[5]);
|
||||||
lcVector4 Row2(r0[6], r1[6], r2[6], r3[6]);
|
const lcVector4 Row2(r0[6], r1[6], r2[6], r3[6]);
|
||||||
lcVector4 Row3(r0[7], r1[7], r2[7], r3[7]);
|
const lcVector4 Row3(r0[7], r1[7], r2[7], r3[7]);
|
||||||
|
|
||||||
lcMatrix44 out(Row0, Row1, Row2, Row3);
|
lcMatrix44 out(Row0, Row1, Row2, Row3);
|
||||||
|
|
||||||
|
@ -1412,17 +1412,17 @@ inline lcVector4 lcQuaternionRotationZ(float Radians)
|
||||||
|
|
||||||
inline lcVector4 lcQuaternionFromAxisAngle(const lcVector4& a)
|
inline lcVector4 lcQuaternionFromAxisAngle(const lcVector4& a)
|
||||||
{
|
{
|
||||||
float s = sinf(a[3] / 2.0f);
|
const float s = sinf(a[3] / 2.0f);
|
||||||
return lcVector4(a[0] * s, a[1] * s, a[2] * s, cosf(a[3] / 2.0f));
|
return lcVector4(a[0] * s, a[1] * s, a[2] * s, cosf(a[3] / 2.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline lcVector4 lcQuaternionToAxisAngle(const lcVector4& a)
|
inline lcVector4 lcQuaternionToAxisAngle(const lcVector4& a)
|
||||||
{
|
{
|
||||||
float Len = lcDot3(a, a);
|
const float Len = lcDot3(a, a);
|
||||||
|
|
||||||
if (Len > 0.00001f)
|
if (Len > 0.00001f)
|
||||||
{
|
{
|
||||||
float f = 1.0f / sqrtf(Len);
|
const float f = 1.0f / sqrtf(Len);
|
||||||
return lcVector4(a[0] * f, a[1] * f, a[2] * f, acosf(a[3]) * 2.0f);
|
return lcVector4(a[0] * f, a[1] * f, a[2] * f, acosf(a[3]) * 2.0f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1433,10 +1433,10 @@ inline lcVector4 lcQuaternionToAxisAngle(const lcVector4& a)
|
||||||
|
|
||||||
inline lcVector4 lcQuaternionMultiply(const lcVector4& a, const lcVector4& b)
|
inline lcVector4 lcQuaternionMultiply(const lcVector4& a, const lcVector4& b)
|
||||||
{
|
{
|
||||||
float x = a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0];
|
const float x = a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0];
|
||||||
float y = -a[0] * b[2] + a[1] * b[3] + a[2] * b[0] + a[3] * b[1];
|
const float y = -a[0] * b[2] + a[1] * b[3] + a[2] * b[0] + a[3] * b[1];
|
||||||
float z = a[0] * b[1] - a[1] * b[0] + a[2] * b[3] + a[3] * b[2];
|
const float z = a[0] * b[1] - a[1] * b[0] + a[2] * b[3] + a[3] * b[2];
|
||||||
float w = -a[0] * b[0] - a[1] * b[1] - a[2] * b[2] + a[3] * b[3];
|
const float w = -a[0] * b[0] - a[1] * b[1] - a[2] * b[2] + a[3] * b[3];
|
||||||
|
|
||||||
return lcVector4(x, y, z, w);
|
return lcVector4(x, y, z, w);
|
||||||
}
|
}
|
||||||
|
@ -1444,18 +1444,18 @@ inline lcVector4 lcQuaternionMultiply(const lcVector4& a, const lcVector4& b)
|
||||||
inline lcVector3 lcQuaternionMul(const lcVector3& a, const lcVector4& b)
|
inline lcVector3 lcQuaternionMul(const lcVector3& a, const lcVector4& b)
|
||||||
{
|
{
|
||||||
// Faster to transform to a matrix and multiply.
|
// Faster to transform to a matrix and multiply.
|
||||||
float Tx = 2.0f*b[0];
|
const float Tx = 2.0f*b[0];
|
||||||
float Ty = 2.0f*b[1];
|
const float Ty = 2.0f*b[1];
|
||||||
float Tz = 2.0f*b[2];
|
const float Tz = 2.0f*b[2];
|
||||||
float Twx = Tx*b[3];
|
const float Twx = Tx*b[3];
|
||||||
float Twy = Ty*b[3];
|
const float Twy = Ty*b[3];
|
||||||
float Twz = Tz*b[3];
|
const float Twz = Tz*b[3];
|
||||||
float Txx = Tx*b[0];
|
const float Txx = Tx*b[0];
|
||||||
float Txy = Ty*b[0];
|
const float Txy = Ty*b[0];
|
||||||
float Txz = Tz*b[0];
|
const float Txz = Tz*b[0];
|
||||||
float Tyy = Ty*b[1];
|
const float Tyy = Ty*b[1];
|
||||||
float Tyz = Tz*b[1];
|
const float Tyz = Tz*b[1];
|
||||||
float Tzz = Tz*b[2];
|
const float Tzz = Tz*b[2];
|
||||||
|
|
||||||
lcVector3 Rows[3];
|
lcVector3 Rows[3];
|
||||||
Rows[0] = lcVector3(1.0f-(Tyy+Tzz), Txy+Twz, Txz-Twy);
|
Rows[0] = lcVector3(1.0f-(Tyy+Tzz), Txy+Twz, Txz-Twy);
|
||||||
|
@ -1483,7 +1483,7 @@ inline lcVector3 lcProjectPoint(const lcVector3& Point, const lcMatrix44& ModelV
|
||||||
inline lcVector3 lcUnprojectPoint(const lcVector3& Point, const lcMatrix44& ModelView, const lcMatrix44& Projection, const int Viewport[4])
|
inline lcVector3 lcUnprojectPoint(const lcVector3& Point, const lcMatrix44& ModelView, const lcMatrix44& Projection, const int Viewport[4])
|
||||||
{
|
{
|
||||||
// Calculate the screen to model transform.
|
// Calculate the screen to model transform.
|
||||||
lcMatrix44 Transform = lcMatrix44Inverse(lcMul(ModelView, Projection));
|
const lcMatrix44 Transform = lcMatrix44Inverse(lcMul(ModelView, Projection));
|
||||||
|
|
||||||
lcVector4 Tmp;
|
lcVector4 Tmp;
|
||||||
|
|
||||||
|
@ -1504,7 +1504,7 @@ inline lcVector3 lcUnprojectPoint(const lcVector3& Point, const lcMatrix44& Mode
|
||||||
inline void lcUnprojectPoints(lcVector3* Points, int NumPoints, const lcMatrix44& ModelView, const lcMatrix44& Projection, const int Viewport[4])
|
inline void lcUnprojectPoints(lcVector3* Points, int NumPoints, const lcMatrix44& ModelView, const lcMatrix44& Projection, const int Viewport[4])
|
||||||
{
|
{
|
||||||
// Calculate the screen to model transform.
|
// Calculate the screen to model transform.
|
||||||
lcMatrix44 Transform = lcMatrix44Inverse(lcMul(ModelView, Projection));
|
const lcMatrix44 Transform = lcMatrix44Inverse(lcMul(ModelView, Projection));
|
||||||
|
|
||||||
for (int i = 0; i < NumPoints; i++)
|
for (int i = 0; i < NumPoints; i++)
|
||||||
{
|
{
|
||||||
|
@ -1556,8 +1556,8 @@ inline void lcGetFrustumPlanes(const lcMatrix44& WorldView, const lcMatrix44& Pr
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
lcVector3 Normal(Planes[i][0], Planes[i][1], Planes[i][2]);
|
const lcVector3 Normal(Planes[i][0], Planes[i][1], Planes[i][2]);
|
||||||
float Length = Normal.Length();
|
const float Length = Normal.Length();
|
||||||
Planes[i] /= -Length;
|
Planes[i] /= -Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1570,19 +1570,19 @@ inline std::tuple<lcVector3, float> lcZoomExtents(const lcVector3& Position, con
|
||||||
lcVector4 Planes[6];
|
lcVector4 Planes[6];
|
||||||
lcGetFrustumPlanes(WorldView, Projection, Planes);
|
lcGetFrustumPlanes(WorldView, Projection, Planes);
|
||||||
|
|
||||||
lcVector3 Front(WorldView[0][2], WorldView[1][2], WorldView[2][2]);
|
const lcVector3 Front(WorldView[0][2], WorldView[1][2], WorldView[2][2]);
|
||||||
|
|
||||||
float SmallestDistance = FLT_MAX;
|
float SmallestDistance = FLT_MAX;
|
||||||
|
|
||||||
for (int PlaneIdx = 0; PlaneIdx < 4; PlaneIdx++)
|
for (int PlaneIdx = 0; PlaneIdx < 4; PlaneIdx++)
|
||||||
{
|
{
|
||||||
lcVector3 Plane(Planes[PlaneIdx][0], Planes[PlaneIdx][1], Planes[PlaneIdx][2]);
|
const lcVector3 Plane(Planes[PlaneIdx][0], Planes[PlaneIdx][1], Planes[PlaneIdx][2]);
|
||||||
float ep = lcDot(Position, Plane);
|
const float ep = lcDot(Position, Plane);
|
||||||
float fp = lcDot(Front, Plane);
|
const float fp = lcDot(Front, Plane);
|
||||||
|
|
||||||
for (int PointIdx = 0; PointIdx < NumPoints; PointIdx++)
|
for (int PointIdx = 0; PointIdx < NumPoints; PointIdx++)
|
||||||
{
|
{
|
||||||
float u = (ep - lcDot(Points[PointIdx], Plane)) / fp;
|
const float u = (ep - lcDot(Points[PointIdx], Plane)) / fp;
|
||||||
|
|
||||||
if (u < SmallestDistance)
|
if (u < SmallestDistance)
|
||||||
SmallestDistance = u;
|
SmallestDistance = u;
|
||||||
|
@ -1595,7 +1595,7 @@ inline std::tuple<lcVector3, float> lcZoomExtents(const lcVector3& Position, con
|
||||||
|
|
||||||
for (int PointIdx = 0; PointIdx < NumPoints; PointIdx++)
|
for (int PointIdx = 0; PointIdx < NumPoints; PointIdx++)
|
||||||
{
|
{
|
||||||
float Distance = lcDot(Points[PointIdx], Front);
|
const float Distance = lcDot(Points[PointIdx], Front);
|
||||||
|
|
||||||
if (Distance > FarDistance)
|
if (Distance > FarDistance)
|
||||||
FarDistance = Distance;
|
FarDistance = Distance;
|
||||||
|
@ -1606,11 +1606,11 @@ inline std::tuple<lcVector3, float> lcZoomExtents(const lcVector3& Position, con
|
||||||
|
|
||||||
inline void lcClosestPointsBetweenLines(const lcVector3& Line1a, const lcVector3& Line1b, const lcVector3& Line2a, const lcVector3& Line2b, lcVector3* Intersection1, lcVector3* Intersection2)
|
inline void lcClosestPointsBetweenLines(const lcVector3& Line1a, const lcVector3& Line1b, const lcVector3& Line2a, const lcVector3& Line2b, lcVector3* Intersection1, lcVector3* Intersection2)
|
||||||
{
|
{
|
||||||
lcVector3 u1 = Line1b - Line1a;
|
const lcVector3 u1 = Line1b - Line1a;
|
||||||
lcVector3 u2 = Line2b - Line2a;
|
const lcVector3 u2 = Line2b - Line2a;
|
||||||
lcVector3 p21 = Line2a - Line1a;
|
const lcVector3 p21 = Line2a - Line1a;
|
||||||
lcVector3 m = lcCross(u2, u1);
|
const lcVector3 m = lcCross(u2, u1);
|
||||||
float m2 = lcDot(m, m);
|
const float m2 = lcDot(m, m);
|
||||||
|
|
||||||
if (m2 < 0.00001f)
|
if (m2 < 0.00001f)
|
||||||
{
|
{
|
||||||
|
@ -1621,33 +1621,33 @@ inline void lcClosestPointsBetweenLines(const lcVector3& Line1a, const lcVector3
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lcVector3 r = lcCross(p21, m / m2);
|
const lcVector3 r = lcCross(p21, m / m2);
|
||||||
|
|
||||||
if (Intersection1)
|
if (Intersection1)
|
||||||
{
|
{
|
||||||
float t1 = lcDot(r, u2);
|
const float t1 = lcDot(r, u2);
|
||||||
*Intersection1 = Line1a + t1 * u1;
|
*Intersection1 = Line1a + t1 * u1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Intersection2)
|
if (Intersection2)
|
||||||
{
|
{
|
||||||
float t2 = lcDot(r, u1);
|
const float t2 = lcDot(r, u1);
|
||||||
*Intersection2 = Line2a + t2 * u2;
|
*Intersection2 = Line2a + t2 * u2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool lcLineSegmentPlaneIntersection(lcVector3* Intersection, const lcVector3& Start, const lcVector3& End, const lcVector4& Plane)
|
inline bool lcLineSegmentPlaneIntersection(lcVector3* Intersection, const lcVector3& Start, const lcVector3& End, const lcVector4& Plane)
|
||||||
{
|
{
|
||||||
lcVector3 Dir = End - Start;
|
const lcVector3 Dir = End - Start;
|
||||||
lcVector3 PlaneNormal(Plane[0], Plane[1], Plane[2]);
|
const lcVector3 PlaneNormal(Plane[0], Plane[1], Plane[2]);
|
||||||
|
|
||||||
float t1 = lcDot(PlaneNormal, Start) + Plane[3];
|
const float t1 = lcDot(PlaneNormal, Start) + Plane[3];
|
||||||
float t2 = lcDot(PlaneNormal, Dir);
|
const float t2 = lcDot(PlaneNormal, Dir);
|
||||||
|
|
||||||
if (t2 == 0.0f)
|
if (t2 == 0.0f)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
float t = -t1 / t2;
|
const float t = -t1 / t2;
|
||||||
|
|
||||||
*Intersection = Start + t * Dir;
|
*Intersection = Start + t * Dir;
|
||||||
|
|
||||||
|
@ -1660,19 +1660,19 @@ inline bool lcLineSegmentPlaneIntersection(lcVector3* Intersection, const lcVect
|
||||||
inline bool lcLineTriangleMinIntersection(const lcVector3& p1, const lcVector3& p2, const lcVector3& p3, const lcVector3& Start, const lcVector3& End, float* MinDist, lcVector3* Intersection)
|
inline bool lcLineTriangleMinIntersection(const lcVector3& p1, const lcVector3& p2, const lcVector3& p3, const lcVector3& Start, const lcVector3& End, float* MinDist, lcVector3* Intersection)
|
||||||
{
|
{
|
||||||
// Calculate the polygon plane.
|
// Calculate the polygon plane.
|
||||||
lcVector3 PlaneNormal = lcCross(p1 - p2, p3 - p2);
|
const lcVector3 PlaneNormal = lcCross(p1 - p2, p3 - p2);
|
||||||
float PlaneD = -lcDot(PlaneNormal, p1);
|
const float PlaneD = -lcDot(PlaneNormal, p1);
|
||||||
|
|
||||||
// Check if the line is parallel to the plane.
|
// Check if the line is parallel to the plane.
|
||||||
lcVector3 Dir = End - Start;
|
const lcVector3 Dir = End - Start;
|
||||||
|
|
||||||
float t1 = lcDot(PlaneNormal, Start) + PlaneD;
|
const float t1 = lcDot(PlaneNormal, Start) + PlaneD;
|
||||||
float t2 = lcDot(PlaneNormal, Dir);
|
const float t2 = lcDot(PlaneNormal, Dir);
|
||||||
|
|
||||||
if (t2 == 0)
|
if (t2 == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
float t = -(t1 / t2);
|
const float t = -(t1 / t2);
|
||||||
|
|
||||||
if (t < 0)
|
if (t < 0)
|
||||||
return false;
|
return false;
|
||||||
|
@ -1696,7 +1696,7 @@ inline bool lcLineTriangleMinIntersection(const lcVector3& p1, const lcVector3&
|
||||||
a2 = lcDot(pa2, pa3);
|
a2 = lcDot(pa2, pa3);
|
||||||
a3 = lcDot(pa3, pa1);
|
a3 = lcDot(pa3, pa1);
|
||||||
|
|
||||||
float total = (acosf(a1) + acosf(a2) + acosf(a3)) * LC_RTOD;
|
const float total = (acosf(a1) + acosf(a2) + acosf(a3)) * LC_RTOD;
|
||||||
|
|
||||||
if (fabs(total - 360) <= 0.001f)
|
if (fabs(total - 360) <= 0.001f)
|
||||||
{
|
{
|
||||||
|
@ -1757,15 +1757,15 @@ inline void lcPolygonPlaneClip(lcVector3* InPoints, int NumInPoints, lcVector3*
|
||||||
// Return true if a polygon intersects a set of planes.
|
// Return true if a polygon intersects a set of planes.
|
||||||
inline bool lcTriangleIntersectsPlanes(const float* p1, const float* p2, const float* p3, const lcVector4 Planes[6])
|
inline bool lcTriangleIntersectsPlanes(const float* p1, const float* p2, const float* p3, const lcVector4 Planes[6])
|
||||||
{
|
{
|
||||||
const int NumPlanes = 6;
|
constexpr int NumPlanes = 6;
|
||||||
const float* Points[3] = { p1, p2, p3 };
|
const float* const Points[3] = { p1, p2, p3 };
|
||||||
int Outcodes[3] = { 0, 0, 0 }, i;
|
int Outcodes[3] = { 0, 0, 0 }, i;
|
||||||
int NumPoints = 3;
|
constexpr int NumPoints = 3;
|
||||||
|
|
||||||
// First do the Cohen-Sutherland out code test for trivial rejects/accepts.
|
// First do the Cohen-Sutherland out code test for trivial rejects/accepts.
|
||||||
for (i = 0; i < NumPoints; i++)
|
for (i = 0; i < NumPoints; i++)
|
||||||
{
|
{
|
||||||
lcVector3 Pt(Points[i][0], Points[i][1], Points[i][2]);
|
const lcVector3 Pt(Points[i][0], Points[i][1], Points[i][2]);
|
||||||
|
|
||||||
for (int j = 0; j < NumPlanes; j++)
|
for (int j = 0; j < NumPlanes; j++)
|
||||||
{
|
{
|
||||||
|
@ -1892,9 +1892,9 @@ inline bool lcBoundingBoxRayIntersectDistance(const lcVector3& Min, const lcVect
|
||||||
|
|
||||||
inline bool lcSphereRayMinIntersectDistance(const lcVector3& Center, float Radius, const lcVector3& Start, const lcVector3& End, float* Dist)
|
inline bool lcSphereRayMinIntersectDistance(const lcVector3& Center, float Radius, const lcVector3& Start, const lcVector3& End, float* Dist)
|
||||||
{
|
{
|
||||||
lcVector3 Dir = Center - Start;
|
const lcVector3 Dir = Center - Start;
|
||||||
float LengthSquaredDir = lcLengthSquared(Dir);
|
const float LengthSquaredDir = lcLengthSquared(Dir);
|
||||||
float RadiusSquared = Radius * Radius;
|
const float RadiusSquared = Radius * Radius;
|
||||||
|
|
||||||
if (LengthSquaredDir < RadiusSquared)
|
if (LengthSquaredDir < RadiusSquared)
|
||||||
{
|
{
|
||||||
|
@ -1904,14 +1904,14 @@ inline bool lcSphereRayMinIntersectDistance(const lcVector3& Center, float Radiu
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lcVector3 RayDir = End - Start;
|
const lcVector3 RayDir = End - Start;
|
||||||
float t = lcDot(Dir, RayDir) / lcLengthSquared(RayDir);
|
float t = lcDot(Dir, RayDir) / lcLengthSquared(RayDir);
|
||||||
|
|
||||||
// Ray points away from sphere.
|
// Ray points away from sphere.
|
||||||
if (t < 0)
|
if (t < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
float c = (RadiusSquared - LengthSquaredDir) / lcLengthSquared(RayDir) + (t * t);
|
const float c = (RadiusSquared - LengthSquaredDir) / lcLengthSquared(RayDir) + (t * t);
|
||||||
if (c > 0)
|
if (c > 0)
|
||||||
{
|
{
|
||||||
*Dist = t - sqrtf(c);
|
*Dist = t - sqrtf(c);
|
||||||
|
@ -1924,8 +1924,8 @@ inline bool lcSphereRayMinIntersectDistance(const lcVector3& Center, float Radiu
|
||||||
|
|
||||||
inline lcVector3 lcRayPointClosestPoint(const lcVector3& Point, const lcVector3& Start, const lcVector3& End)
|
inline lcVector3 lcRayPointClosestPoint(const lcVector3& Point, const lcVector3& Start, const lcVector3& End)
|
||||||
{
|
{
|
||||||
lcVector3 Dir = Point - Start;
|
const lcVector3 Dir = Point - Start;
|
||||||
lcVector3 RayDir = End - Start;
|
const lcVector3 RayDir = End - Start;
|
||||||
|
|
||||||
float t = lcDot(Dir, RayDir) / lcLengthSquared(RayDir);
|
float t = lcDot(Dir, RayDir) / lcLengthSquared(RayDir);
|
||||||
t = lcClamp(t, 0.0f, 1.0f);
|
t = lcClamp(t, 0.0f, 1.0f);
|
||||||
|
@ -1935,7 +1935,7 @@ inline lcVector3 lcRayPointClosestPoint(const lcVector3& Point, const lcVector3&
|
||||||
|
|
||||||
inline float lcRayPointDistance(const lcVector3& Point, const lcVector3& Start, const lcVector3& End)
|
inline float lcRayPointDistance(const lcVector3& Point, const lcVector3& Start, const lcVector3& End)
|
||||||
{
|
{
|
||||||
lcVector3 Closest = lcRayPointClosestPoint(Point, Start, End);
|
const lcVector3 Closest = lcRayPointClosestPoint(Point, Start, End);
|
||||||
|
|
||||||
return lcLength(Closest - Point);
|
return lcLength(Closest - Point);
|
||||||
}
|
}
|
||||||
|
@ -1943,7 +1943,7 @@ inline float lcRayPointDistance(const lcVector3& Point, const lcVector3& Start,
|
||||||
// Returns true if the axis aligned box intersects the volume defined by planes.
|
// Returns true if the axis aligned box intersects the volume defined by planes.
|
||||||
inline bool lcBoundingBoxIntersectsVolume(const lcVector3& Min, const lcVector3& Max, const lcVector4 Planes[6])
|
inline bool lcBoundingBoxIntersectsVolume(const lcVector3& Min, const lcVector3& Max, const lcVector4 Planes[6])
|
||||||
{
|
{
|
||||||
const int NumPlanes = 6;
|
constexpr int NumPlanes = 6;
|
||||||
lcVector3 Points[8] =
|
lcVector3 Points[8] =
|
||||||
{
|
{
|
||||||
Points[0] = lcVector3(Min[0], Min[1], Min[2]),
|
Points[0] = lcVector3(Min[0], Min[1], Min[2]),
|
||||||
|
|
|
@ -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* Verts = (lcVertex*)mVertexData;
|
lcVertex* const Verts = (lcVertex*)mVertexData;
|
||||||
bool Hit = false;
|
bool Hit = false;
|
||||||
lcVector3 Intersection;
|
lcVector3 Intersection;
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ void lcMesh::ExportPOVRay(lcFile& File, const char* MeshName, const char** Color
|
||||||
|
|
||||||
for (int SectionIdx = 0; SectionIdx < mLods[LC_MESH_LOD_HIGH].NumSections; SectionIdx++)
|
for (int SectionIdx = 0; SectionIdx < mLods[LC_MESH_LOD_HIGH].NumSections; SectionIdx++)
|
||||||
{
|
{
|
||||||
lcMeshSection* Section = &mLods[LC_MESH_LOD_HIGH].Sections[SectionIdx];
|
const lcMeshSection* const Section = &mLods[LC_MESH_LOD_HIGH].Sections[SectionIdx];
|
||||||
|
|
||||||
if (Section->PrimitiveType == LC_MESH_TRIANGLES || Section->PrimitiveType == LC_MESH_TEXTURED_TRIANGLES)
|
if (Section->PrimitiveType == LC_MESH_TRIANGLES || Section->PrimitiveType == LC_MESH_TEXTURED_TRIANGLES)
|
||||||
NumSections++;
|
NumSections++;
|
||||||
|
@ -277,7 +277,7 @@ void lcMesh::ExportPOVRay(lcFile& File, const char* MeshName, const char** Color
|
||||||
sprintf(Line, "#declare lc_%s = mesh {\n", MeshName);
|
sprintf(Line, "#declare lc_%s = mesh {\n", MeshName);
|
||||||
File.WriteLine(Line);
|
File.WriteLine(Line);
|
||||||
|
|
||||||
lcVertex* Verts = (lcVertex*)mVertexData;
|
const lcVertex* const Verts = (lcVertex*)mVertexData;
|
||||||
|
|
||||||
for (int SectionIdx = 0; SectionIdx < mLods[LC_MESH_LOD_HIGH].NumSections; SectionIdx++)
|
for (int SectionIdx = 0; SectionIdx < mLods[LC_MESH_LOD_HIGH].NumSections; SectionIdx++)
|
||||||
{
|
{
|
||||||
|
@ -348,9 +348,9 @@ void lcMesh::ExportWavefrontIndices(lcFile& File, int DefaultColorIndex, int Ver
|
||||||
|
|
||||||
for (int Idx = 0; Idx < Section->NumIndices; Idx += 3)
|
for (int Idx = 0; Idx < Section->NumIndices; Idx += 3)
|
||||||
{
|
{
|
||||||
long int idx1 = Indices[Idx + 0] + VertexOffset;
|
const long int idx1 = Indices[Idx + 0] + VertexOffset;
|
||||||
long int idx2 = Indices[Idx + 1] + VertexOffset;
|
const long int idx2 = Indices[Idx + 1] + VertexOffset;
|
||||||
long int idx3 = Indices[Idx + 2] + VertexOffset;
|
const long int idx3 = Indices[Idx + 2] + VertexOffset;
|
||||||
|
|
||||||
if (idx1 != idx2 && idx1 != idx3 && idx2 != idx3)
|
if (idx1 != idx2 && idx1 != idx3 && idx2 != idx3)
|
||||||
sprintf(Line, "f %ld//%ld %ld//%ld %ld//%ld\n", idx1, idx1, idx2, idx2, idx3, idx3);
|
sprintf(Line, "f %ld//%ld %ld//%ld %ld//%ld\n", idx1, idx1, idx2, idx2, idx3, idx3);
|
||||||
|
@ -461,7 +461,7 @@ bool lcMesh::FileSave(lcMemFile& File)
|
||||||
{
|
{
|
||||||
for (int SectionIdx = 0; SectionIdx < mLods[LodIdx].NumSections; SectionIdx++)
|
for (int SectionIdx = 0; SectionIdx < mLods[LodIdx].NumSections; SectionIdx++)
|
||||||
{
|
{
|
||||||
lcMeshSection& Section = mLods[LodIdx].Sections[SectionIdx];
|
const lcMeshSection& Section = mLods[LodIdx].Sections[SectionIdx];
|
||||||
|
|
||||||
File.WriteU32(lcGetColorCode(Section.ColorIndex));
|
File.WriteU32(lcGetColorCode(Section.ColorIndex));
|
||||||
File.WriteU32(Section.IndexOffset);
|
File.WriteU32(Section.IndexOffset);
|
||||||
|
@ -473,7 +473,7 @@ bool lcMesh::FileSave(lcMemFile& File)
|
||||||
|
|
||||||
if (Section.Texture)
|
if (Section.Texture)
|
||||||
{
|
{
|
||||||
quint16 Length = (quint16)strlen(Section.Texture->mName);
|
const quint16 Length = (quint16)strlen(Section.Texture->mName);
|
||||||
File.WriteU16(Length);
|
File.WriteU16(Length);
|
||||||
File.WriteBuffer(Section.Texture->mName, Length);
|
File.WriteBuffer(Section.Texture->mName, Length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,13 @@ void lcScene::Begin(const lcMatrix44& ViewMatrix)
|
||||||
|
|
||||||
void lcScene::End()
|
void lcScene::End()
|
||||||
{
|
{
|
||||||
auto OpaqueMeshCompare = [this](int Index1, int Index2)
|
const auto OpaqueMeshCompare = [this](int Index1, int Index2)
|
||||||
{
|
{
|
||||||
const lcMesh* Mesh1 = mRenderMeshes[Index1].Mesh;
|
const lcMesh* Mesh1 = mRenderMeshes[Index1].Mesh;
|
||||||
const lcMesh* Mesh2 = mRenderMeshes[Index2].Mesh;
|
const lcMesh* Mesh2 = mRenderMeshes[Index2].Mesh;
|
||||||
|
|
||||||
int Texture1 = Mesh1->mFlags & lcMeshFlag::HasTexture;
|
const int Texture1 = Mesh1->mFlags & lcMeshFlag::HasTexture;
|
||||||
int Texture2 = Mesh2->mFlags & lcMeshFlag::HasTexture;
|
const int Texture2 = Mesh2->mFlags & lcMeshFlag::HasTexture;
|
||||||
|
|
||||||
if (Texture1 == Texture2)
|
if (Texture1 == Texture2)
|
||||||
return Mesh1 < Mesh2;
|
return Mesh1 < Mesh2;
|
||||||
|
@ -62,11 +62,11 @@ void lcScene::AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorInde
|
||||||
RenderMesh.Mesh = Mesh;
|
RenderMesh.Mesh = Mesh;
|
||||||
RenderMesh.ColorIndex = ColorIndex;
|
RenderMesh.ColorIndex = ColorIndex;
|
||||||
RenderMesh.State = State;
|
RenderMesh.State = State;
|
||||||
float Distance = fabsf(lcMul31(WorldMatrix[3], mViewMatrix).z);
|
const float Distance = fabsf(lcMul31(WorldMatrix[3], mViewMatrix).z);
|
||||||
RenderMesh.LodIndex = mAllowLOD ? RenderMesh.Mesh->GetLodIndex(Distance) : LC_MESH_LOD_HIGH;
|
RenderMesh.LodIndex = mAllowLOD ? RenderMesh.Mesh->GetLodIndex(Distance) : LC_MESH_LOD_HIGH;
|
||||||
|
|
||||||
bool Translucent = lcIsColorTranslucent(ColorIndex);
|
const bool Translucent = lcIsColorTranslucent(ColorIndex);
|
||||||
lcMeshFlags Flags = Mesh->mFlags;
|
const lcMeshFlags Flags = Mesh->mFlags;
|
||||||
|
|
||||||
if ((Flags & (lcMeshFlag::HasSolid | lcMeshFlag::HasLines)) || ((Flags & lcMeshFlag::HasDefault) && !Translucent))
|
if ((Flags & (lcMeshFlag::HasSolid | lcMeshFlag::HasLines)) || ((Flags & lcMeshFlag::HasDefault) && !Translucent))
|
||||||
mOpaqueMeshes.Add(mRenderMeshes.GetSize() - 1);
|
mOpaqueMeshes.Add(mRenderMeshes.GetSize() - 1);
|
||||||
|
@ -90,8 +90,8 @@ void lcScene::AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorInde
|
||||||
if (!lcIsColorTranslucent(SectionColorIndex))
|
if (!lcIsColorTranslucent(SectionColorIndex))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
lcVector3 Center = (Section->BoundingBox.Min + Section->BoundingBox.Max) / 2;
|
const lcVector3 Center = (Section->BoundingBox.Min + Section->BoundingBox.Max) / 2;
|
||||||
float InstanceDistance = fabsf(lcMul31(lcMul31(Center, WorldMatrix), mViewMatrix).z);
|
const float InstanceDistance = fabsf(lcMul31(lcMul31(Center, WorldMatrix), mViewMatrix).z);
|
||||||
|
|
||||||
lcTranslucentMeshInstance& Instance = mTranslucentMeshes.Add();
|
lcTranslucentMeshInstance& Instance = mTranslucentMeshes.Add();
|
||||||
Instance.Section = Section;
|
Instance.Section = Section;
|
||||||
|
@ -101,10 +101,10 @@ void lcScene::AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorInde
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcScene::DrawDebugNormals(lcContext* Context, lcMesh* Mesh) const
|
void lcScene::DrawDebugNormals(lcContext* Context, const lcMesh* Mesh) const
|
||||||
{
|
{
|
||||||
lcVertex* VertexBuffer = (lcVertex*)Mesh->mVertexData;
|
const lcVertex* const VertexBuffer = (lcVertex*)Mesh->mVertexData;
|
||||||
lcVector3* Vertices = (lcVector3*)malloc(Mesh->mNumVertices * 2 * sizeof(lcVector3));
|
lcVector3* const Vertices = (lcVector3*)malloc(Mesh->mNumVertices * 2 * sizeof(lcVector3));
|
||||||
|
|
||||||
for (int VertexIdx = 0; VertexIdx < Mesh->mNumVertices; VertexIdx++)
|
for (int VertexIdx = 0; VertexIdx < Mesh->mNumVertices; VertexIdx++)
|
||||||
{
|
{
|
||||||
|
@ -138,18 +138,18 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy
|
||||||
|
|
||||||
Context->SetPolygonOffset(lcPolygonOffset::Opaque);
|
Context->SetPolygonOffset(lcPolygonOffset::Opaque);
|
||||||
|
|
||||||
for (int MeshIndex : mOpaqueMeshes)
|
for (const int MeshIndex : mOpaqueMeshes)
|
||||||
{
|
{
|
||||||
const lcRenderMesh& RenderMesh = mRenderMeshes[MeshIndex];
|
const lcRenderMesh& RenderMesh = mRenderMeshes[MeshIndex];
|
||||||
const lcMesh* Mesh = RenderMesh.Mesh;
|
const lcMesh* Mesh = RenderMesh.Mesh;
|
||||||
int LodIndex = RenderMesh.LodIndex;
|
const int LodIndex = RenderMesh.LodIndex;
|
||||||
|
|
||||||
Context->BindMesh(Mesh);
|
Context->BindMesh(Mesh);
|
||||||
Context->SetWorldMatrix(RenderMesh.WorldMatrix);
|
Context->SetWorldMatrix(RenderMesh.WorldMatrix);
|
||||||
|
|
||||||
for (int SectionIdx = 0; SectionIdx < Mesh->mLods[LodIndex].NumSections; SectionIdx++)
|
for (int SectionIdx = 0; SectionIdx < Mesh->mLods[LodIndex].NumSections; SectionIdx++)
|
||||||
{
|
{
|
||||||
lcMeshSection* Section = &Mesh->mLods[LodIndex].Sections[SectionIdx];
|
const lcMeshSection* const Section = &Mesh->mLods[LodIndex].Sections[SectionIdx];
|
||||||
|
|
||||||
if ((Section->PrimitiveType & PrimitiveTypes) == 0)
|
if ((Section->PrimitiveType & PrimitiveTypes) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -214,23 +214,23 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy
|
||||||
}
|
}
|
||||||
else if (Section->PrimitiveType == LC_MESH_CONDITIONAL_LINES)
|
else if (Section->PrimitiveType == LC_MESH_CONDITIONAL_LINES)
|
||||||
{
|
{
|
||||||
lcMatrix44 WorldViewProjectionMatrix = lcMul(RenderMesh.WorldMatrix, lcMul(mViewMatrix, Context->GetProjectionMatrix()));
|
const lcMatrix44 WorldViewProjectionMatrix = lcMul(RenderMesh.WorldMatrix, lcMul(mViewMatrix, Context->GetProjectionMatrix()));
|
||||||
lcVertex* VertexBuffer = (lcVertex*)Mesh->mVertexData;
|
const lcVertex* const VertexBuffer = (lcVertex*)Mesh->mVertexData;
|
||||||
int IndexBufferOffset = Mesh->mIndexCacheOffset != -1 ? Mesh->mIndexCacheOffset : 0;
|
const int IndexBufferOffset = Mesh->mIndexCacheOffset != -1 ? Mesh->mIndexCacheOffset : 0;
|
||||||
|
|
||||||
int VertexBufferOffset = Mesh->mVertexCacheOffset != -1 ? Mesh->mVertexCacheOffset : 0;
|
const int VertexBufferOffset = Mesh->mVertexCacheOffset != -1 ? Mesh->mVertexCacheOffset : 0;
|
||||||
Context->SetVertexFormat(VertexBufferOffset, 3, 1, 0, 0, DrawLit);
|
Context->SetVertexFormat(VertexBufferOffset, 3, 1, 0, 0, DrawLit);
|
||||||
|
|
||||||
if (Mesh->mIndexType == GL_UNSIGNED_SHORT)
|
if (Mesh->mIndexType == GL_UNSIGNED_SHORT)
|
||||||
{
|
{
|
||||||
quint16* Indices = (quint16*)((char*)Mesh->mIndexData + Section->IndexOffset);
|
const quint16* const Indices = (quint16*)((char*)Mesh->mIndexData + Section->IndexOffset);
|
||||||
|
|
||||||
for (int i = 0; i < Section->NumIndices; i += 4)
|
for (int i = 0; i < Section->NumIndices; i += 4)
|
||||||
{
|
{
|
||||||
lcVector3 p1 = lcMul31(VertexBuffer[Indices[i + 0]].Position, WorldViewProjectionMatrix);
|
const lcVector3 p1 = lcMul31(VertexBuffer[Indices[i + 0]].Position, WorldViewProjectionMatrix);
|
||||||
lcVector3 p2 = lcMul31(VertexBuffer[Indices[i + 1]].Position, WorldViewProjectionMatrix);
|
const lcVector3 p2 = lcMul31(VertexBuffer[Indices[i + 1]].Position, WorldViewProjectionMatrix);
|
||||||
lcVector3 p3 = lcMul31(VertexBuffer[Indices[i + 2]].Position, WorldViewProjectionMatrix);
|
const lcVector3 p3 = lcMul31(VertexBuffer[Indices[i + 2]].Position, WorldViewProjectionMatrix);
|
||||||
lcVector3 p4 = lcMul31(VertexBuffer[Indices[i + 3]].Position, WorldViewProjectionMatrix);
|
const lcVector3 p4 = lcMul31(VertexBuffer[Indices[i + 3]].Position, WorldViewProjectionMatrix);
|
||||||
|
|
||||||
if (((p1.y - p2.y) * (p3.x - p1.x) + (p2.x - p1.x) * (p3.y - p1.y)) * ((p1.y - p2.y) * (p4.x - p1.x) + (p2.x - p1.x) * (p4.y - p1.y)) >= 0)
|
if (((p1.y - p2.y) * (p3.x - p1.x) + (p2.x - p1.x) * (p3.y - p1.y)) * ((p1.y - p2.y) * (p4.x - p1.x) + (p2.x - p1.x) * (p4.y - p1.y)) >= 0)
|
||||||
Context->DrawIndexedPrimitives(GL_LINES, 2, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset + i * sizeof(quint16));
|
Context->DrawIndexedPrimitives(GL_LINES, 2, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset + i * sizeof(quint16));
|
||||||
|
@ -238,14 +238,14 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
quint32* Indices = (quint32*)((char*)Mesh->mIndexData + Section->IndexOffset);
|
const quint32* const Indices = (quint32*)((char*)Mesh->mIndexData + Section->IndexOffset);
|
||||||
|
|
||||||
for (int i = 0; i < Section->NumIndices; i += 4)
|
for (int i = 0; i < Section->NumIndices; i += 4)
|
||||||
{
|
{
|
||||||
lcVector3 p1 = lcMul31(VertexBuffer[Indices[i + 0]].Position, WorldViewProjectionMatrix);
|
const lcVector3 p1 = lcMul31(VertexBuffer[Indices[i + 0]].Position, WorldViewProjectionMatrix);
|
||||||
lcVector3 p2 = lcMul31(VertexBuffer[Indices[i + 1]].Position, WorldViewProjectionMatrix);
|
const lcVector3 p2 = lcMul31(VertexBuffer[Indices[i + 1]].Position, WorldViewProjectionMatrix);
|
||||||
lcVector3 p3 = lcMul31(VertexBuffer[Indices[i + 2]].Position, WorldViewProjectionMatrix);
|
const lcVector3 p3 = lcMul31(VertexBuffer[Indices[i + 2]].Position, WorldViewProjectionMatrix);
|
||||||
lcVector3 p4 = lcMul31(VertexBuffer[Indices[i + 3]].Position, WorldViewProjectionMatrix);
|
const lcVector3 p4 = lcMul31(VertexBuffer[Indices[i + 3]].Position, WorldViewProjectionMatrix);
|
||||||
|
|
||||||
if (((p1.y - p2.y) * (p3.x - p1.x) + (p2.x - p1.x) * (p3.y - p1.y)) * ((p1.y - p2.y) * (p4.x - p1.x) + (p2.x - p1.x) * (p4.y - p1.y)) >= 0)
|
if (((p1.y - p2.y) * (p3.x - p1.x) + (p2.x - p1.x) * (p3.y - p1.y)) * ((p1.y - p2.y) * (p4.x - p1.x) + (p2.x - p1.x) * (p4.y - p1.y)) >= 0)
|
||||||
Context->DrawIndexedPrimitives(GL_LINES, 2, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset + i * sizeof(quint32));
|
Context->DrawIndexedPrimitives(GL_LINES, 2, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset + i * sizeof(quint32));
|
||||||
|
@ -255,9 +255,9 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
lcTexture* Texture = Section->Texture;
|
const lcTexture* const Texture = Section->Texture;
|
||||||
int VertexBufferOffset = Mesh->mVertexCacheOffset != -1 ? Mesh->mVertexCacheOffset : 0;
|
int VertexBufferOffset = Mesh->mVertexCacheOffset != -1 ? Mesh->mVertexCacheOffset : 0;
|
||||||
int IndexBufferOffset = Mesh->mIndexCacheOffset != -1 ? Mesh->mIndexCacheOffset : 0;
|
const int IndexBufferOffset = Mesh->mIndexCacheOffset != -1 ? Mesh->mIndexCacheOffset : 0;
|
||||||
|
|
||||||
if (!Texture)
|
if (!Texture)
|
||||||
{
|
{
|
||||||
|
@ -272,7 +272,7 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy
|
||||||
Context->BindTexture2D(Texture->mTexture);
|
Context->BindTexture2D(Texture->mTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum DrawPrimitiveType = Section->PrimitiveType & (LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES) ? GL_TRIANGLES : GL_LINES;
|
const GLenum DrawPrimitiveType = Section->PrimitiveType & (LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES) ? GL_TRIANGLES : GL_LINES;
|
||||||
Context->DrawIndexedPrimitives(DrawPrimitiveType, Section->NumIndices, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset);
|
Context->DrawIndexedPrimitives(DrawPrimitiveType, Section->NumIndices, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,9 +342,9 @@ void lcScene::DrawTranslucentMeshes(lcContext* Context, bool DrawLit) const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
lcTexture* Texture = Section->Texture;
|
const lcTexture* Texture = Section->Texture;
|
||||||
int VertexBufferOffset = Mesh->mVertexCacheOffset != -1 ? Mesh->mVertexCacheOffset : 0;
|
int VertexBufferOffset = Mesh->mVertexCacheOffset != -1 ? Mesh->mVertexCacheOffset : 0;
|
||||||
int IndexBufferOffset = Mesh->mIndexCacheOffset != -1 ? Mesh->mIndexCacheOffset : 0;
|
const int IndexBufferOffset = Mesh->mIndexCacheOffset != -1 ? Mesh->mIndexCacheOffset : 0;
|
||||||
|
|
||||||
if (!Texture)
|
if (!Texture)
|
||||||
{
|
{
|
||||||
|
@ -359,7 +359,7 @@ void lcScene::DrawTranslucentMeshes(lcContext* Context, bool DrawLit) const
|
||||||
Context->BindTexture2D(Texture->mTexture);
|
Context->BindTexture2D(Texture->mTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum DrawPrimitiveType = Section->PrimitiveType & (LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES) ? GL_TRIANGLES : GL_LINES;
|
const GLenum DrawPrimitiveType = Section->PrimitiveType & (LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES) ? GL_TRIANGLES : GL_LINES;
|
||||||
Context->DrawIndexedPrimitives(DrawPrimitiveType, Section->NumIndices, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset);
|
Context->DrawIndexedPrimitives(DrawPrimitiveType, Section->NumIndices, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset);
|
||||||
|
|
||||||
#ifdef LC_DEBUG_NORMALS
|
#ifdef LC_DEBUG_NORMALS
|
||||||
|
@ -382,7 +382,7 @@ void lcScene::Draw(lcContext* Context) const
|
||||||
|
|
||||||
Context->SetViewMatrix(mViewMatrix);
|
Context->SetViewMatrix(mViewMatrix);
|
||||||
|
|
||||||
const bool DrawConditional = false;
|
constexpr bool DrawConditional = false;
|
||||||
const lcPreferences& Preferences = lcGetPreferences();
|
const lcPreferences& Preferences = lcGetPreferences();
|
||||||
|
|
||||||
lcShadingMode ShadingMode = Preferences.mShadingMode;
|
lcShadingMode ShadingMode = Preferences.mShadingMode;
|
||||||
|
@ -403,7 +403,7 @@ void lcScene::Draw(lcContext* Context) const
|
||||||
}
|
}
|
||||||
else if (ShadingMode == lcShadingMode::Flat)
|
else if (ShadingMode == lcShadingMode::Flat)
|
||||||
{
|
{
|
||||||
bool DrawLines = Preferences.mDrawEdgeLines && Preferences.mLineWidth != 0.0f;
|
const bool DrawLines = Preferences.mDrawEdgeLines && Preferences.mLineWidth != 0.0f;
|
||||||
|
|
||||||
int PrimitiveTypes = LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES;
|
int PrimitiveTypes = LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES;
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ void lcScene::Draw(lcContext* Context) const
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool DrawLines = Preferences.mDrawEdgeLines && Preferences.mLineWidth != 0.0f;
|
const bool DrawLines = Preferences.mDrawEdgeLines && Preferences.mLineWidth != 0.0f;
|
||||||
|
|
||||||
if (DrawLines)
|
if (DrawLines)
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTypes) const;
|
void DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTypes) const;
|
||||||
void DrawTranslucentMeshes(lcContext* Context, bool DrawLit) const;
|
void DrawTranslucentMeshes(lcContext* Context, bool DrawLit) const;
|
||||||
void DrawDebugNormals(lcContext* Context, lcMesh* Mesh) const;
|
void DrawDebugNormals(lcContext* Context, const lcMesh* Mesh) const;
|
||||||
|
|
||||||
lcMatrix44 mViewMatrix;
|
lcMatrix44 mViewMatrix;
|
||||||
lcMatrix44 mActiveSubmodelTransform;
|
lcMatrix44 mActiveSubmodelTransform;
|
||||||
|
|
|
@ -45,7 +45,7 @@ lcTexture::~lcTexture()
|
||||||
|
|
||||||
void lcTexture::CreateGridTexture()
|
void lcTexture::CreateGridTexture()
|
||||||
{
|
{
|
||||||
const int NumLevels = 9;
|
constexpr int NumLevels = 9;
|
||||||
mImages.resize(NumLevels);
|
mImages.resize(NumLevels);
|
||||||
quint8* Previous = nullptr;
|
quint8* Previous = nullptr;
|
||||||
|
|
||||||
|
@ -57,30 +57,30 @@ void lcTexture::CreateGridTexture()
|
||||||
|
|
||||||
if (Previous)
|
if (Previous)
|
||||||
{
|
{
|
||||||
int PreviousGridSize = 2 * GridSize;
|
const int PreviousGridSize = 2 * GridSize;
|
||||||
|
|
||||||
for (int y = 0; y < GridSize - 1; y++)
|
for (int y = 0; y < GridSize - 1; y++)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < GridSize - 1; x++)
|
for (int x = 0; x < GridSize - 1; x++)
|
||||||
{
|
{
|
||||||
quint8 a = Previous[x * 2 + y * 2 * PreviousGridSize] > 64 ? 255 : 0;
|
const quint8 a = Previous[x * 2 + y * 2 * PreviousGridSize] > 64 ? 255 : 0;
|
||||||
quint8 b = Previous[x * 2 + 1 + y * 2 * PreviousGridSize] > 64 ? 255 : 0;
|
const quint8 b = Previous[x * 2 + 1 + y * 2 * PreviousGridSize] > 64 ? 255 : 0;
|
||||||
quint8 c = Previous[x * 2 + (y * 2 + 1) * PreviousGridSize] > 64 ? 255 : 0;
|
const quint8 c = Previous[x * 2 + (y * 2 + 1) * PreviousGridSize] > 64 ? 255 : 0;
|
||||||
quint8 d = Previous[x * 2 + 1 + (y * 2 + 1) * PreviousGridSize] > 64 ? 255 : 0;
|
const quint8 d = Previous[x * 2 + 1 + (y * 2 + 1) * PreviousGridSize] > 64 ? 255 : 0;
|
||||||
GridImage.mData[x + y * GridSize] = (a + b + c + d) / 4;
|
GridImage.mData[x + y * GridSize] = (a + b + c + d) / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = GridSize - 1;
|
int x = GridSize - 1;
|
||||||
quint8 a = Previous[x * 2 + y * 2 * PreviousGridSize];
|
const quint8 a = Previous[x * 2 + y * 2 * PreviousGridSize];
|
||||||
quint8 c = Previous[x * 2 + (y * 2 + 1) * PreviousGridSize];
|
const quint8 c = Previous[x * 2 + (y * 2 + 1) * PreviousGridSize];
|
||||||
GridImage.mData[x + y * GridSize] = (a + c) / 2;
|
GridImage.mData[x + y * GridSize] = (a + c) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int y = GridSize - 1;
|
int y = GridSize - 1;
|
||||||
for (int x = 0; x < GridSize - 1; x++)
|
for (int x = 0; x < GridSize - 1; x++)
|
||||||
{
|
{
|
||||||
quint8 a = Previous[x * 2 + y * 2 * PreviousGridSize];
|
const quint8 a = Previous[x * 2 + y * 2 * PreviousGridSize];
|
||||||
quint8 b = Previous[x * 2 + 1 + y * 2 * PreviousGridSize];
|
const quint8 b = Previous[x * 2 + 1 + y * 2 * PreviousGridSize];
|
||||||
GridImage.mData[x + y * GridSize] = (a + b) / 2;
|
GridImage.mData[x + y * GridSize] = (a + b) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,15 +105,15 @@ void lcTexture::CreateGridTexture()
|
||||||
|
|
||||||
if (Radius2 <= y2)
|
if (Radius2 <= y2)
|
||||||
{
|
{
|
||||||
int x1 = sqrtf(Radius1 - y2);
|
const int x1 = sqrtf(Radius1 - y2);
|
||||||
|
|
||||||
for (int x = GridSize / 2 - x1; x < GridSize / 2 + x1; x++)
|
for (int x = GridSize / 2 - x1; x < GridSize / 2 + x1; x++)
|
||||||
Pixel[x] = 255;
|
Pixel[x] = 255;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int x1 = sqrtf(Radius1 - y2);
|
const int x1 = sqrtf(Radius1 - y2);
|
||||||
int x2 = sqrtf(Radius2 - y2);
|
const int x2 = sqrtf(Radius2 - y2);
|
||||||
|
|
||||||
for (int x = GridSize / 2 - x1; x < GridSize / 2 - x2; x++)
|
for (int x = GridSize / 2 - x1; x < GridSize / 2 - x2; x++)
|
||||||
Pixel[x] = 255;
|
Pixel[x] = 255;
|
||||||
|
@ -127,24 +127,24 @@ void lcTexture::CreateGridTexture()
|
||||||
{
|
{
|
||||||
for (int x = 0; x < GridSize - 1; x++)
|
for (int x = 0; x < GridSize - 1; x++)
|
||||||
{
|
{
|
||||||
quint8 a = TempBuffer[x + y * GridSize];
|
const quint8 a = TempBuffer[x + y * GridSize];
|
||||||
quint8 b = TempBuffer[x + 1 + y * GridSize];
|
const quint8 b = TempBuffer[x + 1 + y * GridSize];
|
||||||
quint8 c = TempBuffer[x + (y + 1) * GridSize];
|
const quint8 c = TempBuffer[x + (y + 1) * GridSize];
|
||||||
quint8 d = TempBuffer[x + 1 + (y + 1) * GridSize];
|
const quint8 d = TempBuffer[x + 1 + (y + 1) * GridSize];
|
||||||
GridImage.mData[x + y * GridSize] = (a + b + c + d) / 4;
|
GridImage.mData[x + y * GridSize] = (a + b + c + d) / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = GridSize - 1;
|
int x = GridSize - 1;
|
||||||
quint8 a = TempBuffer[x + y * GridSize];
|
const quint8 a = TempBuffer[x + y * GridSize];
|
||||||
quint8 c = TempBuffer[x + (y + 1) * GridSize];
|
const quint8 c = TempBuffer[x + (y + 1) * GridSize];
|
||||||
GridImage.mData[x + y * GridSize] = (a + c) / 2;
|
GridImage.mData[x + y * GridSize] = (a + c) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int y = GridSize - 1;
|
int y = GridSize - 1;
|
||||||
for (int x = 0; x < GridSize - 1; x++)
|
for (int x = 0; x < GridSize - 1; x++)
|
||||||
{
|
{
|
||||||
quint8 a = TempBuffer[x + y * GridSize];
|
const quint8 a = TempBuffer[x + y * GridSize];
|
||||||
quint8 b = TempBuffer[x + 1 + y * GridSize];
|
const quint8 b = TempBuffer[x + 1 + y * GridSize];
|
||||||
GridImage.mData[x + y * GridSize] = (a + b) / 2;
|
GridImage.mData[x + y * GridSize] = (a + b) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,15 +210,15 @@ void lcTexture::Upload(lcContext* Context)
|
||||||
if (!mTexture)
|
if (!mTexture)
|
||||||
glGenTextures(1, &mTexture);
|
glGenTextures(1, &mTexture);
|
||||||
|
|
||||||
int Filters[2][5] =
|
constexpr int Filters[2][5] =
|
||||||
{
|
{
|
||||||
{ GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR },
|
{ GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR },
|
||||||
{ GL_NEAREST, GL_LINEAR, GL_LINEAR, GL_LINEAR, GL_LINEAR },
|
{ GL_NEAREST, GL_LINEAR, GL_LINEAR, GL_LINEAR, GL_LINEAR },
|
||||||
};
|
};
|
||||||
|
|
||||||
int FilterFlags = mFlags & LC_TEXTURE_FILTER_MASK;
|
const int FilterFlags = mFlags & LC_TEXTURE_FILTER_MASK;
|
||||||
int FilterIndex = FilterFlags >> LC_TEXTURE_FILTER_SHIFT;
|
const int FilterIndex = FilterFlags >> LC_TEXTURE_FILTER_SHIFT;
|
||||||
int MipIndex = mFlags & LC_TEXTURE_MIPMAPS ? 0 : 1;
|
const int MipIndex = mFlags & LC_TEXTURE_MIPMAPS ? 0 : 1;
|
||||||
|
|
||||||
unsigned int Faces, Target;
|
unsigned int Faces, Target;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
|
|
||||||
bool Release()
|
bool Release()
|
||||||
{
|
{
|
||||||
bool InUse = mRefCount.deref();
|
const bool InUse = mRefCount.deref();
|
||||||
|
|
||||||
if (!InUse)
|
if (!InUse)
|
||||||
Unload();
|
Unload();
|
||||||
|
|
|
@ -98,7 +98,7 @@ void MinifigWizard::OnInitialUpdate()
|
||||||
static_assert(LC_ARRAY_COUNT(MinifigWizard::mSectionNames) == LC_MFW_NUMITEMS, "Array size mismatch.");
|
static_assert(LC_ARRAY_COUNT(MinifigWizard::mSectionNames) == LC_MFW_NUMITEMS, "Array size mismatch.");
|
||||||
|
|
||||||
const int ColorCodes[LC_MFW_NUMITEMS] = { 4, 7, 14, 7, 1, 0, 7, 4, 4, 14, 14, 7, 7, 0, 0, 7, 7 };
|
const int ColorCodes[LC_MFW_NUMITEMS] = { 4, 7, 14, 7, 1, 0, 7, 4, 4, 14, 14, 7, 7, 0, 0, 7, 7 };
|
||||||
const char* Pieces[LC_MFW_NUMITEMS] = { "3624.dat", "", "3626bp01.dat", "", "973.dat", "3815.dat", "", "3819.dat", "3818.dat", "3820.dat", "3820.dat", "", "", "3817.dat", "3816.dat", "", "" };
|
const char* const Pieces[LC_MFW_NUMITEMS] = { "3624.dat", "", "3626bp01.dat", "", "973.dat", "3815.dat", "", "3819.dat", "3818.dat", "3820.dat", "3820.dat", "", "", "3817.dat", "3816.dat", "", "" };
|
||||||
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
||||||
|
|
||||||
for (int i = 0; i < LC_MFW_NUMITEMS; i++)
|
for (int i = 0; i < LC_MFW_NUMITEMS; i++)
|
||||||
|
@ -129,7 +129,7 @@ void MinifigWizard::ParseSettings(lcFile& Settings)
|
||||||
char Line[1024];
|
char Line[1024];
|
||||||
bool FoundSection = false;
|
bool FoundSection = false;
|
||||||
const char* SectionName = mSectionNames[SectionIndex];
|
const char* SectionName = mSectionNames[SectionIndex];
|
||||||
size_t SectionNameLength = strlen(SectionName);
|
const size_t SectionNameLength = strlen(SectionName);
|
||||||
|
|
||||||
while (Settings.ReadLine(Line, sizeof(Line)))
|
while (Settings.ReadLine(Line, sizeof(Line)))
|
||||||
{
|
{
|
||||||
|
@ -323,7 +323,7 @@ void MinifigWizard::OnDraw()
|
||||||
{
|
{
|
||||||
mContext->SetDefaultState();
|
mContext->SetDefaultState();
|
||||||
|
|
||||||
float Aspect = (float)mWidth/(float)mHeight;
|
const float Aspect = (float)mWidth/(float)mHeight;
|
||||||
mContext->SetViewport(0, 0, mWidth, mHeight);
|
mContext->SetViewport(0, 0, mWidth, mHeight);
|
||||||
|
|
||||||
lcGetActiveModel()->DrawBackground(this);
|
lcGetActiveModel()->DrawBackground(this);
|
||||||
|
@ -332,7 +332,7 @@ void MinifigWizard::OnDraw()
|
||||||
|
|
||||||
for (int InfoIdx = 0; InfoIdx < LC_MFW_NUMITEMS; InfoIdx++)
|
for (int InfoIdx = 0; InfoIdx < LC_MFW_NUMITEMS; InfoIdx++)
|
||||||
{
|
{
|
||||||
PieceInfo* Info = mMinifig.Parts[InfoIdx];
|
const PieceInfo* const Info = mMinifig.Parts[InfoIdx];
|
||||||
|
|
||||||
if (!Info)
|
if (!Info)
|
||||||
continue;
|
continue;
|
||||||
|
@ -342,21 +342,21 @@ void MinifigWizard::OnDraw()
|
||||||
|
|
||||||
for (int PointIdx = 0; PointIdx < 8; PointIdx++)
|
for (int PointIdx = 0; PointIdx < 8; PointIdx++)
|
||||||
{
|
{
|
||||||
lcVector3 Point = lcMul31(Points[PointIdx], mMinifig.Matrices[InfoIdx]);
|
const lcVector3 Point = lcMul31(Points[PointIdx], mMinifig.Matrices[InfoIdx]);
|
||||||
|
|
||||||
Min = lcMin(Point, Min);
|
Min = lcMin(Point, Min);
|
||||||
Max = lcMax(Point, Max);
|
Max = lcMax(Point, Max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lcVector3 Center = (Min + Max) / 2.0f;
|
const lcVector3 Center = (Min + Max) / 2.0f;
|
||||||
|
|
||||||
lcVector3 Eye(0.0f, 0.0f, 1.0f);
|
lcVector3 Eye(0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
Eye = lcMul30(Eye, lcMatrix44RotationX(-mRotateX * LC_DTOR));
|
Eye = lcMul30(Eye, lcMatrix44RotationX(-mRotateX * LC_DTOR));
|
||||||
Eye = lcMul30(Eye, lcMatrix44RotationZ(-mRotateZ * LC_DTOR));
|
Eye = lcMul30(Eye, lcMatrix44RotationZ(-mRotateZ * LC_DTOR));
|
||||||
|
|
||||||
lcMatrix44 Projection = lcMatrix44Perspective(30.0f, Aspect, 1.0f, 2500.0f);
|
const lcMatrix44 Projection = lcMatrix44Perspective(30.0f, Aspect, 1.0f, 2500.0f);
|
||||||
mContext->SetProjectionMatrix(Projection);
|
mContext->SetProjectionMatrix(Projection);
|
||||||
|
|
||||||
lcMatrix44 ViewMatrix;
|
lcMatrix44 ViewMatrix;
|
||||||
|
@ -368,12 +368,12 @@ void MinifigWizard::OnDraw()
|
||||||
|
|
||||||
Eye += Center;
|
Eye += Center;
|
||||||
|
|
||||||
lcMatrix44 ModelView = lcMatrix44LookAt(Eye, Center, lcVector3(0, 0, 1));
|
const lcMatrix44 ModelView = lcMatrix44LookAt(Eye, Center, lcVector3(0, 0, 1));
|
||||||
std::tie(Eye, std::ignore) = lcZoomExtents(Eye, ModelView, Projection, Points, 8);
|
std::tie(Eye, std::ignore) = lcZoomExtents(Eye, ModelView, Projection, Points, 8);
|
||||||
|
|
||||||
ViewMatrix = lcMatrix44LookAt(Eye, Center, lcVector3(0, 0, 1));
|
ViewMatrix = lcMatrix44LookAt(Eye, Center, lcVector3(0, 0, 1));
|
||||||
|
|
||||||
lcVector3 d = Eye - Center;
|
const lcVector3 d = Eye - Center;
|
||||||
mDistance = d.Length();
|
mDistance = d.Length();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -476,11 +476,11 @@ void MinifigWizard::Calculate()
|
||||||
lcMatrix44 Root, Mat, Mat2;
|
lcMatrix44 Root, Mat, Mat2;
|
||||||
|
|
||||||
PieceInfo** Parts = mMinifig.Parts;
|
PieceInfo** Parts = mMinifig.Parts;
|
||||||
float* Angles = mMinifig.Angles;
|
const float* Angles = mMinifig.Angles;
|
||||||
lcMatrix44* Matrices = mMinifig.Matrices;
|
lcMatrix44* Matrices = mMinifig.Matrices;
|
||||||
|
|
||||||
bool DroidTorso = Parts[LC_MFW_BODY] && !qstricmp(Parts[LC_MFW_BODY]->mFileName, "30375.dat");
|
const bool DroidTorso = Parts[LC_MFW_BODY] && !qstricmp(Parts[LC_MFW_BODY]->mFileName, "30375.dat");
|
||||||
bool SkeletonTorso = Parts[LC_MFW_BODY] && !qstricmp(Parts[LC_MFW_BODY]->mFileName, "6260.dat");
|
const bool SkeletonTorso = Parts[LC_MFW_BODY] && !qstricmp(Parts[LC_MFW_BODY]->mFileName, "6260.dat");
|
||||||
|
|
||||||
if (Parts[LC_MFW_BODY3])
|
if (Parts[LC_MFW_BODY3])
|
||||||
Root = lcMatrix44Translation(lcVector3(0, 0, 74.0f));
|
Root = lcMatrix44Translation(lcVector3(0, 0, 74.0f));
|
||||||
|
@ -610,7 +610,7 @@ void MinifigWizard::Calculate()
|
||||||
|
|
||||||
if (Parts[LC_MFW_RLEGA])
|
if (Parts[LC_MFW_RLEGA])
|
||||||
{
|
{
|
||||||
lcVector3 Center(-10.0f, -1.0f, -28.0f);
|
const lcVector3 Center(-10.0f, -1.0f, -28.0f);
|
||||||
Mat = lcMatrix44RotationZ(LC_DTOR * Angles[LC_MFW_RLEGA]);
|
Mat = lcMatrix44RotationZ(LC_DTOR * Angles[LC_MFW_RLEGA]);
|
||||||
Mat2 = mSettings[LC_MFW_RLEGA][GetSelectionIndex(LC_MFW_RLEGA)].Offset;
|
Mat2 = mSettings[LC_MFW_RLEGA][GetSelectionIndex(LC_MFW_RLEGA)].Offset;
|
||||||
Mat2.SetTranslation(lcMul31(-Center, Mat2));
|
Mat2.SetTranslation(lcMul31(-Center, Mat2));
|
||||||
|
@ -629,7 +629,7 @@ void MinifigWizard::Calculate()
|
||||||
|
|
||||||
if (Parts[LC_MFW_LLEGA])
|
if (Parts[LC_MFW_LLEGA])
|
||||||
{
|
{
|
||||||
lcVector3 Center(10.0f, -1.0f, -28.0f);
|
const lcVector3 Center(10.0f, -1.0f, -28.0f);
|
||||||
Mat = lcMatrix44RotationZ(LC_DTOR * Angles[LC_MFW_LLEGA]);
|
Mat = lcMatrix44RotationZ(LC_DTOR * Angles[LC_MFW_LLEGA]);
|
||||||
Mat2 = mSettings[LC_MFW_LLEGA][GetSelectionIndex(LC_MFW_LLEGA)].Offset;
|
Mat2 = mSettings[LC_MFW_LLEGA][GetSelectionIndex(LC_MFW_LLEGA)].Offset;
|
||||||
Mat2.SetTranslation(lcMul31(-Center, Mat2));
|
Mat2.SetTranslation(lcMul31(-Center, Mat2));
|
||||||
|
|
|
@ -545,7 +545,7 @@ public:
|
||||||
|
|
||||||
lcVector3 GetRotationCenter() const
|
lcVector3 GetRotationCenter() const
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -556,7 +556,7 @@ public:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1;
|
const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1;
|
||||||
|
|
||||||
if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize())
|
if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize())
|
||||||
{
|
{
|
||||||
|
@ -570,7 +570,7 @@ public:
|
||||||
|
|
||||||
lcMatrix33 GetRelativeRotation() const
|
lcMatrix33 GetRelativeRotation() const
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -581,7 +581,7 @@ public:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1;
|
const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1;
|
||||||
|
|
||||||
if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize())
|
if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize())
|
||||||
{
|
{
|
||||||
|
|
|
@ -84,7 +84,7 @@ void PieceInfo::SetModel(lcModel* Model, bool UpdateMesh, Project* CurrentProjec
|
||||||
PieceFile.Seek(0, SEEK_SET);
|
PieceFile.Seek(0, SEEK_SET);
|
||||||
|
|
||||||
lcMeshLoader MeshLoader(MeshData, true, CurrentProject, SearchProjectFolder);
|
lcMeshLoader MeshLoader(MeshData, true, CurrentProject, SearchProjectFolder);
|
||||||
bool Ret = MeshLoader.LoadMesh(PieceFile, LC_MESHDATA_SHARED);
|
const bool Ret = MeshLoader.LoadMesh(PieceFile, LC_MESHDATA_SHARED);
|
||||||
|
|
||||||
if (Ret && !MeshData.IsEmpty())
|
if (Ret && !MeshData.IsEmpty())
|
||||||
SetMesh(MeshData.CreateMesh());
|
SetMesh(MeshData.CreateMesh());
|
||||||
|
@ -210,7 +210,7 @@ bool PieceInfo::MinIntersectDist(const lcVector3& Start, const lcVector3& End, f
|
||||||
Intersect |= mModel->SubModelMinIntersectDist(Start, End, MinDistance);
|
Intersect |= mModel->SubModelMinIntersectDist(Start, End, MinDistance);
|
||||||
else if (IsProject())
|
else if (IsProject())
|
||||||
{
|
{
|
||||||
lcModel* Model = mProject->GetMainModel();
|
const lcModel* const Model = mProject->GetMainModel();
|
||||||
if (Model)
|
if (Model)
|
||||||
Intersect |= Model->SubModelMinIntersectDist(Start, End, MinDistance);
|
Intersect |= Model->SubModelMinIntersectDist(Start, End, MinDistance);
|
||||||
}
|
}
|
||||||
|
@ -226,13 +226,13 @@ bool PieceInfo::BoxTest(const lcMatrix44& WorldMatrix, const lcVector4 WorldPlan
|
||||||
{
|
{
|
||||||
lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse(WorldMatrix);
|
lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse(WorldMatrix);
|
||||||
|
|
||||||
const int NumCorners = 8;
|
constexpr int NumCorners = 8;
|
||||||
const int NumPlanes = 6;
|
constexpr int NumPlanes = 6;
|
||||||
lcVector4 LocalPlanes[NumPlanes];
|
lcVector4 LocalPlanes[NumPlanes];
|
||||||
|
|
||||||
for (int PlaneIdx = 0; PlaneIdx < NumPlanes; PlaneIdx++)
|
for (int PlaneIdx = 0; PlaneIdx < NumPlanes; PlaneIdx++)
|
||||||
{
|
{
|
||||||
lcVector3 PlaneNormal = lcMul30(WorldPlanes[PlaneIdx], InverseWorldMatrix);
|
const lcVector3 PlaneNormal = lcMul30(WorldPlanes[PlaneIdx], InverseWorldMatrix);
|
||||||
LocalPlanes[PlaneIdx] = lcVector4(PlaneNormal, WorldPlanes[PlaneIdx][3] - lcDot3(InverseWorldMatrix[3], PlaneNormal));
|
LocalPlanes[PlaneIdx] = lcVector4(PlaneNormal, WorldPlanes[PlaneIdx][3] - lcDot3(InverseWorldMatrix[3], PlaneNormal));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ bool PieceInfo::BoxTest(const lcMatrix44& WorldMatrix, const lcVector4 WorldPlan
|
||||||
return mModel->SubModelBoxTest(LocalPlanes);
|
return mModel->SubModelBoxTest(LocalPlanes);
|
||||||
else if (IsProject())
|
else if (IsProject())
|
||||||
{
|
{
|
||||||
lcModel* Model = mProject->GetMainModel();
|
const lcModel* const Model = mProject->GetMainModel();
|
||||||
return Model ? Model->SubModelBoxTest(LocalPlanes) : false;
|
return Model ? Model->SubModelBoxTest(LocalPlanes) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,11 +288,11 @@ void PieceInfo::ZoomExtents(float FoV, float AspectRatio, lcMatrix44& Projection
|
||||||
lcVector3 Points[8];
|
lcVector3 Points[8];
|
||||||
lcGetBoxCorners(mBoundingBox, Points);
|
lcGetBoxCorners(mBoundingBox, Points);
|
||||||
|
|
||||||
lcVector3 Center = (mBoundingBox.Min + mBoundingBox.Max) / 2.0f;
|
const lcVector3 Center = (mBoundingBox.Min + mBoundingBox.Max) / 2.0f;
|
||||||
lcVector3 Position = Center + lcVector3(100.0f, -100.0f, 75.0f);
|
lcVector3 Position = Center + lcVector3(100.0f, -100.0f, 75.0f);
|
||||||
|
|
||||||
ProjectionMatrix = lcMatrix44Perspective(FoV, AspectRatio, 1.0f, 12500.0f);
|
ProjectionMatrix = lcMatrix44Perspective(FoV, AspectRatio, 1.0f, 12500.0f);
|
||||||
lcMatrix44 ModelView = lcMatrix44LookAt(Position, Center, lcVector3(0, 0, 1));
|
const lcMatrix44 ModelView = lcMatrix44LookAt(Position, Center, lcVector3(0, 0, 1));
|
||||||
float FarDistance;
|
float FarDistance;
|
||||||
std::tie(Position, FarDistance) = lcZoomExtents(Position, ModelView, ProjectionMatrix, Points, 8);
|
std::tie(Position, FarDistance) = lcZoomExtents(Position, ModelView, ProjectionMatrix, Points, 8);
|
||||||
ViewMatrix = lcMatrix44LookAt(Position, Center, lcVector3(0, 0, 1));
|
ViewMatrix = lcMatrix44LookAt(Position, Center, lcVector3(0, 0, 1));
|
||||||
|
@ -314,7 +314,7 @@ void PieceInfo::AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, i
|
||||||
mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);
|
mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);
|
||||||
else if (IsProject())
|
else if (IsProject())
|
||||||
{
|
{
|
||||||
lcModel* Model = mProject->GetMainModel();
|
const lcModel* const Model = mProject->GetMainModel();
|
||||||
if (Model)
|
if (Model)
|
||||||
Model->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);
|
Model->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);
|
||||||
}
|
}
|
||||||
|
@ -332,7 +332,7 @@ void PieceInfo::GetPartsList(int DefaultColorIndex, bool ScanSubModels, bool Add
|
||||||
}
|
}
|
||||||
else if (IsProject())
|
else if (IsProject())
|
||||||
{
|
{
|
||||||
lcModel* Model = mProject->GetMainModel();
|
const lcModel* const Model = mProject->GetMainModel();
|
||||||
if (Model)
|
if (Model)
|
||||||
Model->GetPartsList(DefaultColorIndex, ScanSubModels, AddSubModels, PartsList);
|
Model->GetPartsList(DefaultColorIndex, ScanSubModels, AddSubModels, PartsList);
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ void PieceInfo::GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorInd
|
||||||
}
|
}
|
||||||
else if (IsProject())
|
else if (IsProject())
|
||||||
{
|
{
|
||||||
lcModel* Model = mProject->GetMainModel();
|
const lcModel* const Model = mProject->GetMainModel();
|
||||||
if (Model)
|
if (Model)
|
||||||
Model->GetModelParts(WorldMatrix, DefaultColorIndex, ModelParts);
|
Model->GetModelParts(WorldMatrix, DefaultColorIndex, ModelParts);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -122,7 +122,7 @@ protected:
|
||||||
|
|
||||||
inline lcModel* lcGetActiveModel()
|
inline lcModel* lcGetActiveModel()
|
||||||
{
|
{
|
||||||
Project* Project = lcGetActiveProject();
|
const Project* const Project = lcGetActiveProject();
|
||||||
return Project ? Project->GetActiveModel() : nullptr;
|
return Project ? Project->GetActiveModel() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue