2017-07-19 23:20:32 +02:00
|
|
|
#pragma once
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2012-08-17 01:50:40 +02:00
|
|
|
#include "lc_math.h"
|
2014-05-01 16:55:12 +02:00
|
|
|
#include "lc_array.h"
|
2012-08-17 01:50:40 +02:00
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
typedef quint32 lcStep;
|
2014-07-06 08:04:09 +02:00
|
|
|
#define LC_STEP_MAX 0xffffffff
|
|
|
|
|
2020-04-19 04:45:21 +02:00
|
|
|
enum class lcObjectType
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2020-04-19 04:45:21 +02:00
|
|
|
Piece,
|
|
|
|
Camera,
|
|
|
|
Light
|
2012-08-17 01:50:40 +02:00
|
|
|
};
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-08-31 02:53:12 +02:00
|
|
|
template<typename T>
|
|
|
|
struct lcObjectKey
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2014-07-06 08:04:09 +02:00
|
|
|
lcStep Step;
|
2014-08-31 02:53:12 +02:00
|
|
|
T Value;
|
2012-08-17 01:50:40 +02:00
|
|
|
};
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
struct lcObjectSection
|
|
|
|
{
|
2014-05-01 20:42:11 +02:00
|
|
|
lcObject* Object;
|
2017-12-02 21:22:04 +01:00
|
|
|
quint32 Section;
|
2014-05-01 16:55:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct lcObjectRayTest
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2014-05-03 18:59:57 +02:00
|
|
|
lcCamera* ViewCamera;
|
|
|
|
bool PiecesOnly;
|
2017-11-13 04:38:07 +01:00
|
|
|
bool IgnoreSelected;
|
2012-08-17 01:50:40 +02:00
|
|
|
lcVector3 Start;
|
|
|
|
lcVector3 End;
|
2014-05-01 16:55:12 +02:00
|
|
|
float Distance;
|
|
|
|
lcObjectSection ObjectSection;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct lcObjectBoxTest
|
|
|
|
{
|
2014-05-03 18:59:57 +02:00
|
|
|
lcCamera* ViewCamera;
|
2014-05-01 16:55:12 +02:00
|
|
|
lcVector4 Planes[6];
|
2014-11-29 03:55:58 +01:00
|
|
|
lcArray<lcObject*> Objects;
|
|
|
|
};
|
|
|
|
|
2016-05-01 02:20:37 +02:00
|
|
|
#define LC_OBJECT_TRANSFORM_MOVE_X 0x001
|
|
|
|
#define LC_OBJECT_TRANSFORM_MOVE_Y 0x002
|
|
|
|
#define LC_OBJECT_TRANSFORM_MOVE_Z 0x004
|
|
|
|
#define LC_OBJECT_TRANSFORM_ROTATE_X 0x010
|
|
|
|
#define LC_OBJECT_TRANSFORM_ROTATE_Y 0x020
|
|
|
|
#define LC_OBJECT_TRANSFORM_ROTATE_Z 0x040
|
|
|
|
#define LC_OBJECT_TRANSFORM_SCALE_X 0x100
|
|
|
|
#define LC_OBJECT_TRANSFORM_SCALE_Y 0x200
|
|
|
|
#define LC_OBJECT_TRANSFORM_SCALE_Z 0x400
|
|
|
|
|
2014-05-01 20:42:11 +02:00
|
|
|
class lcObject
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-05-01 20:42:11 +02:00
|
|
|
lcObject(lcObjectType ObjectType);
|
|
|
|
virtual ~lcObject();
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2020-05-04 00:39:39 +02:00
|
|
|
lcObject(const lcObject&) = delete;
|
|
|
|
lcObject(lcObject&&) = delete;
|
|
|
|
lcObject& operator=(const lcObject&) = delete;
|
|
|
|
lcObject& operator=(lcObject&&) = delete;
|
|
|
|
|
2011-09-07 23:06:51 +02:00
|
|
|
public:
|
2014-01-31 00:26:55 +01:00
|
|
|
bool IsPiece() const
|
|
|
|
{
|
2020-04-19 04:45:21 +02:00
|
|
|
return mObjectType == lcObjectType::Piece;
|
2014-01-31 00:26:55 +01:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-01-31 00:26:55 +01:00
|
|
|
bool IsCamera() const
|
|
|
|
{
|
2020-04-19 04:45:21 +02:00
|
|
|
return mObjectType == lcObjectType::Camera;
|
2014-01-31 00:26:55 +01:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-01-31 00:26:55 +01:00
|
|
|
bool IsLight() const
|
|
|
|
{
|
2020-04-19 04:45:21 +02:00
|
|
|
return mObjectType == lcObjectType::Light;
|
2014-01-31 00:26:55 +01:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
lcObjectType GetType() const
|
2014-01-31 00:26:55 +01:00
|
|
|
{
|
2014-05-01 16:55:12 +02:00
|
|
|
return mObjectType;
|
2014-01-31 00:26:55 +01:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
virtual bool IsSelected() const = 0;
|
2017-12-02 21:22:04 +01:00
|
|
|
virtual bool IsSelected(quint32 Section) const = 0;
|
2014-05-01 16:55:12 +02:00
|
|
|
virtual void SetSelected(bool Selected) = 0;
|
2017-12-02 21:22:04 +01:00
|
|
|
virtual void SetSelected(quint32 Section, bool Selected) = 0;
|
2014-05-01 16:55:12 +02:00
|
|
|
virtual bool IsFocused() const = 0;
|
2017-12-02 21:22:04 +01:00
|
|
|
virtual bool IsFocused(quint32 Section) const = 0;
|
|
|
|
virtual void SetFocused(quint32 Section, bool Focused) = 0;
|
|
|
|
virtual quint32 GetFocusSection() const = 0;
|
2014-05-01 16:55:12 +02:00
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
virtual quint32 GetAllowedTransforms() const = 0;
|
|
|
|
virtual lcVector3 GetSectionPosition(quint32 Section) const = 0;
|
2014-05-01 16:55:12 +02:00
|
|
|
virtual void RayTest(lcObjectRayTest& ObjectRayTest) const = 0;
|
|
|
|
virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const = 0;
|
2018-04-08 02:17:32 +02:00
|
|
|
virtual void DrawInterface(lcContext* Context, const lcScene& Scene) const = 0;
|
2018-02-24 21:47:19 +01:00
|
|
|
virtual void RemoveKeyFrames() = 0;
|
2020-12-14 01:27:21 +01:00
|
|
|
virtual QString GetName() const = 0;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-01-31 00:26:55 +01:00
|
|
|
protected:
|
2014-09-05 02:24:28 +02:00
|
|
|
template<typename T>
|
|
|
|
void SaveKeysLDraw(QTextStream& Stream, const lcArray<lcObjectKey<T>>& Keys, const char* KeyName) const
|
|
|
|
{
|
|
|
|
const int Count = sizeof(T) / sizeof(float);
|
|
|
|
for (int KeyIdx = 0; KeyIdx < Keys.GetSize(); KeyIdx++)
|
|
|
|
{
|
2016-04-19 20:37:50 +02:00
|
|
|
const lcObjectKey<T>& Key = Keys[KeyIdx];
|
2014-09-05 02:24:28 +02:00
|
|
|
Stream << QLatin1String("0 !LEOCAD ") << KeyName << Key.Step << ' ';
|
|
|
|
for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++)
|
2015-03-24 16:12:39 +01:00
|
|
|
Stream << ((float*)&Key.Value)[ValueIdx] << ' ';
|
2014-09-08 21:42:20 +02:00
|
|
|
Stream << QLatin1String("\r\n");
|
2014-09-05 02:24:28 +02:00
|
|
|
}
|
|
|
|
}
|
2014-09-02 05:44:51 +02:00
|
|
|
|
|
|
|
template<typename T>
|
2014-09-05 02:24:28 +02:00
|
|
|
void LoadKeysLDraw(QTextStream& Stream, lcArray<lcObjectKey<T>>& Keys)
|
2014-09-02 05:44:51 +02:00
|
|
|
{
|
2014-09-03 16:34:53 +02:00
|
|
|
QString Token;
|
|
|
|
Stream >> Token;
|
2014-09-02 05:44:51 +02:00
|
|
|
|
|
|
|
int Step = Token.toInt();
|
|
|
|
T Value;
|
|
|
|
|
|
|
|
const int Count = sizeof(T) / sizeof(float);
|
|
|
|
for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++)
|
2015-01-10 21:30:37 +01:00
|
|
|
Stream >> ((float*)&Value)[ValueIdx];
|
2014-09-02 05:44:51 +02:00
|
|
|
|
2015-03-24 16:12:39 +01:00
|
|
|
ChangeKey(Keys, Value, Step, true);
|
2014-09-02 05:44:51 +02:00
|
|
|
}
|
|
|
|
|
2014-08-31 02:53:12 +02:00
|
|
|
template<typename T>
|
|
|
|
const T& CalculateKey(const lcArray<lcObjectKey<T>>& Keys, lcStep Step)
|
2014-01-31 00:26:55 +01:00
|
|
|
{
|
2016-04-19 20:37:50 +02:00
|
|
|
const lcObjectKey<T>* PreviousKey = &Keys[0];
|
2014-08-31 02:53:12 +02:00
|
|
|
|
|
|
|
for (int KeyIdx = 0; KeyIdx < Keys.GetSize(); KeyIdx++)
|
|
|
|
{
|
|
|
|
if (Keys[KeyIdx].Step > Step)
|
|
|
|
break;
|
|
|
|
|
|
|
|
PreviousKey = &Keys[KeyIdx];
|
|
|
|
}
|
|
|
|
|
|
|
|
return PreviousKey->Value;
|
2014-01-31 00:26:55 +01:00
|
|
|
}
|
|
|
|
|
2014-08-31 02:53:12 +02:00
|
|
|
template<typename T>
|
|
|
|
void ChangeKey(lcArray<lcObjectKey<T>>& Keys, const T& Value, lcStep Step, bool AddKey)
|
2014-01-31 00:26:55 +01:00
|
|
|
{
|
2014-08-31 02:53:12 +02:00
|
|
|
for (int KeyIdx = 0; KeyIdx < Keys.GetSize(); KeyIdx++)
|
|
|
|
{
|
2020-03-23 04:32:04 +01:00
|
|
|
lcObjectKey<T>* Key = &Keys[KeyIdx];
|
2014-08-31 02:53:12 +02:00
|
|
|
|
|
|
|
if (Key->Step == Step)
|
|
|
|
{
|
|
|
|
Key->Value = Value;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Key->Step > Step)
|
|
|
|
{
|
|
|
|
if (AddKey)
|
|
|
|
{
|
|
|
|
Key = &Keys.InsertAt(KeyIdx);
|
|
|
|
Key->Step = Step;
|
|
|
|
}
|
|
|
|
else if (KeyIdx)
|
|
|
|
Key = &Keys[KeyIdx - 1];
|
|
|
|
|
|
|
|
Key->Value = Value;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AddKey || Keys.GetSize() == 0)
|
|
|
|
{
|
2020-03-23 04:32:04 +01:00
|
|
|
lcObjectKey<T>* Key = &Keys.Add();
|
2014-08-31 02:53:12 +02:00
|
|
|
|
|
|
|
Key->Step = Step;
|
|
|
|
Key->Value = Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-23 04:32:04 +01:00
|
|
|
lcObjectKey<T>* Key = &Keys[Keys.GetSize() - 1];
|
2014-08-31 02:53:12 +02:00
|
|
|
Key->Value = Value;
|
|
|
|
}
|
2014-01-31 00:26:55 +01:00
|
|
|
}
|
|
|
|
|
2014-08-31 02:53:12 +02:00
|
|
|
template<typename T>
|
|
|
|
void InsertTime(lcArray<lcObjectKey<T>>& Keys, lcStep Start, lcStep Time)
|
2014-01-31 00:26:55 +01:00
|
|
|
{
|
2014-08-31 02:53:12 +02:00
|
|
|
bool EndKey = false;
|
|
|
|
|
|
|
|
for (int KeyIdx = 0; KeyIdx < Keys.GetSize(); KeyIdx++)
|
|
|
|
{
|
|
|
|
lcObjectKey<T>& Key = Keys[KeyIdx];
|
|
|
|
|
|
|
|
if ((Key.Step < Start) || (Key.Step == 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (EndKey)
|
|
|
|
{
|
|
|
|
Keys.RemoveIndex(KeyIdx);
|
|
|
|
KeyIdx--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Key.Step >= LC_STEP_MAX - Time)
|
|
|
|
{
|
|
|
|
Key.Step = LC_STEP_MAX;
|
|
|
|
EndKey = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Key.Step += Time;
|
|
|
|
}
|
2014-01-31 00:26:55 +01:00
|
|
|
}
|
|
|
|
|
2014-08-31 02:53:12 +02:00
|
|
|
template<typename T>
|
|
|
|
void RemoveTime(lcArray<lcObjectKey<T>>& Keys, lcStep Start, lcStep Time)
|
|
|
|
{
|
|
|
|
for (int KeyIdx = 0; KeyIdx < Keys.GetSize(); KeyIdx++)
|
|
|
|
{
|
|
|
|
lcObjectKey<T>& Key = Keys[KeyIdx];
|
|
|
|
|
|
|
|
if ((Key.Step < Start) || (Key.Step == 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Key.Step < Start + Time)
|
|
|
|
{
|
|
|
|
Keys.RemoveIndex(KeyIdx);
|
|
|
|
KeyIdx--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Key.Step -= Time;
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2012-08-17 01:50:40 +02:00
|
|
|
private:
|
2014-05-01 16:55:12 +02:00
|
|
|
lcObjectType mObjectType;
|
2011-09-07 23:06:51 +02:00
|
|
|
};
|
|
|
|
|