leocad/common/light.h

234 lines
5.4 KiB
C
Raw Normal View History

#pragma once
2011-09-07 23:06:51 +02:00
#include "object.h"
2012-06-07 02:08:59 +02:00
#include "lc_math.h"
2011-09-07 23:06:51 +02:00
#define LC_LIGHT_HIDDEN 0x0001
#define LC_LIGHT_DISABLED 0x0002
#define LC_LIGHT_SPOT 0x0004
#define LC_LIGHT_DIRECTIONAL 0x0008
#define LC_LIGHT_POSITION_SELECTED 0x0010
#define LC_LIGHT_POSITION_FOCUSED 0x0020
#define LC_LIGHT_TARGET_SELECTED 0x0040
#define LC_LIGHT_TARGET_FOCUSED 0x0080
#define LC_LIGHT_SELECTION_MASK (LC_LIGHT_POSITION_SELECTED | LC_LIGHT_TARGET_SELECTED)
#define LC_LIGHT_FOCUS_MASK (LC_LIGHT_POSITION_FOCUSED | LC_LIGHT_TARGET_FOCUSED)
enum lcLightSection
{
LC_LIGHT_SECTION_POSITION,
LC_LIGHT_SECTION_TARGET
};
2014-05-01 20:42:11 +02:00
class lcLight : public lcObject
2011-09-07 23:06:51 +02:00
{
public:
2014-05-01 20:42:11 +02:00
lcLight(float px, float py, float pz);
lcLight(float px, float py, float pz, float tx, float ty, float tz);
~lcLight();
2011-09-07 23:06:51 +02:00
2020-05-04 00:39:39 +02:00
lcLight(const lcLight&) = delete;
lcLight(lcLight&&) = delete;
lcLight& operator=(const lcLight&) = delete;
lcLight& operator=(lcLight&&) = delete;
bool IsPointLight() const
{
return (mState & (LC_LIGHT_SPOT | LC_LIGHT_DIRECTIONAL)) == 0;
}
bool IsSpotLight() const
2011-09-07 23:06:51 +02:00
{
return (mState & LC_LIGHT_SPOT) != 0;
2011-09-07 23:06:51 +02:00
}
bool IsDirectionalLight() const
{
return (mState & LC_LIGHT_DIRECTIONAL) != 0;
}
2011-09-07 23:06:51 +02:00
bool IsSelected() const override
{
return (mState & LC_LIGHT_SELECTION_MASK) != 0;
}
2011-09-07 23:06:51 +02:00
bool IsSelected(quint32 Section) const override
{
switch (Section)
{
case LC_LIGHT_SECTION_POSITION:
return (mState & LC_LIGHT_POSITION_SELECTED) != 0;
break;
case LC_LIGHT_SECTION_TARGET:
return (mState & LC_LIGHT_TARGET_SELECTED) != 0;
break;
}
return false;
}
2011-09-07 23:06:51 +02:00
void SetSelected(bool Selected) override
{
if (Selected)
{
if (IsPointLight())
mState |= LC_LIGHT_POSITION_SELECTED;
else
mState |= LC_LIGHT_SELECTION_MASK;
}
else
mState &= ~(LC_LIGHT_SELECTION_MASK | LC_LIGHT_FOCUS_MASK);
}
2011-09-07 23:06:51 +02:00
void SetSelected(quint32 Section, bool Selected) override
{
switch (Section)
{
case LC_LIGHT_SECTION_POSITION:
if (Selected)
mState |= LC_LIGHT_POSITION_SELECTED;
else
mState &= ~(LC_LIGHT_POSITION_SELECTED | LC_LIGHT_POSITION_FOCUSED);
break;
case LC_LIGHT_SECTION_TARGET:
if (Selected)
{
if (!IsPointLight())
mState |= LC_LIGHT_TARGET_SELECTED;
}
else
mState &= ~(LC_LIGHT_TARGET_SELECTED | LC_LIGHT_TARGET_FOCUSED);
break;
}
}
bool IsFocused() const override
{
return (mState & LC_LIGHT_FOCUS_MASK) != 0;
}
bool IsFocused(quint32 Section) const override
{
switch (Section)
{
case LC_LIGHT_SECTION_POSITION:
return (mState & LC_LIGHT_POSITION_FOCUSED) != 0;
break;
case LC_LIGHT_SECTION_TARGET:
return (mState & LC_LIGHT_TARGET_FOCUSED) != 0;
break;
}
return false;
}
void SetFocused(quint32 Section, bool Focused) override
{
switch (Section)
{
case LC_LIGHT_SECTION_POSITION:
if (Focused)
mState |= LC_LIGHT_POSITION_SELECTED | LC_LIGHT_POSITION_FOCUSED;
else
mState &= ~(LC_LIGHT_POSITION_SELECTED | LC_LIGHT_POSITION_FOCUSED);
break;
case LC_LIGHT_SECTION_TARGET:
if (Focused)
{
if (!IsPointLight())
mState |= LC_LIGHT_TARGET_SELECTED | LC_LIGHT_TARGET_FOCUSED;
}
else
mState &= ~(LC_LIGHT_TARGET_SELECTED | LC_LIGHT_TARGET_FOCUSED);
break;
}
}
quint32 GetFocusSection() const override
{
if (mState & LC_LIGHT_POSITION_FOCUSED)
return LC_LIGHT_SECTION_POSITION;
if (!IsPointLight() && (mState & LC_LIGHT_TARGET_FOCUSED))
return LC_LIGHT_SECTION_TARGET;
2017-12-13 07:17:14 +01:00
return ~0U;
}
quint32 GetAllowedTransforms() const override
{
return LC_OBJECT_TRANSFORM_MOVE_X | LC_OBJECT_TRANSFORM_MOVE_Y | LC_OBJECT_TRANSFORM_MOVE_Z;
}
lcVector3 GetSectionPosition(quint32 Section) const override
{
switch (Section)
{
case LC_LIGHT_SECTION_POSITION:
return mPosition;
case LC_LIGHT_SECTION_TARGET:
return mTargetPosition;
}
return lcVector3(0.0f, 0.0f, 0.0f);
}
2011-09-07 23:06:51 +02:00
2014-09-05 02:24:28 +02:00
void SaveLDraw(QTextStream& Stream) const;
2014-08-30 01:52:42 +02:00
2011-09-07 23:06:51 +02:00
public:
void RayTest(lcObjectRayTest& ObjectRayTest) const override;
void BoxTest(lcObjectBoxTest& ObjectBoxTest) const override;
void DrawInterface(lcContext* Context, const lcScene& Scene) const override;
void RemoveKeyFrames() override;
2014-08-31 02:53:12 +02:00
void InsertTime(lcStep Start, lcStep Time);
void RemoveTime(lcStep Start, lcStep Time);
bool IsVisible() const
{ return (mState & LC_LIGHT_HIDDEN) == 0; }
2020-12-14 01:27:21 +01:00
QString GetName() const override
{
return mName;
}
2011-09-07 23:06:51 +02:00
2016-02-19 18:53:54 +01:00
void CompareBoundingBox(lcVector3& Min, lcVector3& Max);
2014-07-06 08:04:09 +02:00
void UpdatePosition(lcStep Step);
void MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance);
bool Setup(int LightIndex);
2014-08-07 17:22:33 +02:00
void CreateName(const lcArray<lcLight*>& Lights);
2011-09-07 23:06:51 +02:00
2012-08-17 01:50:40 +02:00
// Temporary parameters
lcMatrix44 mWorldLight;
2012-06-07 02:08:59 +02:00
lcVector3 mPosition;
lcVector3 mTargetPosition;
2012-08-17 01:50:40 +02:00
lcVector4 mAmbientColor;
lcVector4 mDiffuseColor;
lcVector4 mSpecularColor;
2014-08-31 02:53:12 +02:00
lcVector3 mAttenuation;
2012-08-17 01:50:40 +02:00
float mSpotCutoff;
float mSpotExponent;
2012-06-07 02:08:59 +02:00
2011-09-07 23:06:51 +02:00
protected:
lcObjectKeyArray<lcVector3> mPositionKeys;
lcObjectKeyArray<lcVector3> mTargetPositionKeys;
lcObjectKeyArray<lcVector4> mAmbientColorKeys;
lcObjectKeyArray<lcVector4> mDiffuseColorKeys;
lcObjectKeyArray<lcVector4> mSpecularColorKeys;
lcObjectKeyArray<lcVector3> mAttenuationKeys;
lcObjectKeyArray<float> mSpotCutoffKeys;
lcObjectKeyArray<float> mSpotExponentKeys;
2014-08-31 02:53:12 +02:00
void Initialize(const lcVector3& Position, const lcVector3& TargetPosition);
2012-08-17 01:50:40 +02:00
2015-05-17 01:04:35 +02:00
void DrawPointLight(lcContext* Context) const;
void DrawSpotLight(lcContext* Context) const;
2015-04-19 03:10:01 +02:00
2020-12-14 01:27:21 +01:00
QString mName;
2017-12-02 21:22:04 +01:00
quint32 mState;
2011-09-07 23:06:51 +02:00
};