leocad/common/object.h

183 lines
4.5 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"
2011-09-07 23:06:51 +02:00
class Matrix;
class Object;
/*
#define LC_OBJECT_NAME_LEN 80
#define LC_OBJECT_HIDDEN 0x01
#define LC_OBJECT_SELECTED 0x02
#define LC_OBJECT_FOCUSED 0x04
*/
2012-08-17 01:50:40 +02:00
enum LC_OBJECT_TYPE
2011-09-07 23:06:51 +02:00
{
2012-08-17 01:50:40 +02:00
LC_OBJECT_PIECE,
LC_OBJECT_CAMERA,
LC_OBJECT_CAMERA_TARGET,
LC_OBJECT_LIGHT,
LC_OBJECT_LIGHT_TARGET,
LC_OBJECT_CURVE,
LC_OBJECT_CURVE_POINT,
// LC_OBJECT_GROUP,
// LC_OBJECT_GROUP_PIVOT,
};
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
2012-08-17 01:50:40 +02:00
struct lcClickLine
2011-09-07 23:06:51 +02:00
{
2012-08-17 01:50:40 +02:00
lcVector3 Start;
lcVector3 End;
float MinDist;
Object* Closest;
};
2011-09-07 23:06:51 +02:00
class Object
{
public:
2012-08-17 01:50:40 +02:00
Object(LC_OBJECT_TYPE nType);
virtual ~Object();
2011-09-07 23:06:51 +02:00
public:
// Move the object.
virtual void Move(unsigned short nTime, bool bAnimation, bool bAddKey, float dx, float dy, float dz) = 0;
// Check if the object intersects the ray.
2012-08-17 01:50:40 +02:00
virtual void MinIntersectDist(lcClickLine* ClickLine) = 0;
2011-09-07 23:06:51 +02:00
// bSelecting is the action (add/remove), bFocus means "add focus if selecting"
// or "remove focus only if deselecting", bMultiple = Ctrl key is down
virtual void Select(bool bSelecting, bool bFocus, bool bMultiple) = 0;
// Check if the object intersects the volume specified by a given set of planes.
2012-08-23 20:47:37 +02:00
virtual bool IntersectsVolume(const lcVector4 Planes[6]) const = 0;
2011-09-07 23:06:51 +02:00
/*
2012-08-17 01:50:40 +02:00
virtual void UpdatePosition(unsigned short nTime, bool bAnimation) = 0;
virtual void CompareBoundingBox(float *box) { };
virtual void Render(LC_RENDER_INFO* pInfo) = 0;
2011-09-07 23:06:51 +02:00
// Query functions
2012-08-17 01:50:40 +02:00
virtual bool IsSelected() const
2011-09-07 23:06:51 +02:00
{ return (m_nState & LC_OBJECT_SELECTED) != 0; };
2012-08-17 01:50:40 +02:00
virtual bool IsFocused() const
2011-09-07 23:06:51 +02:00
{ return (m_nState & LC_OBJECT_FOCUSED) != 0; };
2012-08-17 01:50:40 +02:00
virtual bool IsVisible(unsigned short nTime, bool bAnimation) const
2011-09-07 23:06:51 +02:00
{ return (m_nState & LC_OBJECT_HIDDEN) == 0; }
const char* GetName() const
{ return m_strName; }
// State change, most classes will have to replace these functions
2012-08-17 01:50:40 +02:00
virtual void SetSelection(bool bSelect, void *pParam = NULL)
2011-09-07 23:06:51 +02:00
{
if (bSelect)
m_nState |= LC_OBJECT_SELECTED;
else
m_nState &= ~(LC_OBJECT_SELECTED | LC_OBJECT_FOCUSED);
};
2012-08-17 01:50:40 +02:00
virtual void SetFocus(bool bFocus, void *pParam = NULL)
2011-09-07 23:06:51 +02:00
{
if (bFocus)
m_nState |= (LC_OBJECT_SELECTED | LC_OBJECT_FOCUSED);
else
m_nState &= ~LC_OBJECT_FOCUSED;
};
2012-08-17 01:50:40 +02:00
virtual void SetVisible(bool bVisible)
2011-09-07 23:06:51 +02:00
{
if (bVisible)
m_nState &= ~LC_OBJECT_HIDDEN;
else
{
m_nState |= LC_OBJECT_HIDDEN;
SetSelection (false, NULL);
}
}
2012-08-17 01:50:40 +02:00
virtual bool SetColor(int nColor)
2011-09-07 23:06:51 +02:00
{ return false; };
*/
// determine the object type
2012-08-17 01:50:40 +02:00
bool IsPiece() const
2011-09-07 23:06:51 +02:00
{ return m_nObjectType == LC_OBJECT_PIECE; }
2012-08-17 01:50:40 +02:00
bool IsCamera() const
2011-09-07 23:06:51 +02:00
{ return m_nObjectType == LC_OBJECT_CAMERA; }
2012-08-17 01:50:40 +02:00
bool IsLight() const
2011-09-07 23:06:51 +02:00
{ return m_nObjectType == LC_OBJECT_LIGHT; }
2012-08-17 01:50:40 +02:00
bool IsCurve() const
2011-09-07 23:06:51 +02:00
{ return m_nObjectType == LC_OBJECT_CURVE; }
2012-08-17 01:50:40 +02:00
LC_OBJECT_TYPE GetType() const
2011-09-07 23:06:51 +02:00
{ return m_nObjectType; }
virtual const char* GetName() const = 0;
/*
// For linked lists
Object* m_pNext;
Object* m_pNextRender;
Object* m_pParent;
2012-08-17 01:50:40 +02:00
Object* GetTopAncestor() const
{ return m_pParent ? m_pParent->GetTopAncestor() : this; }
2011-09-07 23:06:51 +02:00
*/
protected:
// Str m_strName;
// unsigned char m_nState;
2012-03-23 00:44:56 +01:00
virtual bool FileLoad(lcFile& file);
virtual void FileSave(lcFile& file) const;
2011-09-07 23:06:51 +02:00
// Key handling stuff
public:
2012-08-17 01:50:40 +02:00
void CalculateSingleKey(unsigned short nTime, bool bAnimation, int keytype, float *value) const;
void ChangeKey(unsigned short time, bool animation, bool addkey, const float *param, unsigned char keytype);
virtual void InsertTime(unsigned short start, bool animation, unsigned short time);
virtual void RemoveTime(unsigned short start, bool animation, unsigned short time);
2011-09-07 23:06:51 +02:00
2012-08-17 01:50:40 +02:00
int GetKeyTypeCount() const
2011-09-07 23:06:51 +02:00
{ return m_nKeyInfoCount; }
2012-08-17 01:50:40 +02:00
const LC_OBJECT_KEY_INFO* GetKeyTypeInfo(int index) const
2011-09-07 23:06:51 +02:00
{ return &m_pKeyInfo[index]; };
2012-08-17 01:50:40 +02:00
const float* GetKeyTypeValue(int index) const
2011-09-07 23:06:51 +02:00
{ return m_pKeyValues[index]; };
protected:
2012-08-17 01:50:40 +02:00
void RegisterKeys(float *values[], LC_OBJECT_KEY_INFO* info, int count);
void CalculateKeys(unsigned short nTime, bool bAnimation);
2011-09-07 23:06:51 +02:00
private:
2012-08-17 01:50:40 +02:00
void RemoveKeys();
2011-09-07 23:06:51 +02:00
LC_OBJECT_KEY* m_pAnimationKeys;
LC_OBJECT_KEY* m_pInstructionKeys;
float **m_pKeyValues;
LC_OBJECT_KEY_INFO *m_pKeyInfo;
int m_nKeyInfoCount;
2012-08-17 01:50:40 +02:00
private:
2011-09-07 23:06:51 +02:00
LC_OBJECT_TYPE m_nObjectType;
};
#endif