leocad/common/object.h

140 lines
2.7 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
2014-07-06 08:04:09 +02:00
typedef lcuint32 lcStep;
#define LC_STEP_MAX 0xffffffff
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
{
2014-07-06 08:04:09 +02:00
lcStep Step;
2012-08-17 01:50:40 +02:00
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;
lcuint32 Section;
};
struct lcObjectRayTest
2011-09-07 23:06:51 +02:00
{
2014-05-03 18:59:57 +02:00
lcCamera* ViewCamera;
bool PiecesOnly;
2012-08-17 01:50:40 +02:00
lcVector3 Start;
lcVector3 End;
float Distance;
lcObjectSection ObjectSection;
};
struct lcObjectBoxTest
{
2014-05-03 18:59:57 +02:00
lcCamera* ViewCamera;
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(lcuint32 Section) const = 0;
virtual void SetSelected(bool Selected) = 0;
virtual void SetSelected(lcuint32 Section, bool Selected) = 0;
virtual bool IsFocused() const = 0;
virtual bool IsFocused(lcuint32 Section) const = 0;
virtual void SetFocused(lcuint32 Section, bool Focused) = 0;
virtual lcuint32 GetFocusSection() const = 0;
virtual lcVector3 GetSectionPosition(lcuint32 Section) const = 0;
2014-07-06 08:04:09 +02:00
virtual void Move(lcStep Step, bool AddKey, const lcVector3& Distance) = 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:
2014-07-06 08:04:09 +02:00
void ChangeKey(lcStep Step, bool AddKey, const float *param, unsigned char keytype);
virtual void InsertTime(lcStep Start, lcStep Time);
virtual void RemoveTime(lcStep Start, lcStep Time);
2014-01-31 00:26:55 +01:00
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);
2014-07-06 08:04:09 +02:00
void CalculateKeys(lcStep Step);
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