leocad/common/minifig.cpp

507 lines
14 KiB
C++
Raw Normal View History

#include "lc_global.h"
#include "minifig.h"
#include "lc_colors.h"
2011-09-07 23:06:51 +02:00
#include "pieceinf.h"
#include "lc_model.h"
2012-10-02 03:23:44 +02:00
#include "lc_library.h"
2011-09-07 23:06:51 +02:00
#include "lc_application.h"
#include "lc_file.h"
#include "lc_profile.h"
2011-09-07 23:06:51 +02:00
const char* MinifigWizard::mSectionNames[LC_MFW_NUMITEMS] =
{
"HATS", // LC_MFW_HATS
"HATS2", // LC_MFW_HATS2
"HEAD", // LC_MFW_HEAD
"NECK", // LC_MFW_NECK
"BODY", // LC_MFW_BODY
"BODY2", // LC_MFW_BODY2
"BODY3", // LC_MFW_BODY3
"RARM", // LC_MFW_RARM
"LARM", // LC_MFW_LARM
"RHAND", // LC_MFW_RHAND
"LHAND", // LC_MFW_LHAND
"RHANDA", // LC_MFW_RHANDA
"LHANDA", // LC_MFW_LHANDA
"RLEG", // LC_MFW_RLEG
"LLEG", // LC_MFW_LLEG
"RLEGA", // LC_MFW_RLEGA
"LLEGA", // LC_MFW_LLEGA
};
2016-08-01 05:44:15 +02:00
MinifigWizard::MinifigWizard()
: mModel(new lcModel(QString(), nullptr, false))
2011-09-07 23:06:51 +02:00
{
LoadSettings();
LoadTemplates();
2011-09-07 23:06:51 +02:00
}
MinifigWizard::~MinifigWizard()
{
lcPiecesLibrary* Library = lcGetPiecesLibrary();
for (int i = 0; i < LC_MFW_NUMITEMS; i++)
if (mMinifig.Parts[i])
Library->ReleasePieceInfo(mMinifig.Parts[i]); // todo: don't call ReleasePieceInfo here because it may release textures and they need a GL context current
SaveTemplates();
}
void MinifigWizard::LoadSettings()
{
QString CustomSettingsPath = lcGetProfileString(LC_PROFILE_MINIFIG_SETTINGS);
if (!CustomSettingsPath.isEmpty())
{
lcDiskFile DiskSettings(CustomSettingsPath);
if (DiskSettings.Open(QIODevice::ReadOnly))
{
ParseSettings(DiskSettings);
return;
}
}
2020-12-11 23:14:54 +01:00
lcDiskFile MinifigFile(":/resources/minifig.ini");
2020-12-11 23:14:54 +01:00
if (MinifigFile.Open(QIODevice::ReadOnly))
ParseSettings(MinifigFile);
}
void MinifigWizard::LoadDefault()
{
LC_ARRAY_SIZE_CHECK(MinifigWizard::mSectionNames, LC_MFW_NUMITEMS);
const int ColorCodes[LC_MFW_NUMITEMS] = { 4, 7, 14, 7, 1, 0, 7, 4, 4, 14, 14, 7, 7, 0, 0, 7, 7 };
2020-03-23 04:18:52 +01:00
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", "", "" };
2017-01-23 04:28:05 +01:00
lcPiecesLibrary* Library = lcGetPiecesLibrary();
for (int i = 0; i < LC_MFW_NUMITEMS; i++)
{
2016-08-01 05:44:15 +02:00
mMinifig.Colors[i] = lcGetColorIndex(ColorCodes[i]);
2019-02-06 01:35:15 +01:00
mMinifig.Angles[i] = 0.0f;
mMinifig.Matrices[i] = lcMatrix44Identity();
PieceInfo* Info = Library->FindPiece(Pieces[i], nullptr, false, false);
2019-02-06 01:35:15 +01:00
mMinifig.Parts[i] = Info;
if (Info)
2017-01-23 04:28:05 +01:00
Library->LoadPieceInfo(Info, false, true);
}
2017-01-23 04:28:05 +01:00
Library->WaitForLoadQueue();
Calculate();
}
2012-03-23 00:44:56 +01:00
void MinifigWizard::ParseSettings(lcFile& Settings)
2011-09-07 23:06:51 +02:00
{
for (int SectionIndex = 0; SectionIndex < LC_MFW_NUMITEMS; SectionIndex++)
{
2019-06-05 03:45:22 +02:00
std::vector<lcMinifigPieceInfo>& InfoArray = mSettings[SectionIndex];
2011-09-07 23:06:51 +02:00
2019-06-05 03:45:22 +02:00
InfoArray.clear();
2011-09-07 23:06:51 +02:00
Settings.Seek(0, SEEK_SET);
char Line[1024];
bool FoundSection = false;
const char* SectionName = mSectionNames[SectionIndex];
2020-03-23 04:18:52 +01:00
const size_t SectionNameLength = strlen(SectionName);
2011-09-07 23:06:51 +02:00
while (Settings.ReadLine(Line, sizeof(Line)))
{
if (Line[0] == '[' && !strncmp(Line + 1, SectionName, SectionNameLength) && Line[SectionNameLength + 1] == ']')
2011-09-07 23:06:51 +02:00
{
FoundSection = true;
break;
}
}
if (!FoundSection)
2012-07-21 02:31:21 +02:00
{
lcMinifigPieceInfo MinifigInfo;
strncpy(MinifigInfo.Description, "None", sizeof(MinifigInfo.Description));
MinifigInfo.Description[sizeof(MinifigInfo.Description)-1] = 0;
MinifigInfo.Offset = lcMatrix44Identity();
MinifigInfo.Info = nullptr;
2012-07-21 02:31:21 +02:00
2019-06-05 03:45:22 +02:00
InfoArray.emplace_back(std::move(MinifigInfo));
2011-09-07 23:06:51 +02:00
continue;
2012-07-21 02:31:21 +02:00
}
2011-09-07 23:06:51 +02:00
while (Settings.ReadLine(Line, sizeof(Line)))
{
if (Line[0] == '[')
break;
char* DescriptionStart = strchr(Line, '"');
if (!DescriptionStart)
continue;
DescriptionStart++;
char* DescriptionEnd = strchr(DescriptionStart, '"');
if (!DescriptionEnd)
continue;
*DescriptionEnd = 0;
DescriptionEnd++;
char* NameStart = strchr(DescriptionEnd, '"');
if (!NameStart)
continue;
NameStart++;
char* NameEnd = strchr(NameStart, '"');
if (!NameEnd)
continue;
*NameEnd = 0;
NameEnd++;
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece(NameStart, nullptr, false, false);
2011-09-07 23:06:51 +02:00
if (!Info && *NameStart)
continue;
float Mat[12];
int Flags;
if (sscanf(NameEnd, "%d %g %g %g %g %g %g %g %g %g %g %g %g",
&Flags, &Mat[0], &Mat[1], &Mat[2], &Mat[3], &Mat[4], &Mat[5], &Mat[6],
&Mat[7], &Mat[8], &Mat[9], &Mat[10], &Mat[11]) != 13)
continue;
2012-05-19 03:13:05 +02:00
lcMatrix44 Offset = lcMatrix44Identity();
2011-09-07 23:06:51 +02:00
float* OffsetMatrix = &Offset[0][0];
OffsetMatrix[0] = Mat[0];
OffsetMatrix[8] = -Mat[1];
OffsetMatrix[4] = Mat[2];
OffsetMatrix[2] = -Mat[3];
OffsetMatrix[10] = Mat[4];
OffsetMatrix[6] = -Mat[5];
OffsetMatrix[1] = Mat[6];
OffsetMatrix[9] = -Mat[7];
OffsetMatrix[5] = Mat[8];
2014-08-30 21:48:36 +02:00
OffsetMatrix[12] = Mat[9];
OffsetMatrix[14] = -Mat[10];
OffsetMatrix[13] = Mat[11];
2011-09-07 23:06:51 +02:00
lcMinifigPieceInfo MinifigInfo;
strncpy(MinifigInfo.Description, DescriptionStart, sizeof(MinifigInfo.Description));
MinifigInfo.Description[sizeof(MinifigInfo.Description)-1] = 0;
MinifigInfo.Offset = Offset;
MinifigInfo.Info = Info;
2019-06-05 03:45:22 +02:00
InfoArray.emplace_back(std::move(MinifigInfo));
2011-09-07 23:06:51 +02:00
}
}
}
void MinifigWizard::SaveTemplate(const QString& TemplateName, const lcMinifigTemplate& Template)
{
mTemplates[TemplateName] = Template;
}
void MinifigWizard::DeleteTemplate(const QString& TemplateName)
{
mTemplates.erase(TemplateName);
}
2019-09-15 02:05:13 +02:00
void MinifigWizard::AddTemplatesJson(const QByteArray& TemplateData)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QJsonDocument Document = QJsonDocument::fromJson(TemplateData);
QJsonObject RootObject = Document.object();
2019-09-15 02:05:13 +02:00
int Version = RootObject["Version"].toInt(0);
QJsonObject TemplatesObject;
if (Version > 0)
TemplatesObject = RootObject["Templates"].toObject();
else
TemplatesObject = RootObject;
for (QJsonObject::const_iterator ElementIt = TemplatesObject.constBegin(); ElementIt != TemplatesObject.constEnd(); ElementIt++)
{
2019-09-15 02:05:13 +02:00
if (!ElementIt.value().isObject())
continue;
QJsonObject TemplateObject = ElementIt.value().toObject();
lcMinifigTemplate Template;
for (int PartIdx = 0; PartIdx < LC_MFW_NUMITEMS; PartIdx++)
{
QJsonObject PartObject = TemplateObject.value(QLatin1String(mSectionNames[PartIdx])).toObject();
Template.Parts[PartIdx] = PartObject["Id"].toString();
Template.Colors[PartIdx] = PartObject["Color"].toInt();
Template.Angles[PartIdx] = PartObject["Angle"].toDouble();
}
mTemplates.emplace(ElementIt.key(), std::move(Template));
}
#endif
}
2019-09-15 02:05:13 +02:00
QByteArray MinifigWizard::GetTemplatesJson() const
{
2019-09-15 02:05:13 +02:00
QByteArray TemplateData;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QJsonObject RootObject;
2019-09-15 02:05:13 +02:00
RootObject["Version"] = 1;
QJsonObject TemplatesObject;
for (const auto& TemplateEntry : mTemplates)
{
const lcMinifigTemplate& Template = TemplateEntry.second;
QJsonObject TemplateObject;
for (int PartIdx = 0; PartIdx < LC_MFW_NUMITEMS; PartIdx++)
{
QJsonObject PartObject;
PartObject["Id"] = Template.Parts[PartIdx];
PartObject["Color"] = Template.Colors[PartIdx];
PartObject["Angle"] = Template.Angles[PartIdx];
TemplateObject[QLatin1String(mSectionNames[PartIdx])] = PartObject;
}
2019-09-15 02:05:13 +02:00
TemplatesObject[TemplateEntry.first] = TemplateObject;
}
2019-09-15 02:05:13 +02:00
RootObject["Templates"] = TemplatesObject;
TemplateData = QJsonDocument(RootObject).toJson();
#endif
return TemplateData;
}
void MinifigWizard::LoadTemplates()
{
mTemplates.clear();
QSettings Settings;
Settings.beginGroup("Minifig");
2019-09-15 02:05:13 +02:00
QByteArray TemplateData = Settings.value("Templates").toByteArray();
AddTemplatesJson(TemplateData);
}
void MinifigWizard::SaveTemplates()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QSettings Settings;
Settings.beginGroup("Minifig");
Settings.setValue("Templates", GetTemplatesJson());
#endif
}
2011-09-07 23:06:51 +02:00
void MinifigWizard::Calculate()
{
float HeadOffset = 0.0f;
2012-05-19 03:13:05 +02:00
lcMatrix44 Root, Mat, Mat2;
2011-09-07 23:06:51 +02:00
2016-08-01 05:44:15 +02:00
PieceInfo** Parts = mMinifig.Parts;
2020-03-23 04:18:52 +01:00
const float* Angles = mMinifig.Angles;
2016-08-01 05:44:15 +02:00
lcMatrix44* Matrices = mMinifig.Matrices;
2012-02-01 03:07:54 +01:00
2020-03-23 04:18:52 +01:00
const bool DroidTorso = Parts[LC_MFW_BODY] && !qstricmp(Parts[LC_MFW_BODY]->mFileName, "30375.dat");
const bool SkeletonTorso = Parts[LC_MFW_BODY] && !qstricmp(Parts[LC_MFW_BODY]->mFileName, "6260.dat");
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_BODY3])
2014-08-30 21:48:36 +02:00
Root = lcMatrix44Translation(lcVector3(0, 0, 74.0f));
else
2014-08-30 21:48:36 +02:00
Root = lcMatrix44Translation(lcVector3(0, 0, 72.0f));
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_BODY] = lcMul(mSettings[LC_MFW_BODY][GetSelectionIndex(LC_MFW_BODY)].Offset, Root);
2011-09-07 23:06:51 +02:00
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_NECK])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_NECK] = lcMul(mSettings[LC_MFW_NECK][GetSelectionIndex(LC_MFW_NECK)].Offset, Root);
2011-09-07 23:06:51 +02:00
HeadOffset = 0.08f;
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_HEAD])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationZ(-LC_DTOR * Angles[LC_MFW_HEAD]);
2014-08-30 21:48:36 +02:00
Mat.SetTranslation(lcVector3(0.0f, 0.0f, 24.0f + HeadOffset));
2012-05-19 03:13:05 +02:00
Mat = lcMul(mSettings[LC_MFW_HEAD][GetSelectionIndex(LC_MFW_HEAD)].Offset, Mat);
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_HEAD] = lcMul(Mat, Root);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_HATS])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationZ(-LC_DTOR * Angles[LC_MFW_HATS]);
Mat = lcMul(mSettings[LC_MFW_HATS][GetSelectionIndex(LC_MFW_HATS)].Offset, Mat);
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_HATS] = lcMul(Mat, Matrices[LC_MFW_HEAD]);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_HATS2])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationX(-LC_DTOR * Angles[LC_MFW_HATS2]);
Mat = lcMul(mSettings[LC_MFW_HATS2][GetSelectionIndex(LC_MFW_HATS2)].Offset, Mat);
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_HATS2] = lcMul(Mat, Matrices[LC_MFW_HATS]);
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_RARM])
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationX(-LC_DTOR * Angles[LC_MFW_RARM]);
2011-09-07 23:06:51 +02:00
2012-02-01 03:07:54 +01:00
if (DroidTorso || SkeletonTorso)
2012-05-19 03:13:05 +02:00
Mat2 = lcMatrix44Identity();
2011-09-07 23:06:51 +02:00
else
Mat2 = lcMatrix44RotationY(-LC_DTOR * 9.791f);
Mat2.SetTranslation(lcVector3(15.552f, 0, -8.88f));
2011-09-07 23:06:51 +02:00
Mat = lcMul(mSettings[LC_MFW_RARM][GetSelectionIndex(LC_MFW_RARM)].Offset, Mat);
2012-05-19 03:13:05 +02:00
Mat = lcMul(Mat, Mat2);
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_RARM] = lcMul(Mat, Root);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_RHAND])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationY(-LC_DTOR * Angles[LC_MFW_RHAND]);
2012-05-19 03:13:05 +02:00
Mat2 = lcMatrix44RotationX(LC_DTOR * 45);
Mat = lcMul(mSettings[LC_MFW_RHAND][GetSelectionIndex(LC_MFW_RHAND)].Offset, Mat);
2012-05-19 03:13:05 +02:00
Mat = lcMul(Mat, Mat2);
2014-08-30 21:48:36 +02:00
Mat.SetTranslation(lcVector3(5.0f, -10.0f, -19.0f));
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_RHAND] = lcMul(Mat, Matrices[LC_MFW_RARM]);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_RHANDA])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationZ(LC_DTOR * Angles[LC_MFW_RHANDA]);
2014-08-30 21:48:36 +02:00
Mat.SetTranslation(lcVector3(0, -10.0f, 0));
Mat = lcMul(mSettings[LC_MFW_RHANDA][GetSelectionIndex(LC_MFW_RHANDA)].Offset, Mat);
Mat = lcMul(Mat, lcMatrix44RotationX(LC_DTOR * 15.0f));
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_RHANDA] = lcMul(Mat, Matrices[LC_MFW_RHAND]);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_LARM])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationX(-LC_DTOR * Angles[LC_MFW_LARM]);
2011-09-07 23:06:51 +02:00
2012-02-01 03:07:54 +01:00
if (DroidTorso || SkeletonTorso)
2012-05-19 03:13:05 +02:00
Mat2 = lcMatrix44Identity();
2011-09-07 23:06:51 +02:00
else
Mat2 = lcMatrix44RotationY(LC_DTOR * 9.791f);
Mat2.SetTranslation(lcVector3(-15.552f, 0.0f, -8.88f));
2011-09-07 23:06:51 +02:00
Mat = lcMul(mSettings[LC_MFW_LARM][GetSelectionIndex(LC_MFW_LARM)].Offset, Mat);
2012-05-19 03:13:05 +02:00
Mat = lcMul(Mat, Mat2);
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_LARM] = lcMul(Mat, Root);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_LHAND])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationY(-LC_DTOR * Angles[LC_MFW_LHAND]);
2012-05-19 03:13:05 +02:00
Mat2 = lcMatrix44RotationX(LC_DTOR * 45);
Mat = lcMul(mSettings[LC_MFW_LHAND][GetSelectionIndex(LC_MFW_LHAND)].Offset, Mat);
2012-05-19 03:13:05 +02:00
Mat = lcMul(Mat, Mat2);
2014-08-30 21:48:36 +02:00
Mat.SetTranslation(lcVector3(-5.0f, -10.0f, -19.0f));
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_LHAND] = lcMul(Mat, Matrices[LC_MFW_LARM]);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_LHANDA])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationZ(LC_DTOR * Angles[LC_MFW_LHANDA]);
2014-08-30 21:48:36 +02:00
Mat.SetTranslation(lcVector3(0, -10.0f, 0));
Mat = lcMul(mSettings[LC_MFW_LHANDA][GetSelectionIndex(LC_MFW_LHANDA)].Offset, Mat);
Mat = lcMul(Mat, lcMatrix44RotationX(LC_DTOR * 15.0f));
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_LHANDA] = lcMul(Mat, Matrices[LC_MFW_LHAND]);
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_BODY2])
{
Mat = lcMatrix44Identity();
2014-08-30 21:48:36 +02:00
Mat.SetTranslation(lcVector3(0, 0, -32.0f));
Mat = lcMul(mSettings[LC_MFW_BODY2][GetSelectionIndex(LC_MFW_BODY2)].Offset, Mat);
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_BODY2] = lcMul(Mat, Root);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_BODY3])
2011-09-07 23:06:51 +02:00
{
2012-05-19 03:13:05 +02:00
Mat = lcMatrix44Identity();
2014-08-30 21:48:36 +02:00
Mat.SetTranslation(lcVector3(0, 0, -32.0f));
Mat = lcMul(mSettings[LC_MFW_BODY3][GetSelectionIndex(LC_MFW_BODY3)].Offset, Mat);
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_BODY3] = lcMul(Mat, Root);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_RLEG])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationX(-LC_DTOR * Angles[LC_MFW_RLEG]);
2014-08-30 21:48:36 +02:00
Mat.SetTranslation(lcVector3(0, 0, -44.0f));
Mat = lcMul(mSettings[LC_MFW_RLEG][GetSelectionIndex(LC_MFW_RLEG)].Offset, Mat);
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_RLEG] = lcMul(Mat, Root);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_RLEGA])
2011-09-07 23:06:51 +02:00
{
2020-03-23 04:18:52 +01:00
const lcVector3 Center(-10.0f, -1.0f, -28.0f);
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationZ(LC_DTOR * Angles[LC_MFW_RLEGA]);
Mat2 = mSettings[LC_MFW_RLEGA][GetSelectionIndex(LC_MFW_RLEGA)].Offset;
2012-05-19 03:13:05 +02:00
Mat2.SetTranslation(lcMul31(-Center, Mat2));
Mat = lcMul(Mat2, Mat);
Mat.SetTranslation(lcMul31(Center, Mat2));
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_RLEGA] = lcMul(Mat, Matrices[LC_MFW_RLEG]);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_LLEG])
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationX(-LC_DTOR * Angles[LC_MFW_LLEG]);
2014-08-30 21:48:36 +02:00
Mat.SetTranslation(lcVector3(0, 0, -44.0f));
Mat = lcMul(mSettings[LC_MFW_LLEG][GetSelectionIndex(LC_MFW_LLEG)].Offset, Mat);
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_LLEG] = lcMul(Mat, Root);
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
if (Parts[LC_MFW_LLEGA])
2011-09-07 23:06:51 +02:00
{
2020-03-23 04:18:52 +01:00
const lcVector3 Center(10.0f, -1.0f, -28.0f);
2013-08-09 06:57:18 +02:00
Mat = lcMatrix44RotationZ(LC_DTOR * Angles[LC_MFW_LLEGA]);
Mat2 = mSettings[LC_MFW_LLEGA][GetSelectionIndex(LC_MFW_LLEGA)].Offset;
2012-05-19 03:13:05 +02:00
Mat2.SetTranslation(lcMul31(-Center, Mat2));
Mat = lcMul(Mat2, Mat);
Mat.SetTranslation(lcMul31(Center, Mat2));
2013-08-09 06:57:18 +02:00
Matrices[LC_MFW_LLEGA] = lcMul(Mat, Matrices[LC_MFW_LLEG]);
2011-09-07 23:06:51 +02:00
}
mModel->SetMinifig(mMinifig);
2011-09-07 23:06:51 +02:00
}
int MinifigWizard::GetSelectionIndex(int Type) const
{
2019-06-05 03:45:22 +02:00
const std::vector<lcMinifigPieceInfo>& InfoArray = mSettings[Type];
2011-09-07 23:06:51 +02:00
2019-06-05 03:45:22 +02:00
for (size_t Index = 0; Index < InfoArray.size(); Index++)
2016-08-01 05:44:15 +02:00
if (InfoArray[Index].Info == mMinifig.Parts[Type])
return (int)Index;
2011-09-07 23:06:51 +02:00
return 0;
}
void MinifigWizard::SetSelectionIndex(int Type, int Index)
{
2017-01-23 04:28:05 +01:00
lcPiecesLibrary* Library = lcGetPiecesLibrary();
2016-08-01 05:44:15 +02:00
if (mMinifig.Parts[Type])
2017-01-23 04:28:05 +01:00
Library->ReleasePieceInfo(mMinifig.Parts[Type]);
2011-09-07 23:06:51 +02:00
2016-08-01 05:44:15 +02:00
mMinifig.Parts[Type] = mSettings[Type][Index].Info;
2011-09-07 23:06:51 +02:00
2016-08-01 05:44:15 +02:00
if (mMinifig.Parts[Type])
2017-01-23 04:28:05 +01:00
Library->LoadPieceInfo(mMinifig.Parts[Type], true, true);
2011-09-07 23:06:51 +02:00
Calculate();
}
void MinifigWizard::SetColor(int Type, int Color)
{
2016-08-01 05:44:15 +02:00
mMinifig.Colors[Type] = Color;
2020-12-20 03:51:54 +01:00
Calculate();
2011-09-07 23:06:51 +02:00
}
void MinifigWizard::SetAngle(int Type, float Angle)
{
2016-08-01 05:44:15 +02:00
mMinifig.Angles[Type] = Angle;
2020-12-20 03:51:54 +01:00
Calculate();
2011-09-07 23:06:51 +02:00
}