leocad/common/object.h

145 lines
2.9 KiB
C
Raw Normal View History

2011-09-07 23:06:51 +02:00
#ifndef _OBJECT_H_
#define _OBJECT_H_
2012-08-17 01:50:40 +02:00
#include "lc_math.h"
#include "lc_array.h"
2012-08-17 01:50:40 +02:00
enum lcObjectType
2011-09-07 23:06:51 +02:00
{
2012-08-17 01:50:40 +02:00
LC_OBJECT_PIECE,
LC_OBJECT_CAMERA,
LC_OBJECT_LIGHT
2012-08-17 01:50:40 +02:00
};
2011-09-07 23:06:51 +02:00
// key handling
2012-08-17 01:50:40 +02:00
struct LC_OBJECT_KEY
2011-09-07 23:06:51 +02:00
{
2012-08-17 01:50:40 +02:00
unsigned short time;
float param[4];
unsigned char type;
LC_OBJECT_KEY* next;
};
2011-09-07 23:06:51 +02:00
2012-08-17 01:50:40 +02:00
struct LC_OBJECT_KEY_INFO
2011-09-07 23:06:51 +02:00
{
2012-08-17 01:50:40 +02:00
const char *description;
unsigned char size; // number of floats
unsigned char type;
};
2011-09-07 23:06:51 +02:00
struct lcObjectSection
{
2014-05-01 20:42:11 +02:00
lcObject* Object;
lcuintptr Section;
};
inline lcObjectSection lcMakeObjectSection(Object* Object, lcuintptr Section)
{
lcObjectSection ObjectSection;
ObjectSection.Object = Object;
ObjectSection.Section = Section;
return ObjectSection;
}
struct lcObjectRayTest
2011-09-07 23:06:51 +02:00
{
2012-08-17 01:50:40 +02:00
lcVector3 Start;
lcVector3 End;
float Distance;
lcObjectSection ObjectSection;
};
struct lcObjectBoxTest
{
lcVector4 Planes[6];
lcArray<lcObjectSection> ObjectSections;
2012-08-17 01:50:40 +02:00
};
2011-09-07 23:06:51 +02:00
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
public:
2014-01-31 00:26:55 +01:00
bool IsPiece() const
{
return mObjectType == LC_OBJECT_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
{
return mObjectType == LC_OBJECT_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
{
return mObjectType == LC_OBJECT_LIGHT;
2014-01-31 00:26:55 +01:00
}
2011-09-07 23:06:51 +02:00
lcObjectType GetType() const
2014-01-31 00:26:55 +01:00
{
return mObjectType;
2014-01-31 00:26:55 +01:00
}
2011-09-07 23:06:51 +02:00
virtual bool IsSelected() const = 0;
virtual bool IsSelected(lcuintptr Section) const = 0;
virtual void SetSelected(bool Selected) = 0;
virtual void SetSelected(lcuintptr Section, bool Selected) = 0;
virtual bool IsFocused() const = 0;
virtual bool IsFocused(lcuintptr Section) const = 0;
virtual void SetFocused(lcuintptr Section, bool Focused) = 0;
virtual lcuintptr GetFocusSection() const = 0;
virtual lcVector3 GetSectionPosition(lcuintptr Section) const = 0;
virtual void Move(unsigned short nTime, bool bAddKey, float dx, float dy, float dz) = 0;
virtual void RayTest(lcObjectRayTest& ObjectRayTest) const = 0;
virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const = 0;
2014-01-31 00:26:55 +01:00
virtual const char* GetName() const = 0;
2011-09-07 23:06:51 +02:00
2014-01-31 00:26:55 +01:00
protected:
virtual bool FileLoad(lcFile& file);
virtual void FileSave(lcFile& file) const;
2011-09-07 23:06:51 +02:00
2014-01-31 00:26:55 +01:00
public:
void CalculateSingleKey(unsigned short nTime, int keytype, float *value) const;
void ChangeKey(unsigned short time, bool addkey, const float *param, unsigned char keytype);
virtual void InsertTime(unsigned short start, unsigned short time);
virtual void RemoveTime(unsigned short start, unsigned short time);
int GetKeyTypeCount() const
{
return m_nKeyInfoCount;
}
const LC_OBJECT_KEY_INFO* GetKeyTypeInfo(int index) const
{
return &m_pKeyInfo[index];
}
const float* GetKeyTypeValue(int index) const
{
return m_pKeyValues[index];
}
protected:
void RegisterKeys(float *values[], LC_OBJECT_KEY_INFO* info, int count);
void CalculateKeys(unsigned short nTime);
2011-09-07 23:06:51 +02:00
2014-01-31 00:26:55 +01:00
private:
void RemoveKeys();
2011-09-07 23:06:51 +02:00
2014-01-31 00:26:55 +01:00
LC_OBJECT_KEY* m_pInstructionKeys;
float **m_pKeyValues;
2011-09-07 23:06:51 +02:00
2014-01-31 00:26:55 +01:00
LC_OBJECT_KEY_INFO *m_pKeyInfo;
int m_nKeyInfoCount;
2011-09-07 23:06:51 +02:00
2012-08-17 01:50:40 +02:00
private:
lcObjectType mObjectType;
2011-09-07 23:06:51 +02:00
};
#endif