2012-03-20 01:57:42 +01:00
|
|
|
#include "lc_global.h"
|
2012-04-26 04:19:33 +02:00
|
|
|
#include "lc_colors.h"
|
2012-05-19 03:13:05 +02:00
|
|
|
#include "lc_math.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "minifig.h"
|
|
|
|
#include "pieceinf.h"
|
|
|
|
#include "project.h"
|
2014-12-08 08:32:39 +01:00
|
|
|
#include "lc_model.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
#include "system.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"
|
2014-04-20 03:50:41 +02:00
|
|
|
#include "lc_context.h"
|
2014-12-08 08:32:39 +01:00
|
|
|
#include "lc_file.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
MinifigWizard::MinifigWizard(lcMinifig* Minifig)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
|
|
|
char Filename[LC_MAXPATH];
|
2012-10-02 03:23:44 +02:00
|
|
|
strcpy(Filename, lcGetPiecesLibrary()->mLibraryPath);
|
2011-09-07 23:06:51 +02:00
|
|
|
strcat(Filename, "mlcad.ini");
|
|
|
|
|
2012-03-23 00:44:56 +01:00
|
|
|
lcDiskFile DiskSettings;
|
2011-09-07 23:06:51 +02:00
|
|
|
if (DiskSettings.Open(Filename, "rt"))
|
|
|
|
{
|
|
|
|
ParseSettings(DiskSettings);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-22 16:59:42 +02:00
|
|
|
QResource Resource(":/resources/minifig.ini");
|
|
|
|
|
|
|
|
if (Resource.isValid())
|
|
|
|
{
|
|
|
|
QByteArray Data;
|
|
|
|
|
|
|
|
if (Resource.isCompressed())
|
|
|
|
Data = qUncompress(Resource.data(), Resource.size());
|
|
|
|
else
|
|
|
|
Data = QByteArray::fromRawData((const char*)Resource.data(), Resource.size());
|
|
|
|
|
|
|
|
lcMemFile MemSettings;
|
|
|
|
MemSettings.WriteBuffer(Data.constData(), Data.size());
|
|
|
|
ParseSettings(MemSettings);
|
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
mMinifig = Minifig;
|
|
|
|
|
2013-01-29 01:43:34 +01:00
|
|
|
m_RotateX = 75.0f;
|
|
|
|
m_RotateZ = 180.0f;
|
|
|
|
m_Distance = 10.0f;
|
|
|
|
m_AutoZoom = true;
|
|
|
|
m_Tracking = LC_TRACK_NONE;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-08 23:48:51 +01:00
|
|
|
void MinifigWizard::OnInitialUpdate()
|
|
|
|
{
|
|
|
|
MakeCurrent();
|
2014-04-20 03:50:41 +02:00
|
|
|
mContext->SetDefaultState();
|
2012-02-08 23:48:51 +01:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
memset(mMinifig, 0, sizeof(lcMinifig));
|
|
|
|
|
2012-07-20 23:32:27 +02:00
|
|
|
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", "None", "3626BP01", "None", "973", "3815", "None", "3819", "3818", "3820", "3820", "None", "None", "3817", "3816", "None", "None" };
|
|
|
|
|
2012-02-08 23:48:51 +01:00
|
|
|
for (int i = 0; i < LC_MFW_NUMITEMS; i++)
|
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
mMinifig->Colors[i] = lcGetColorIndex(ColorCodes[i]);
|
2012-02-08 23:48:51 +01:00
|
|
|
|
2015-02-22 03:39:15 +01:00
|
|
|
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece(Pieces[i], NULL, false);
|
2013-08-09 06:57:18 +02:00
|
|
|
if (Info)
|
|
|
|
{
|
|
|
|
mMinifig->Parts[i] = Info;
|
|
|
|
Info->AddRef();
|
|
|
|
}
|
2012-02-08 23:48:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Calculate();
|
|
|
|
}
|
|
|
|
|
2015-11-16 03:41:16 +01:00
|
|
|
MinifigWizard::~MinifigWizard()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
for (int i = 0; i < LC_MFW_NUMITEMS; i++)
|
|
|
|
if (mMinifig->Parts[i])
|
2015-11-16 03:41:16 +01:00
|
|
|
mMinifig->Parts[i]->Release(true);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-03-23 00:44:56 +01:00
|
|
|
void MinifigWizard::ParseSettings(lcFile& Settings)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
|
|
|
const char* SectionNames[LC_MFW_NUMITEMS] =
|
|
|
|
{
|
2012-07-20 23:32:27 +02:00
|
|
|
"[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
|
2011-09-07 23:06:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int SectionIndex = 0; SectionIndex < LC_MFW_NUMITEMS; SectionIndex++)
|
|
|
|
{
|
2013-08-16 01:43:18 +02:00
|
|
|
lcArray<lcMinifigPieceInfo>& InfoArray = mSettings[SectionIndex];
|
2011-09-07 23:06:51 +02:00
|
|
|
|
|
|
|
InfoArray.RemoveAll();
|
|
|
|
Settings.Seek(0, SEEK_SET);
|
|
|
|
|
|
|
|
char Line[1024];
|
|
|
|
bool FoundSection = false;
|
|
|
|
const char* SectionName = SectionNames[SectionIndex];
|
2016-02-17 00:11:52 +01:00
|
|
|
size_t SectionNameLength = strlen(SectionName);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
|
|
|
// Find start of section
|
|
|
|
while (Settings.ReadLine(Line, sizeof(Line)))
|
|
|
|
{
|
|
|
|
if (!strncmp(Line, SectionName, SectionNameLength))
|
|
|
|
{
|
|
|
|
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 = NULL;
|
|
|
|
|
|
|
|
InfoArray.Add(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
|
|
|
|
|
|
|
// Parse section.
|
|
|
|
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++;
|
|
|
|
|
|
|
|
strupr(NameStart);
|
|
|
|
char* Ext = strrchr(NameStart, '.');
|
|
|
|
if (Ext != NULL)
|
|
|
|
{
|
2012-02-01 03:07:54 +01:00
|
|
|
if (!strcmp(Ext, ".DAT"))
|
2011-09-07 23:06:51 +02:00
|
|
|
*Ext = 0;
|
|
|
|
}
|
|
|
|
|
2015-02-22 03:39:15 +01:00
|
|
|
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece(NameStart, NULL, 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;
|
|
|
|
|
|
|
|
InfoArray.Add(MinifigInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 03:07:54 +01:00
|
|
|
void MinifigWizard::OnDraw()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2015-02-08 00:02:20 +01:00
|
|
|
mContext->SetDefaultState();
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
float Aspect = (float)mWidth/(float)mHeight;
|
2014-10-24 00:03:50 +02:00
|
|
|
mContext->SetViewport(0, 0, mWidth, mHeight);
|
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
lcGetActiveModel()->DrawBackground(mContext);
|
2013-01-29 01:43:34 +01:00
|
|
|
|
|
|
|
float Box[6] = { 10000, 10000, 10000, -10000, -10000, -10000 };
|
|
|
|
|
|
|
|
for (int InfoIdx = 0; InfoIdx < LC_MFW_NUMITEMS; InfoIdx++)
|
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
PieceInfo* Info = mMinifig->Parts[InfoIdx];
|
2013-01-29 01:43:34 +01:00
|
|
|
|
|
|
|
if (!Info)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lcVector3 Points[8] =
|
|
|
|
{
|
|
|
|
lcVector3(Info->m_fDimensions[0], Info->m_fDimensions[1], Info->m_fDimensions[5]),
|
|
|
|
lcVector3(Info->m_fDimensions[3], Info->m_fDimensions[1], Info->m_fDimensions[5]),
|
|
|
|
lcVector3(Info->m_fDimensions[0], Info->m_fDimensions[1], Info->m_fDimensions[2]),
|
|
|
|
lcVector3(Info->m_fDimensions[3], Info->m_fDimensions[4], Info->m_fDimensions[5]),
|
|
|
|
lcVector3(Info->m_fDimensions[3], Info->m_fDimensions[4], Info->m_fDimensions[2]),
|
|
|
|
lcVector3(Info->m_fDimensions[0], Info->m_fDimensions[4], Info->m_fDimensions[2]),
|
|
|
|
lcVector3(Info->m_fDimensions[0], Info->m_fDimensions[4], Info->m_fDimensions[5]),
|
|
|
|
lcVector3(Info->m_fDimensions[3], Info->m_fDimensions[1], Info->m_fDimensions[2])
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int PointIdx = 0; PointIdx < 8; PointIdx++)
|
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
lcVector3 Point = lcMul31(Points[PointIdx], mMinifig->Matrices[InfoIdx]);
|
2013-01-29 01:43:34 +01:00
|
|
|
|
|
|
|
if (Point[0] < Box[0]) Box[0] = Point[0];
|
|
|
|
if (Point[1] < Box[1]) Box[1] = Point[1];
|
|
|
|
if (Point[2] < Box[2]) Box[2] = Point[2];
|
|
|
|
if (Point[0] > Box[3]) Box[3] = Point[0];
|
|
|
|
if (Point[1] > Box[4]) Box[4] = Point[1];
|
|
|
|
if (Point[2] > Box[5]) Box[5] = Point[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lcVector3 Center((Box[0] + Box[3]) / 2, (Box[1] + Box[4]) / 2, (Box[2] + Box[5]) / 2);
|
|
|
|
|
|
|
|
lcVector3 Eye(0.0f, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
Eye = lcMul30(Eye, lcMatrix44RotationX(-m_RotateX * LC_DTOR));
|
|
|
|
Eye = lcMul30(Eye, lcMatrix44RotationZ(-m_RotateZ * LC_DTOR));
|
|
|
|
|
2014-08-30 21:48:36 +02:00
|
|
|
lcMatrix44 Projection = lcMatrix44Perspective(30.0f, Aspect, 1.0f, 2500.0f);
|
2014-04-20 03:50:41 +02:00
|
|
|
mContext->SetProjectionMatrix(Projection);
|
2013-01-29 01:43:34 +01:00
|
|
|
|
2014-02-16 08:23:55 +01:00
|
|
|
lcMatrix44 ViewMatrix;
|
|
|
|
|
2013-01-29 01:43:34 +01:00
|
|
|
if (m_AutoZoom)
|
|
|
|
{
|
|
|
|
lcVector3 Points[8] =
|
|
|
|
{
|
|
|
|
lcVector3(Box[0], Box[1], Box[5]),
|
|
|
|
lcVector3(Box[3], Box[1], Box[5]),
|
|
|
|
lcVector3(Box[0], Box[1], Box[2]),
|
|
|
|
lcVector3(Box[3], Box[4], Box[5]),
|
|
|
|
lcVector3(Box[3], Box[4], Box[2]),
|
|
|
|
lcVector3(Box[0], Box[4], Box[2]),
|
|
|
|
lcVector3(Box[0], Box[4], Box[5]),
|
|
|
|
lcVector3(Box[3], Box[1], Box[2])
|
|
|
|
};
|
|
|
|
|
|
|
|
Eye += Center;
|
|
|
|
|
|
|
|
lcMatrix44 ModelView = lcMatrix44LookAt(Eye, Center, lcVector3(0, 0, 1));
|
|
|
|
Eye = lcZoomExtents(Eye, ModelView, Projection, Points, 8);
|
|
|
|
|
2014-02-16 08:23:55 +01:00
|
|
|
ViewMatrix = lcMatrix44LookAt(Eye, Center, lcVector3(0, 0, 1));
|
2013-01-29 01:43:34 +01:00
|
|
|
|
|
|
|
// Update the new camera distance.
|
|
|
|
lcVector3 d = Eye - Center;
|
|
|
|
m_Distance = d.Length();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-16 08:23:55 +01:00
|
|
|
ViewMatrix = lcMatrix44LookAt(Eye * m_Distance, Center, lcVector3(0, 0, 1));
|
2013-01-29 01:43:34 +01:00
|
|
|
}
|
2012-02-01 03:07:54 +01:00
|
|
|
|
2015-05-17 01:04:35 +02:00
|
|
|
mContext->SetViewMatrix(ViewMatrix);
|
|
|
|
|
2012-02-01 03:07:54 +01:00
|
|
|
Calculate();
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2015-02-08 19:54:51 +01:00
|
|
|
lcScene Scene;
|
|
|
|
Scene.Begin(ViewMatrix);
|
2014-04-23 16:53:43 +02:00
|
|
|
|
2013-01-29 01:43:34 +01:00
|
|
|
for (int PieceIdx = 0; PieceIdx < LC_MFW_NUMITEMS; PieceIdx++)
|
2014-04-23 16:53:43 +02:00
|
|
|
if (mMinifig->Parts[PieceIdx])
|
2015-02-08 19:54:51 +01:00
|
|
|
mMinifig->Parts[PieceIdx]->AddRenderMeshes(Scene, mMinifig->Matrices[PieceIdx], mMinifig->Colors[PieceIdx], false, false);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2015-02-08 19:54:51 +01:00
|
|
|
Scene.End();
|
2014-04-23 16:53:43 +02:00
|
|
|
|
2015-05-17 01:04:35 +02:00
|
|
|
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
|
|
|
mContext->DrawOpaqueMeshes(Scene.mOpaqueMeshes);
|
|
|
|
mContext->DrawTranslucentMeshes(Scene.mTranslucentMeshes);
|
2015-02-08 19:54:51 +01:00
|
|
|
|
|
|
|
mContext->UnbindMesh(); // context remove
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void MinifigWizard::OnLeftButtonDown()
|
2013-01-29 01:43:34 +01:00
|
|
|
{
|
|
|
|
if (m_Tracking == LC_TRACK_NONE)
|
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_DownX = mInputState.x;
|
|
|
|
m_DownY = mInputState.y;
|
2013-01-29 01:43:34 +01:00
|
|
|
m_Tracking = LC_TRACK_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void MinifigWizard::OnLeftButtonUp()
|
2013-01-29 01:43:34 +01:00
|
|
|
{
|
|
|
|
if (m_Tracking == LC_TRACK_LEFT)
|
|
|
|
m_Tracking = LC_TRACK_NONE;
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void MinifigWizard::OnLeftButtonDoubleClick()
|
2013-01-29 01:43:34 +01:00
|
|
|
{
|
|
|
|
m_AutoZoom = true;
|
|
|
|
Redraw();
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void MinifigWizard::OnRightButtonDown()
|
2013-01-29 01:43:34 +01:00
|
|
|
{
|
|
|
|
if (m_Tracking == LC_TRACK_NONE)
|
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_DownX = mInputState.x;
|
|
|
|
m_DownY = mInputState.y;
|
2013-01-29 01:43:34 +01:00
|
|
|
m_Tracking = LC_TRACK_RIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void MinifigWizard::OnRightButtonUp()
|
2013-01-29 01:43:34 +01:00
|
|
|
{
|
|
|
|
if (m_Tracking == LC_TRACK_RIGHT)
|
|
|
|
m_Tracking = LC_TRACK_NONE;
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void MinifigWizard::OnMouseMove()
|
2013-01-29 01:43:34 +01:00
|
|
|
{
|
|
|
|
if (m_Tracking == LC_TRACK_LEFT)
|
|
|
|
{
|
|
|
|
// Rotate.
|
2013-08-09 06:57:18 +02:00
|
|
|
m_RotateZ += mInputState.x - m_DownX;
|
|
|
|
m_RotateX += mInputState.y - m_DownY;
|
2013-01-29 01:43:34 +01:00
|
|
|
|
|
|
|
if (m_RotateX > 179.5f)
|
|
|
|
m_RotateX = 179.5f;
|
|
|
|
else if (m_RotateX < 0.5f)
|
|
|
|
m_RotateX = 0.5f;
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
m_DownX = mInputState.x;
|
|
|
|
m_DownY = mInputState.y;
|
2013-01-29 01:43:34 +01:00
|
|
|
|
|
|
|
Redraw();
|
|
|
|
}
|
|
|
|
else if (m_Tracking == LC_TRACK_RIGHT)
|
|
|
|
{
|
|
|
|
// Zoom.
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Distance += (float)(m_DownY - mInputState.y) * 0.2f;
|
2013-01-29 01:43:34 +01:00
|
|
|
m_AutoZoom = false;
|
|
|
|
|
|
|
|
if (m_Distance < 0.5f)
|
|
|
|
m_Distance = 0.5f;
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
m_DownX = mInputState.x;
|
|
|
|
m_DownY = mInputState.y;
|
2013-01-29 01:43:34 +01:00
|
|
|
|
|
|
|
Redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
PieceInfo** Parts = mMinifig->Parts;
|
|
|
|
float* Angles = mMinifig->Angles;
|
|
|
|
lcMatrix44* Matrices = mMinifig->Matrices;
|
2012-02-01 03:07:54 +01:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
bool DroidTorso = Parts[LC_MFW_BODY] && !strcmp(Parts[LC_MFW_BODY]->m_strName, "30375");
|
|
|
|
bool SkeletonTorso = Parts[LC_MFW_BODY] && !strcmp(Parts[LC_MFW_BODY]->m_strName, "6260");
|
|
|
|
|
|
|
|
if (Parts[LC_MFW_BODY3])
|
2014-08-30 21:48:36 +02:00
|
|
|
Root = lcMatrix44Translation(lcVector3(0, 0, 74.0f));
|
2012-07-20 23:32:27 +02:00
|
|
|
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]);
|
2012-07-20 23:32:27 +02:00
|
|
|
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]);
|
2012-07-20 23:32:27 +02:00
|
|
|
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]);
|
2012-07-20 23:32:27 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
if (Parts[LC_MFW_RARM])
|
2012-07-20 23:32:27 +02:00
|
|
|
{
|
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
|
2012-07-20 23:32:27 +02:00
|
|
|
Mat2 = lcMatrix44RotationY(-LC_DTOR * 9.791f);
|
2014-08-30 21:48:36 +02:00
|
|
|
Mat2.SetTranslation(lcVector3(15.5f, 0, -8.0f));
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2012-07-20 23:32:27 +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);
|
2012-07-20 23:32:27 +02:00
|
|
|
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));
|
2012-07-20 23:32:27 +02:00
|
|
|
Mat = lcMul(mSettings[LC_MFW_RHANDA][GetSelectionIndex(LC_MFW_RHANDA)].Offset, Mat);
|
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
|
2012-07-20 23:32:27 +02:00
|
|
|
Mat2 = lcMatrix44RotationY(LC_DTOR * 9.791f);
|
2014-08-30 21:48:36 +02:00
|
|
|
Mat2.SetTranslation(lcVector3(-15.5f, 0.0f, -8.0f));
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2012-07-20 23:32:27 +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);
|
2012-07-20 23:32:27 +02:00
|
|
|
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));
|
2012-07-20 23:32:27 +02:00
|
|
|
Mat = lcMul(mSettings[LC_MFW_LHANDA][GetSelectionIndex(LC_MFW_LHANDA)].Offset, Mat);
|
2013-08-09 06:57:18 +02:00
|
|
|
Matrices[LC_MFW_LHANDA] = lcMul(Mat, Matrices[LC_MFW_LHAND]);
|
2012-07-20 23:32:27 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
if (Parts[LC_MFW_BODY2])
|
2012-07-20 23:32:27 +02:00
|
|
|
{
|
|
|
|
Mat = lcMatrix44Identity();
|
2014-08-30 21:48:36 +02:00
|
|
|
Mat.SetTranslation(lcVector3(0, 0, -32.0f));
|
2012-07-20 23:32:27 +02:00
|
|
|
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));
|
2012-07-20 23:32:27 +02:00
|
|
|
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));
|
2012-07-20 23:32:27 +02:00
|
|
|
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
|
|
|
{
|
2014-08-30 21:48:36 +02:00
|
|
|
lcVector3 Center(-10.0f, -1.0f, -28.0f);
|
2013-08-09 06:57:18 +02:00
|
|
|
Mat = lcMatrix44RotationZ(LC_DTOR * Angles[LC_MFW_RLEGA]);
|
2012-07-20 23:32:27 +02:00
|
|
|
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));
|
2012-07-20 23:32:27 +02:00
|
|
|
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
|
|
|
{
|
2014-08-30 21:48:36 +02:00
|
|
|
lcVector3 Center(10.0f, -1.0f, -28.0f);
|
2013-08-09 06:57:18 +02:00
|
|
|
Mat = lcMatrix44RotationZ(LC_DTOR * Angles[LC_MFW_LLEGA]);
|
2012-07-20 23:32:27 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int MinifigWizard::GetSelectionIndex(int Type) const
|
|
|
|
{
|
2013-08-16 01:43:18 +02:00
|
|
|
const lcArray<lcMinifigPieceInfo>& InfoArray = mSettings[Type];
|
2011-09-07 23:06:51 +02:00
|
|
|
|
|
|
|
for (int Index = 0; Index < InfoArray.GetSize(); Index++)
|
2013-08-09 06:57:18 +02:00
|
|
|
if (InfoArray[Index].Info == mMinifig->Parts[Type])
|
2011-09-07 23:06:51 +02:00
|
|
|
return Index;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinifigWizard::SetSelectionIndex(int Type, int Index)
|
|
|
|
{
|
2015-02-08 00:02:20 +01:00
|
|
|
MakeCurrent();
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
if (mMinifig->Parts[Type])
|
2015-11-16 03:41:16 +01:00
|
|
|
mMinifig->Parts[Type]->Release(true);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
mMinifig->Parts[Type] = mSettings[Type][Index].Info;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
if (mMinifig->Parts[Type])
|
|
|
|
mMinifig->Parts[Type]->AddRef();
|
2011-09-07 23:06:51 +02:00
|
|
|
|
|
|
|
Calculate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinifigWizard::SetColor(int Type, int Color)
|
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
mMinifig->Colors[Type] = Color;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MinifigWizard::SetAngle(int Type, float Angle)
|
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
mMinifig->Angles[Type] = Angle;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|