Added camera action.
This commit is contained in:
+4
-4
@@ -30,11 +30,11 @@ lcCamera::lcCamera(bool Simple)
|
||||
}
|
||||
}
|
||||
|
||||
lcCamera::lcCamera(float ex, float ey, float ez, float tx, float ty, float tz)
|
||||
lcCamera::lcCamera(const lcVector3& Position, const lcVector3& TargetPosition)
|
||||
: lcObject(lcObjectType::Camera)
|
||||
{
|
||||
// Fix the up vector
|
||||
lcVector3 UpVector(0, 0, 1), FrontVector(ex - tx, ey - ty, ez - tz), SideVector;
|
||||
lcVector3 UpVector(0, 0, 1), FrontVector(Position - TargetPosition), SideVector;
|
||||
FrontVector.Normalize();
|
||||
if (FrontVector == UpVector)
|
||||
SideVector = lcVector3(1, 0, 0);
|
||||
@@ -45,8 +45,8 @@ lcCamera::lcCamera(float ex, float ey, float ez, float tx, float ty, float tz)
|
||||
|
||||
Initialize();
|
||||
|
||||
mPosition.SetValue(lcVector3(ex, ey, ez));
|
||||
mTargetPosition.SetValue(lcVector3(tx, ty, tz));
|
||||
mPosition.SetValue(Position);
|
||||
mTargetPosition.SetValue(TargetPosition);
|
||||
mUpVector.SetValue(UpVector);
|
||||
|
||||
lcCamera::UpdatePosition(1);
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ class lcCamera : public lcObject
|
||||
{
|
||||
public:
|
||||
lcCamera(bool Simple);
|
||||
lcCamera(float ex, float ey, float ez, float tx, float ty, float tz);
|
||||
lcCamera(const lcVector3& Position, const lcVector3& TargetPosition);
|
||||
virtual ~lcCamera();
|
||||
|
||||
lcCamera(const lcCamera&) = delete;
|
||||
|
||||
+53
-66
@@ -9,8 +9,6 @@
|
||||
#include "lc_profile.h"
|
||||
#include "lc_library.h"
|
||||
#include "lc_scene.h"
|
||||
#include "lc_texture.h"
|
||||
#include "lc_synth.h"
|
||||
#include "lc_traintrack.h"
|
||||
#include "lc_file.h"
|
||||
#include "pieceinf.h"
|
||||
@@ -25,7 +23,6 @@
|
||||
#include "lc_qutils.h"
|
||||
#include "lc_lxf.h"
|
||||
#include "lc_previewwidget.h"
|
||||
#include "lc_findreplacewidget.h"
|
||||
#include <locale.h>
|
||||
|
||||
void lcModelProperties::LoadDefaults()
|
||||
@@ -1734,12 +1731,7 @@ void lcModel::BeginMouseToolAction(lcTool Tool, lcView* View)
|
||||
case lcTool::SpotLight:
|
||||
case lcTool::DirectionalLight:
|
||||
case lcTool::AreaLight:
|
||||
break;
|
||||
|
||||
// case lcTool::Camera:
|
||||
// SaveCheckpoint(tr("New Camera"));
|
||||
// break;
|
||||
|
||||
case lcTool::Camera:
|
||||
case lcTool::Select:
|
||||
break;
|
||||
|
||||
@@ -1787,12 +1779,7 @@ void lcModel::EndMouseToolAction(lcTool Tool, lcView* View, const QString& Descr
|
||||
case lcTool::SpotLight:
|
||||
case lcTool::DirectionalLight:
|
||||
case lcTool::AreaLight:
|
||||
break;
|
||||
|
||||
// case lcTool::Camera:
|
||||
// SaveCheckpoint(tr("New Camera"));
|
||||
// break;
|
||||
|
||||
case lcTool::Camera:
|
||||
case lcTool::Select:
|
||||
break;
|
||||
|
||||
@@ -1838,12 +1825,7 @@ void lcModel::RunMouseToolAction(const lcModelActionMouseTool* ModelActionMouseT
|
||||
case lcTool::SpotLight:
|
||||
case lcTool::DirectionalLight:
|
||||
case lcTool::AreaLight:
|
||||
break;
|
||||
|
||||
// case lcTool::Camera:
|
||||
// SaveCheckpoint(tr("New Camera"));
|
||||
// break;
|
||||
|
||||
case lcTool::Camera:
|
||||
case lcTool::Select:
|
||||
break;
|
||||
|
||||
@@ -1963,6 +1945,38 @@ void lcModel::RunAddPiecesAction(const lcModelActionAddPieces* ModelActionAddPie
|
||||
}
|
||||
}
|
||||
|
||||
void lcModel::RecordAddCameraAction(const lcVector3& Position, const lcVector3& TargetPosition)
|
||||
{
|
||||
std::unique_ptr<lcModelActionAddCamera> ModelActionAddCamera = std::make_unique<lcModelActionAddCamera>(Position, TargetPosition);
|
||||
|
||||
RunAddCameraAction(ModelActionAddCamera.get(), true);
|
||||
|
||||
mActionSequence.emplace_back(std::move(ModelActionAddCamera));
|
||||
}
|
||||
|
||||
void lcModel::RunAddCameraAction(const lcModelActionAddCamera* ModelActionAddCamera, bool Apply)
|
||||
{
|
||||
if (!ModelActionAddCamera)
|
||||
return;
|
||||
|
||||
if (Apply)
|
||||
{
|
||||
lcCamera* Camera = new lcCamera(ModelActionAddCamera->GetPosition(), ModelActionAddCamera->GetTargetPosition());
|
||||
Camera->CreateName(mCameras);
|
||||
mCameras.emplace_back(Camera);
|
||||
|
||||
ClearSelectionAndSetFocus(Camera, LC_CAMERA_SECTION_POSITION, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mCameras.empty())
|
||||
mCameras.pop_back();
|
||||
|
||||
gMainWindow->UpdateSelectedObjects(true);
|
||||
gMainWindow->UpdateInUseCategory();
|
||||
}
|
||||
}
|
||||
|
||||
void lcModel::RecordAddLightAction(const lcVector3& Position, lcLightType LightType)
|
||||
{
|
||||
std::unique_ptr<lcModelActionAddLight> ModelActionAddLight = std::make_unique<lcModelActionAddLight>(Position, LightType);
|
||||
@@ -2297,6 +2311,8 @@ void lcModel::PerformActionSequence(const std::vector<std::unique_ptr<lcModelAct
|
||||
RunMouseToolAction(ModelActionMouseTool, Apply);
|
||||
else if (const lcModelActionAddPieces* ModelActionAddPieces = dynamic_cast<const lcModelActionAddPieces*>(ModelAction))
|
||||
RunAddPiecesAction(ModelActionAddPieces, Apply);
|
||||
else if (const lcModelActionAddCamera* ModelActionAddCamera = dynamic_cast<const lcModelActionAddCamera*>(ModelAction))
|
||||
RunAddCameraAction(ModelActionAddCamera, Apply);
|
||||
else if (const lcModelActionAddLight* ModelActionAddLight = dynamic_cast<const lcModelActionAddLight*>(ModelAction))
|
||||
RunAddLightAction(ModelActionAddLight, Apply);
|
||||
else if (const lcModelActionGroupPieces* ModelActionGroupPieces = dynamic_cast<const lcModelActionGroupPieces*>(ModelAction))
|
||||
@@ -5118,16 +5134,7 @@ void lcModel::BeginMouseTool(lcTool Tool, lcView* View)
|
||||
case lcTool::SpotLight:
|
||||
case lcTool::DirectionalLight:
|
||||
case lcTool::AreaLight:
|
||||
break;
|
||||
|
||||
// case lcTool::Camera:
|
||||
// {
|
||||
// lcVector3 Position = GetCameraLightInsertPosition();
|
||||
// lcVector3 Target = Position + lcVector3(0.1f, 0.1f, 0.1f);
|
||||
// ActiveModel->BeginCameraTool(Position, Target);
|
||||
// }
|
||||
// break;
|
||||
|
||||
case lcTool::Camera:
|
||||
case lcTool::Select:
|
||||
break;
|
||||
|
||||
@@ -5181,12 +5188,7 @@ void lcModel::EndMouseTool(lcTool Tool, lcView* View, bool Accept)
|
||||
case lcTool::SpotLight:
|
||||
case lcTool::DirectionalLight:
|
||||
case lcTool::AreaLight:
|
||||
break;
|
||||
|
||||
// case lcTool::Camera:
|
||||
// SaveCheckpoint(tr("New Camera"));
|
||||
// break;
|
||||
|
||||
case lcTool::Camera:
|
||||
case lcTool::Select:
|
||||
break;
|
||||
|
||||
@@ -5244,6 +5246,20 @@ void lcModel::InsertPieceToolClicked(const std::vector<lcInsertPieceInfo>& Piece
|
||||
EndActionSequence(tr("Add Piece"));
|
||||
}
|
||||
|
||||
void lcModel::InsertCameraToolClicked(const lcVector3& Position)
|
||||
{
|
||||
lcVector3 TargetPosition;
|
||||
|
||||
GetPieceFocusOrSelectionCenter(TargetPosition);
|
||||
|
||||
BeginActionSequence();
|
||||
|
||||
RecordSelectionAction(lcModelActionSelectionMode::Save);
|
||||
RecordAddCameraAction(Position, TargetPosition);
|
||||
|
||||
EndActionSequence(tr("Add Camera"));
|
||||
}
|
||||
|
||||
void lcModel::InsertLightToolClicked(const lcVector3& Position, lcLightType LightType)
|
||||
{
|
||||
QString ActionName;
|
||||
@@ -5278,35 +5294,6 @@ void lcModel::InsertLightToolClicked(const lcVector3& Position, lcLightType Ligh
|
||||
EndActionSequence(ActionName);
|
||||
}
|
||||
|
||||
void lcModel::BeginCameraTool(const lcVector3& Position, const lcVector3& Target)
|
||||
{
|
||||
lcCamera* Camera = new lcCamera(Position[0], Position[1], Position[2], Target[0], Target[1], Target[2]);
|
||||
Camera->CreateName(mCameras);
|
||||
mCameras.emplace_back(Camera);
|
||||
|
||||
mMouseToolDistance = Position;
|
||||
mMouseToolFirstMove = false;
|
||||
|
||||
ClearSelectionAndSetFocus(Camera, LC_CAMERA_SECTION_TARGET, false);
|
||||
}
|
||||
|
||||
void lcModel::UpdateCameraTool(const lcVector3& Position)
|
||||
{
|
||||
if (mCameras.empty())
|
||||
return;
|
||||
|
||||
std::unique_ptr<lcCamera>& Camera = mCameras.back();
|
||||
|
||||
Camera->MoveSelected(1, false, Position - mMouseToolDistance);
|
||||
Camera->UpdatePosition(1);
|
||||
|
||||
mMouseToolDistance = Position;
|
||||
mMouseToolFirstMove = false;
|
||||
|
||||
gMainWindow->UpdateSelectedObjects(false);
|
||||
UpdateAllViews();
|
||||
}
|
||||
|
||||
void lcModel::UpdateMoveTool(const lcVector3& Distance, bool AllowRelative, bool AlternateButtonDrag)
|
||||
{
|
||||
const lcVector3 PieceDistance = SnapPosition(Distance) - SnapPosition(mMouseToolDistance);
|
||||
|
||||
+4
-2
@@ -8,6 +8,7 @@ class lcModelAction;
|
||||
class lcModelActionSelection;
|
||||
class lcModelActionMouseTool;
|
||||
class lcModelActionAddPieces;
|
||||
class lcModelActionAddCamera;
|
||||
class lcModelActionAddLight;
|
||||
class lcModelActionGroupPieces;
|
||||
class lcModelActionDuplicatePieces;
|
||||
@@ -357,9 +358,8 @@ public:
|
||||
void BeginMouseTool(lcTool Tool, lcView* View);
|
||||
void EndMouseTool(lcTool Tool, lcView* View, bool Accept);
|
||||
void InsertPieceToolClicked(const std::vector<lcInsertPieceInfo>& PieceInfoTransforms);
|
||||
void InsertCameraToolClicked(const lcVector3& Position);
|
||||
void InsertLightToolClicked(const lcVector3& Position, lcLightType LightType);
|
||||
void BeginCameraTool(const lcVector3& Position, const lcVector3& Target);
|
||||
void UpdateCameraTool(const lcVector3& Position);
|
||||
void UpdateMoveTool(const lcVector3& Distance, bool AllowRelative, bool AlternateButtonDrag);
|
||||
void UpdateFreeMoveTool(lcPiece* MousePiece, const lcMatrix44& StartTransform, const lcMatrix44& NewTransform, bool IsConnection, bool AlternateButtonDrag);
|
||||
void UpdateRotateTool(const lcVector3& Angles, bool AlternateButtonDrag);
|
||||
@@ -415,6 +415,8 @@ protected:
|
||||
void RunMouseToolAction(const lcModelActionMouseTool* ModelActionMouseTool, bool Apply);
|
||||
void RecordAddPiecesAction(const std::vector<lcInsertPieceInfo>& PieceInfoTransforms, lcModelActionAddPieceSelectionMode SelectionMode);
|
||||
void RunAddPiecesAction(const lcModelActionAddPieces* ModelActionAddPieces, bool Apply);
|
||||
void RecordAddCameraAction(const lcVector3& Position, const lcVector3& TargetPosition);
|
||||
void RunAddCameraAction(const lcModelActionAddCamera* ModelActionAddCamera, bool Apply);
|
||||
void RecordAddLightAction(const lcVector3& Position, lcLightType LightType);
|
||||
void RunAddLightAction(const lcModelActionAddLight* ModelActionAddLight, bool Apply);
|
||||
void RecordGroupPiecesAction(lcModelActionGroupPiecesMode Mode, const QString& GroupName);
|
||||
|
||||
@@ -15,7 +15,7 @@ void lcModelAction::SaveUndoBuffer(QByteArray& Buffer, const lcModel* Model, boo
|
||||
const std::vector<std::unique_ptr<lcCamera>>& Cameras = Model->GetCameras();
|
||||
const std::vector<std::unique_ptr<lcLight>>& Lights = Model->GetLights();
|
||||
|
||||
size_t PieceCount = Pieces.size(), CameraCount = Cameras.size(), LightCount = Lights.size();
|
||||
uint64_t PieceCount = Pieces.size(), CameraCount = Cameras.size(), LightCount = Lights.size();
|
||||
|
||||
Stream << PieceCount;
|
||||
Stream << CameraCount;
|
||||
@@ -42,7 +42,7 @@ void lcModelAction::LoadUndoBuffer(const QByteArray& Buffer, lcModel* Model, boo
|
||||
const std::vector<std::unique_ptr<lcCamera>>& Cameras = Model->GetCameras();
|
||||
const std::vector<std::unique_ptr<lcLight>>& Lights = Model->GetLights();
|
||||
|
||||
size_t PieceCount, CameraCount, LightCount;
|
||||
uint64_t PieceCount, CameraCount, LightCount;
|
||||
|
||||
Stream >> PieceCount;
|
||||
Stream >> CameraCount;
|
||||
@@ -239,6 +239,11 @@ void lcModelActionAddPieces::SetPieceData(const std::vector<lcInsertPieceInfo>&
|
||||
}
|
||||
}
|
||||
|
||||
lcModelActionAddCamera::lcModelActionAddCamera(const lcVector3& Position, const lcVector3& TargetPosition)
|
||||
: mPosition(Position), mTargetPosition(TargetPosition)
|
||||
{
|
||||
}
|
||||
|
||||
lcModelActionAddLight::lcModelActionAddLight(const lcVector3& Position, lcLightType LightType)
|
||||
: mPosition(Position), mLightType(LightType)
|
||||
{
|
||||
|
||||
@@ -126,6 +126,27 @@ protected:
|
||||
lcModelActionAddPieceSelectionMode mSelectionMode;
|
||||
};
|
||||
|
||||
class lcModelActionAddCamera : public lcModelAction
|
||||
{
|
||||
public:
|
||||
lcModelActionAddCamera(const lcVector3& Position, const lcVector3& TargetPosition);
|
||||
virtual ~lcModelActionAddCamera() = default;
|
||||
|
||||
const lcVector3& GetPosition() const
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
const lcVector3& GetTargetPosition() const
|
||||
{
|
||||
return mTargetPosition;
|
||||
}
|
||||
|
||||
protected:
|
||||
lcVector3 mPosition;
|
||||
lcVector3 mTargetPosition;
|
||||
};
|
||||
|
||||
class lcModelActionAddLight : public lcModelAction
|
||||
{
|
||||
public:
|
||||
|
||||
+9
-16
@@ -2355,16 +2355,7 @@ void lcView::StartTracking(lcTrackButton TrackButton)
|
||||
case lcTool::SpotLight:
|
||||
case lcTool::DirectionalLight:
|
||||
case lcTool::AreaLight:
|
||||
break;
|
||||
|
||||
case lcTool::Camera:
|
||||
{
|
||||
lcVector3 Position = GetCameraLightInsertPosition();
|
||||
lcVector3 Target = Position + lcVector3(0.1f, 0.1f, 0.1f);
|
||||
ActiveModel->BeginCameraTool(Position, Target);
|
||||
}
|
||||
break;
|
||||
|
||||
case lcTool::Select:
|
||||
break;
|
||||
|
||||
@@ -2411,13 +2402,10 @@ void lcView::StopTracking(bool Accept)
|
||||
{
|
||||
case lcTool::Insert:
|
||||
case lcTool::PointLight:
|
||||
break;
|
||||
|
||||
case lcTool::SpotLight:
|
||||
case lcTool::DirectionalLight:
|
||||
case lcTool::AreaLight:
|
||||
case lcTool::Camera:
|
||||
ActiveModel->EndMouseTool(Tool, this, Accept);
|
||||
break;
|
||||
|
||||
case lcTool::Select:
|
||||
@@ -2562,7 +2550,15 @@ void lcView::OnButtonDown(lcTrackButton TrackButton)
|
||||
break;
|
||||
|
||||
case lcTrackTool::Camera:
|
||||
StartTracking(TrackButton);
|
||||
{
|
||||
ActiveModel->InsertCameraToolClicked(GetCameraLightInsertPosition());
|
||||
|
||||
if ((mMouseModifiers & Qt::ControlModifier) == 0)
|
||||
gMainWindow->SetTool(lcTool::Select);
|
||||
|
||||
mToolClicked = true;
|
||||
UpdateTrackTool();
|
||||
}
|
||||
break;
|
||||
|
||||
case lcTrackTool::Select:
|
||||
@@ -2854,10 +2850,7 @@ void lcView::OnMouseMove()
|
||||
case lcTrackTool::SpotLight:
|
||||
case lcTrackTool::DirectionalLight:
|
||||
case lcTrackTool::AreaLight:
|
||||
break;
|
||||
|
||||
case lcTrackTool::Camera:
|
||||
ActiveModel->UpdateCameraTool(GetCameraLightInsertPosition());
|
||||
break;
|
||||
|
||||
case lcTrackTool::Select:
|
||||
|
||||
Reference in New Issue
Block a user