2017-07-19 14:20:32 -07:00
|
|
|
#pragma once
|
2011-09-07 21:06:51 +00:00
|
|
|
|
|
|
|
#include "object.h"
|
2012-05-28 23:33:22 +00:00
|
|
|
#include "lc_math.h"
|
2013-08-15 23:43:18 +00:00
|
|
|
#include "lc_array.h"
|
2011-09-07 21:06:51 +00:00
|
|
|
|
2014-05-01 14:55:12 +00:00
|
|
|
#define LC_CAMERA_HIDDEN 0x0001
|
|
|
|
#define LC_CAMERA_SIMPLE 0x0002
|
2014-05-03 01:22:24 +00:00
|
|
|
#define LC_CAMERA_ORTHO 0x0004
|
2014-05-01 14:55:12 +00:00
|
|
|
#define LC_CAMERA_POSITION_SELECTED 0x0010
|
|
|
|
#define LC_CAMERA_POSITION_FOCUSED 0x0020
|
|
|
|
#define LC_CAMERA_TARGET_SELECTED 0x0040
|
|
|
|
#define LC_CAMERA_TARGET_FOCUSED 0x0080
|
|
|
|
#define LC_CAMERA_UPVECTOR_SELECTED 0x0100
|
|
|
|
#define LC_CAMERA_UPVECTOR_FOCUSED 0x0200
|
|
|
|
|
|
|
|
#define LC_CAMERA_SELECTION_MASK (LC_CAMERA_POSITION_SELECTED | LC_CAMERA_TARGET_SELECTED | LC_CAMERA_UPVECTOR_SELECTED)
|
|
|
|
#define LC_CAMERA_FOCUS_MASK (LC_CAMERA_POSITION_FOCUSED | LC_CAMERA_TARGET_FOCUSED | LC_CAMERA_UPVECTOR_FOCUSED)
|
|
|
|
|
2020-12-12 16:58:40 -08:00
|
|
|
enum class lcViewpoint
|
2012-08-20 04:05:56 +00:00
|
|
|
{
|
2020-12-12 16:58:40 -08:00
|
|
|
Front,
|
|
|
|
Back,
|
|
|
|
Top,
|
|
|
|
Bottom,
|
|
|
|
Left,
|
|
|
|
Right,
|
2021-01-01 15:04:27 -08:00
|
|
|
Home,
|
|
|
|
Count
|
2012-08-20 04:05:56 +00:00
|
|
|
};
|
2011-09-07 21:06:51 +00:00
|
|
|
|
2014-05-01 14:55:12 +00:00
|
|
|
enum lcCameraSection
|
|
|
|
{
|
|
|
|
LC_CAMERA_SECTION_POSITION,
|
|
|
|
LC_CAMERA_SECTION_TARGET,
|
|
|
|
LC_CAMERA_SECTION_UPVECTOR
|
|
|
|
};
|
|
|
|
|
2014-05-01 18:42:11 +00:00
|
|
|
class lcCamera : public lcObject
|
2011-09-07 21:06:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-05-01 18:42:11 +00:00
|
|
|
lcCamera(bool Simple);
|
|
|
|
lcCamera(float ex, float ey, float ez, float tx, float ty, float tz);
|
2020-03-22 15:44:41 -07:00
|
|
|
~lcCamera();
|
2011-09-07 21:06:51 +00:00
|
|
|
|
2020-05-03 15:39:39 -07:00
|
|
|
lcCamera(const lcCamera&) = delete;
|
|
|
|
lcCamera& operator=(const lcCamera&) = delete;
|
2021-01-01 15:04:27 -08:00
|
|
|
|
|
|
|
static lcViewpoint GetViewpoint(const QString& ViewpointName);
|
2020-05-03 15:39:39 -07:00
|
|
|
|
2020-12-13 16:27:21 -08:00
|
|
|
QString GetName() const override
|
2012-08-20 04:05:56 +00:00
|
|
|
{
|
2020-12-13 16:27:21 -08:00
|
|
|
return mName;
|
2012-08-20 04:05:56 +00:00
|
|
|
}
|
2011-09-07 21:06:51 +00:00
|
|
|
|
2020-12-13 16:27:21 -08:00
|
|
|
void SetName(const QString& Name);
|
2014-08-07 15:22:33 +00:00
|
|
|
void CreateName(const lcArray<lcCamera*>& Cameras);
|
2012-08-22 01:13:32 +00:00
|
|
|
|
2014-05-01 14:55:12 +00:00
|
|
|
bool IsSimple() const
|
2012-08-20 04:05:56 +00:00
|
|
|
{
|
2014-05-01 14:55:12 +00:00
|
|
|
return (mState & LC_CAMERA_SIMPLE) != 0;
|
2012-08-20 04:05:56 +00:00
|
|
|
}
|
2011-09-07 21:06:51 +00:00
|
|
|
|
2014-05-03 01:22:24 +00:00
|
|
|
bool IsOrtho() const
|
|
|
|
{
|
|
|
|
return (mState & LC_CAMERA_ORTHO) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetOrtho(bool Ortho)
|
|
|
|
{
|
|
|
|
if (Ortho)
|
|
|
|
mState |= LC_CAMERA_ORTHO;
|
|
|
|
else
|
|
|
|
mState &= ~LC_CAMERA_ORTHO;
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
bool IsSelected() const override
|
2012-08-20 04:05:56 +00:00
|
|
|
{
|
2014-05-01 14:55:12 +00:00
|
|
|
return (mState & LC_CAMERA_SELECTION_MASK) != 0;
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
bool IsSelected(quint32 Section) const override
|
2014-05-01 14:55:12 +00:00
|
|
|
{
|
|
|
|
switch (Section)
|
|
|
|
{
|
|
|
|
case LC_CAMERA_SECTION_POSITION:
|
|
|
|
return (mState & LC_CAMERA_POSITION_SELECTED) != 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LC_CAMERA_SECTION_TARGET:
|
|
|
|
return (mState & LC_CAMERA_TARGET_SELECTED) != 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LC_CAMERA_SECTION_UPVECTOR:
|
|
|
|
return (mState & LC_CAMERA_UPVECTOR_SELECTED) != 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
void SetSelected(bool Selected) override
|
2014-05-01 14:55:12 +00:00
|
|
|
{
|
|
|
|
if (Selected)
|
|
|
|
mState |= LC_CAMERA_SELECTION_MASK;
|
|
|
|
else
|
|
|
|
mState &= ~(LC_CAMERA_SELECTION_MASK | LC_CAMERA_FOCUS_MASK);
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
void SetSelected(quint32 Section, bool Selected) override
|
2014-05-01 14:55:12 +00:00
|
|
|
{
|
|
|
|
switch (Section)
|
|
|
|
{
|
|
|
|
case LC_CAMERA_SECTION_POSITION:
|
|
|
|
if (Selected)
|
|
|
|
mState |= LC_CAMERA_POSITION_SELECTED;
|
|
|
|
else
|
|
|
|
mState &= ~(LC_CAMERA_POSITION_SELECTED | LC_CAMERA_POSITION_FOCUSED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LC_CAMERA_SECTION_TARGET:
|
|
|
|
if (Selected)
|
|
|
|
mState |= LC_CAMERA_TARGET_SELECTED;
|
|
|
|
else
|
|
|
|
mState &= ~(LC_CAMERA_TARGET_SELECTED | LC_CAMERA_TARGET_FOCUSED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LC_CAMERA_SECTION_UPVECTOR:
|
|
|
|
if (Selected)
|
|
|
|
mState |= LC_CAMERA_UPVECTOR_SELECTED;
|
|
|
|
else
|
|
|
|
mState &= ~(LC_CAMERA_UPVECTOR_SELECTED | LC_CAMERA_UPVECTOR_FOCUSED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
bool IsFocused() const override
|
2014-05-01 14:55:12 +00:00
|
|
|
{
|
|
|
|
return (mState & LC_CAMERA_FOCUS_MASK) != 0;
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
bool IsFocused(quint32 Section) const override
|
2014-05-01 14:55:12 +00:00
|
|
|
{
|
|
|
|
switch (Section)
|
|
|
|
{
|
|
|
|
case LC_CAMERA_SECTION_POSITION:
|
|
|
|
return (mState & LC_CAMERA_POSITION_FOCUSED) != 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LC_CAMERA_SECTION_TARGET:
|
|
|
|
return (mState & LC_CAMERA_TARGET_FOCUSED) != 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LC_CAMERA_SECTION_UPVECTOR:
|
|
|
|
return (mState & LC_CAMERA_UPVECTOR_FOCUSED) != 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
void SetFocused(quint32 Section, bool Focus) override
|
2014-05-01 14:55:12 +00:00
|
|
|
{
|
|
|
|
switch (Section)
|
|
|
|
{
|
|
|
|
case LC_CAMERA_SECTION_POSITION:
|
|
|
|
if (Focus)
|
|
|
|
mState |= LC_CAMERA_POSITION_SELECTED | LC_CAMERA_POSITION_FOCUSED;
|
|
|
|
else
|
|
|
|
mState &= ~(LC_CAMERA_POSITION_SELECTED | LC_CAMERA_POSITION_FOCUSED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LC_CAMERA_SECTION_TARGET:
|
|
|
|
if (Focus)
|
|
|
|
mState |= LC_CAMERA_TARGET_SELECTED | LC_CAMERA_TARGET_FOCUSED;
|
|
|
|
else
|
|
|
|
mState &= ~(LC_CAMERA_TARGET_SELECTED | LC_CAMERA_TARGET_FOCUSED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LC_CAMERA_SECTION_UPVECTOR:
|
|
|
|
if (Focus)
|
|
|
|
mState |= LC_CAMERA_UPVECTOR_SELECTED | LC_CAMERA_UPVECTOR_FOCUSED;
|
|
|
|
else
|
|
|
|
mState &= ~(LC_CAMERA_UPVECTOR_SELECTED | LC_CAMERA_UPVECTOR_FOCUSED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
quint32 GetFocusSection() const override
|
2014-05-01 14:55:12 +00:00
|
|
|
{
|
|
|
|
if (mState & LC_CAMERA_POSITION_FOCUSED)
|
|
|
|
return LC_CAMERA_SECTION_POSITION;
|
|
|
|
|
|
|
|
if (mState & LC_CAMERA_TARGET_FOCUSED)
|
|
|
|
return LC_CAMERA_SECTION_TARGET;
|
|
|
|
|
|
|
|
if (mState & LC_CAMERA_UPVECTOR_FOCUSED)
|
|
|
|
return LC_CAMERA_SECTION_UPVECTOR;
|
|
|
|
|
2017-12-12 22:17:14 -08:00
|
|
|
return ~0U;
|
2014-05-01 14:55:12 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
quint32 GetAllowedTransforms() const override
|
2016-05-01 00:20:37 +00:00
|
|
|
{
|
|
|
|
return LC_OBJECT_TRANSFORM_MOVE_X | LC_OBJECT_TRANSFORM_MOVE_Y | LC_OBJECT_TRANSFORM_MOVE_Z;
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
lcVector3 GetSectionPosition(quint32 Section) const override
|
2014-05-01 14:55:12 +00:00
|
|
|
{
|
|
|
|
switch (Section)
|
|
|
|
{
|
|
|
|
case LC_CAMERA_SECTION_POSITION:
|
|
|
|
return mPosition;
|
|
|
|
|
|
|
|
case LC_CAMERA_SECTION_TARGET:
|
|
|
|
return mTargetPosition;
|
|
|
|
|
|
|
|
case LC_CAMERA_SECTION_UPVECTOR:
|
2015-12-22 22:44:46 +00:00
|
|
|
return lcMul31(lcVector3(0, 25, 0), lcMatrix44AffineInverse(mWorldView));
|
2014-05-01 14:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return lcVector3(0.0f, 0.0f, 0.0f);
|
2012-08-20 04:05:56 +00:00
|
|
|
}
|
2011-09-07 21:06:51 +00:00
|
|
|
|
2014-09-05 00:24:28 +00:00
|
|
|
void SaveLDraw(QTextStream& Stream) const;
|
2014-09-03 14:34:53 +00:00
|
|
|
bool ParseLDrawLine(QTextStream& Stream);
|
2014-09-02 03:44:51 +00:00
|
|
|
|
2011-09-07 21:06:51 +00:00
|
|
|
public:
|
2014-05-01 14:55:12 +00:00
|
|
|
bool IsVisible() const
|
|
|
|
{ return (mState & LC_CAMERA_HIDDEN) == 0; }
|
2014-09-02 03:44:51 +00:00
|
|
|
|
2014-08-29 23:52:42 +00:00
|
|
|
bool IsHidden() const
|
2014-09-02 03:44:51 +00:00
|
|
|
{
|
|
|
|
return (mState & LC_CAMERA_HIDDEN) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetHidden(bool Hidden)
|
|
|
|
{
|
|
|
|
if (Hidden)
|
|
|
|
mState |= LC_CAMERA_HIDDEN;
|
|
|
|
else
|
|
|
|
mState &= ~LC_CAMERA_HIDDEN;
|
|
|
|
}
|
2011-09-07 21:06:51 +00:00
|
|
|
|
2014-08-31 00:53:12 +00:00
|
|
|
void SetPosition(const lcVector3& Position, lcStep Step, bool AddKey)
|
|
|
|
{
|
2021-01-05 11:26:01 -08:00
|
|
|
mPositionKeys.ChangeKey(Position, Step, AddKey);
|
2014-08-31 00:53:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetTargetPosition(const lcVector3& TargetPosition, lcStep Step, bool AddKey)
|
|
|
|
{
|
2021-01-05 11:26:01 -08:00
|
|
|
mTargetPositionKeys.ChangeKey(TargetPosition, Step, AddKey);
|
2014-08-31 00:53:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetUpVector(const lcVector3& UpVector, lcStep Step, bool AddKey)
|
|
|
|
{
|
2021-01-05 11:26:01 -08:00
|
|
|
mPositionKeys.ChangeKey(UpVector, Step, AddKey);
|
2014-08-31 00:53:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-15 02:24:08 +00:00
|
|
|
float GetOrthoHeight() const
|
|
|
|
{
|
|
|
|
// Compute the FOV/plane intersection radius.
|
|
|
|
// d d
|
|
|
|
// a = 2 atan(------) => ~ a = --- => d = af
|
|
|
|
// 2f f
|
|
|
|
float f = (mPosition - mTargetPosition).Length();
|
|
|
|
return (m_fovy * f) * (LC_PI / 180.0f);
|
|
|
|
}
|
|
|
|
|
2011-09-07 21:06:51 +00:00
|
|
|
public:
|
2020-03-22 15:44:41 -07:00
|
|
|
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-05-01 14:55:12 +00:00
|
|
|
|
2014-08-31 00:53:12 +00:00
|
|
|
void InsertTime(lcStep Start, lcStep Time);
|
|
|
|
void RemoveTime(lcStep Start, lcStep Time);
|
|
|
|
|
2021-01-05 11:26:01 -08:00
|
|
|
static bool FileLoad(lcFile& file);
|
2011-09-07 21:06:51 +00:00
|
|
|
|
2016-02-19 17:53:54 +00:00
|
|
|
void CompareBoundingBox(lcVector3& Min, lcVector3& Max);
|
2014-07-06 06:04:09 +00:00
|
|
|
void UpdatePosition(lcStep Step);
|
2019-08-11 11:38:46 -07:00
|
|
|
void CopyPosition(const lcCamera* Camera);
|
|
|
|
void CopySettings(const lcCamera* Camera);
|
2011-09-07 21:06:51 +00:00
|
|
|
|
2020-12-31 10:22:12 -08:00
|
|
|
void ZoomExtents(float AspectRatio, const lcVector3& Center, const std::vector<lcVector3>& Points, lcStep Step, bool AddKey);
|
2015-02-15 02:24:08 +00:00
|
|
|
void ZoomRegion(float AspectRatio, const lcVector3& Position, const lcVector3& TargetPosition, const lcVector3* Corners, lcStep Step, bool AddKey);
|
2014-07-06 06:04:09 +00:00
|
|
|
void Zoom(float Distance, lcStep Step, bool AddKey);
|
2015-02-08 21:05:50 +00:00
|
|
|
void Pan(const lcVector3& Distance, lcStep Step, bool AddKey);
|
2014-07-06 06:04:09 +00:00
|
|
|
void Orbit(float DistanceX, float DistanceY, const lcVector3& CenterPosition, lcStep Step, bool AddKey);
|
|
|
|
void Roll(float Distance, lcStep Step, bool AddKey);
|
2019-12-25 12:25:32 -08:00
|
|
|
void Center(const lcVector3& NewCenter, lcStep Step, bool AddKey);
|
2018-01-15 11:35:15 -08:00
|
|
|
void MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance);
|
|
|
|
void MoveRelative(const lcVector3& Distance, lcStep Step, bool AddKey);
|
2014-11-08 01:05:17 +00:00
|
|
|
void SetViewpoint(lcViewpoint Viewpoint);
|
2018-08-19 20:27:58 -07:00
|
|
|
void SetViewpoint(const lcVector3& Position);
|
2020-12-12 15:03:06 -08:00
|
|
|
void SetViewpoint(const lcVector3& Position, const lcVector3& Target, const lcVector3& Up);
|
2019-08-15 17:33:37 -07:00
|
|
|
void GetAngles(float& Latitude, float& Longitude, float& Distance) const;
|
2019-08-15 17:41:32 -07:00
|
|
|
void SetAngles(float Latitude, float Longitude, float Distance);
|
2011-09-07 21:06:51 +00:00
|
|
|
|
|
|
|
float m_fovy;
|
|
|
|
float m_zNear;
|
|
|
|
float m_zFar;
|
|
|
|
|
2012-05-28 23:33:22 +00:00
|
|
|
lcMatrix44 mWorldView;
|
|
|
|
lcVector3 mPosition;
|
|
|
|
lcVector3 mTargetPosition;
|
|
|
|
lcVector3 mUpVector;
|
|
|
|
|
2011-09-07 21:06:51 +00:00
|
|
|
protected:
|
2021-01-05 11:26:01 -08:00
|
|
|
lcObjectKeyArray<lcVector3> mPositionKeys;
|
|
|
|
lcObjectKeyArray<lcVector3> mTargetPositionKeys;
|
|
|
|
lcObjectKeyArray<lcVector3> mUpVectorKeys;
|
2014-08-31 00:53:12 +00:00
|
|
|
|
2011-09-07 21:06:51 +00:00
|
|
|
void Initialize();
|
|
|
|
|
2020-12-13 16:27:21 -08:00
|
|
|
QString mName;
|
2017-12-02 12:22:04 -08:00
|
|
|
quint32 mState;
|
2011-09-07 21:06:51 +00:00
|
|
|
};
|