From 98541ed1f21c03e6ebb536e28a5cb7040dfecf96 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 22 Jun 2014 17:39:15 +0000 Subject: [PATCH] Improved moving rotated parts. --- common/camera.cpp | 18 +++++++-------- common/camera.h | 2 +- common/light.cpp | 12 +++++----- common/light.h | 2 +- common/object.h | 2 +- common/piece.cpp | 8 +++---- common/piece.h | 2 +- common/project.cpp | 55 ++++++++++++++++++---------------------------- common/view.cpp | 8 +++++-- 9 files changed, 47 insertions(+), 62 deletions(-) diff --git a/common/camera.cpp b/common/camera.cpp index 055a6281..7e10965c 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -284,31 +284,29 @@ void lcCamera::FileSave(lcFile& file) const ///////////////////////////////////////////////////////////////////////////// // Camera operations -void lcCamera::Move(unsigned short nTime, bool bAddKey, float dx, float dy, float dz) +void lcCamera::Move(unsigned short nTime, bool AddKey, const lcVector3& Distance) { - lcVector3 MoveVec(dx, dy, dz); - if (IsSimple()) - bAddKey = false; + AddKey = false; if (IsSelected(LC_CAMERA_SECTION_POSITION)) { - mPosition += MoveVec; + mPosition += Distance; lcAlign(mOrthoTarget, mPosition, mTargetPosition); - ChangeKey(nTime, bAddKey, mPosition, LC_CK_EYE); + ChangeKey(nTime, AddKey, mPosition, LC_CK_EYE); } if (IsSelected(LC_CAMERA_SECTION_TARGET)) { - mTargetPosition += MoveVec; - ChangeKey(nTime, bAddKey, mTargetPosition, LC_CK_TARGET); + mTargetPosition += Distance; + ChangeKey(nTime, AddKey, mTargetPosition, LC_CK_TARGET); } if (IsSelected(LC_CAMERA_SECTION_UPVECTOR)) { - mUpVector += MoveVec; + mUpVector += Distance; mUpVector.Normalize(); - ChangeKey(nTime, bAddKey, mTargetPosition, LC_CK_UP); + ChangeKey(nTime, AddKey, mTargetPosition, LC_CK_UP); } lcVector3 FrontVector(mTargetPosition - mPosition); diff --git a/common/camera.h b/common/camera.h index 55028cc7..0c3fa4b4 100644 --- a/common/camera.h +++ b/common/camera.h @@ -263,7 +263,7 @@ public: void Orbit(float DistanceX, float DistanceY, const lcVector3& CenterPosition, unsigned short nTime, bool bAddKey); void Roll(float Distance, unsigned short nTime, bool bAddKey); void Center(lcVector3& point, unsigned short nTime, bool bAddKey); - void Move(unsigned short nTime, bool bAddKey, float x, float y, float z); + void Move(unsigned short nTime, bool AddKey, const lcVector3& Distance); void SetViewpoint(LC_VIEWPOINT Viewpoint, unsigned short nTime, bool bAddKey); void SetFocalPoint(const lcVector3& focus, unsigned short nTime, bool bAddKey); diff --git a/common/light.cpp b/common/light.cpp index 001233d2..3411124a 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -214,22 +214,20 @@ void lcLight::BoxTest(lcObjectBoxTest& ObjectBoxTest) const } } -void lcLight::Move(unsigned short nTime, bool bAddKey, float dx, float dy, float dz) +void lcLight::Move(unsigned short nTime, bool AddKey, const lcVector3& Distance) { - lcVector3 MoveVec(dx, dy, dz); - if (IsSelected(LC_LIGHT_SECTION_POSITION)) { - mPosition += MoveVec; + mPosition += Distance; - ChangeKey(nTime, bAddKey, mPosition, LC_LK_POSITION); + ChangeKey(nTime, AddKey, mPosition, LC_LK_POSITION); } if (IsSelected(LC_LIGHT_SECTION_TARGET)) { - mTargetPosition += MoveVec; + mTargetPosition += Distance; - ChangeKey(nTime, bAddKey, mTargetPosition, LC_LK_TARGET); + ChangeKey(nTime, AddKey, mTargetPosition, LC_LK_TARGET); } } diff --git a/common/light.h b/common/light.h index 2a36eb7e..8b5db0b4 100644 --- a/common/light.h +++ b/common/light.h @@ -204,7 +204,7 @@ public: void RenderSphere(); void UpdatePosition(unsigned short nTime); - void Move(unsigned short nTime, bool bAddKey, float dx, float dy, float dz); + void Move(unsigned short nTime, bool AddKey, const lcVector3& Distance); bool Setup(int LightIndex); void CreateName(const lcArray& Lights); bool FileLoad(lcFile& file); diff --git a/common/object.h b/common/object.h index 0d3bbd42..23eb671c 100644 --- a/common/object.h +++ b/common/object.h @@ -87,7 +87,7 @@ public: virtual lcuint32 GetFocusSection() const = 0; virtual lcVector3 GetSectionPosition(lcuint32 Section) const = 0; - virtual void Move(unsigned short nTime, bool bAddKey, float dx, float dy, float dz) = 0; + virtual void Move(unsigned short nTime, bool AddKey, const lcVector3& Distance) = 0; virtual void RayTest(lcObjectRayTest& ObjectRayTest) const = 0; virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const = 0; virtual const char* GetName() const = 0; diff --git a/common/piece.cpp b/common/piece.cpp index 680028f0..2a756ba0 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -402,13 +402,11 @@ void lcPiece::BoxTest(lcObjectBoxTest& ObjectBoxTest) const } } -void lcPiece::Move(unsigned short nTime, bool bAddKey, float dx, float dy, float dz) +void lcPiece::Move(unsigned short nTime, bool AddKey, const lcVector3& Distance) { - mPosition[0] += dx; - mPosition[1] += dy; - mPosition[2] += dz; + mPosition += Distance; - ChangeKey(nTime, bAddKey, mPosition, LC_PK_POSITION); + ChangeKey(nTime, AddKey, mPosition, LC_PK_POSITION); mModelWorld.SetTranslation(mPosition); } diff --git a/common/piece.h b/common/piece.h index 243e939f..7701d255 100644 --- a/common/piece.h +++ b/common/piece.h @@ -128,7 +128,7 @@ public: void FileSave(lcFile& file) const; void UpdatePosition(unsigned short nTime); - void Move(unsigned short nTime, bool bAddKey, float dx, float dy, float dz); + void Move(unsigned short nTime, bool AddKey, const lcVector3& Distance); lcGroup* GetTopGroup(); diff --git a/common/project.cpp b/common/project.cpp index 988d8df2..5f44c895 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -6258,54 +6258,41 @@ bool Project::MoveSelectedObjects(lcVector3& Move, lcVector3& Remainder, bool Sn return false; } - lcVector3 TransformedMove(Move); + lcVector3 TransformedMove = lcMul30(Move, GetRelativeRotation()); - // Transform the translation if we're in relative mode. - if ((m_nSnap & LC_DRAW_GLOBAL_SNAP) == 0) + for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) { - Object* Focus = GetFocusObject(); + lcPiece* Piece = mPieces[PieceIdx]; - if ((Focus != NULL) && Focus->IsPiece()) - TransformedMove = lcMul30(TransformedMove, ((Piece*)Focus)->mModelWorld); + if (Piece->IsSelected()) + { + Piece->Move(m_nCurStep, gMainWindow->GetAddKeys(), TransformedMove); + Piece->UpdatePosition(m_nCurStep); + } } - float x = TransformedMove[0], y = TransformedMove[1], z = TransformedMove[2]; - for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++) { - Camera* pCamera = mCameras[CameraIdx]; + lcCamera* Camera = mCameras[CameraIdx]; - if (pCamera->IsSelected()) + if (Camera->IsSelected()) { - pCamera->Move(m_nCurStep, gMainWindow->GetAddKeys(), x, y, z); - pCamera->UpdatePosition(m_nCurStep); + Camera->Move(m_nCurStep, gMainWindow->GetAddKeys(), TransformedMove); + Camera->UpdatePosition(m_nCurStep); } } for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++) { - Light* pLight = mLights[LightIdx]; + lcLight* Light = mLights[LightIdx]; - if (pLight->IsSelected()) + if (Light->IsSelected()) { - pLight->Move (m_nCurStep, gMainWindow->GetAddKeys(), x, y, z); - pLight->UpdatePosition (m_nCurStep); + Light->Move(m_nCurStep, gMainWindow->GetAddKeys(), TransformedMove); + Light->UpdatePosition(m_nCurStep); } } - for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) - { - Piece* Piece = mPieces[PieceIdx]; - - if (Piece->IsSelected()) - { - Piece->Move(m_nCurStep, gMainWindow->GetAddKeys(), x, y, z); - Piece->UpdatePosition(m_nCurStep); - } - } - - // TODO: move group centers - return true; } @@ -6513,7 +6500,7 @@ void Project::TransformSelectedObjects(LC_TRANSFORM_TYPE Type, const lcVector3& if (pCamera->IsSelected()) { - pCamera->Move(m_nCurStep, gMainWindow->GetAddKeys(), Offset.x, Offset.y, Offset.z); + pCamera->Move(m_nCurStep, gMainWindow->GetAddKeys(), Offset); pCamera->UpdatePosition(m_nCurStep); } } @@ -6524,7 +6511,7 @@ void Project::TransformSelectedObjects(LC_TRANSFORM_TYPE Type, const lcVector3& if (pLight->IsSelected()) { - pLight->Move(m_nCurStep, gMainWindow->GetAddKeys(), Offset.x, Offset.y, Offset.z); + pLight->Move(m_nCurStep, gMainWindow->GetAddKeys(), Offset); pLight->UpdatePosition (m_nCurStep); } } @@ -6535,7 +6522,7 @@ void Project::TransformSelectedObjects(LC_TRANSFORM_TYPE Type, const lcVector3& if (Piece->IsSelected()) { - Piece->Move(m_nCurStep, gMainWindow->GetAddKeys(), Offset.x, Offset.y, Offset.z); + Piece->Move(m_nCurStep, gMainWindow->GetAddKeys(), Offset); Piece->UpdatePosition(m_nCurStep); } } @@ -6962,7 +6949,7 @@ void Project::UpdateSpotLightTool(const lcVector3& Target) { lcLight* Light = mLights[mLights.GetSize() - 1]; - Light->Move(1, false, Target[0], Target[1], Target[2]); + Light->Move(1, false, Target); Light->UpdatePosition(1); gMainWindow->UpdateFocusObject(Light); @@ -6982,7 +6969,7 @@ void Project::UpdateCameraTool(const lcVector3& Target) { lcCamera* Camera = mCameras[mCameras.GetSize() - 1]; - Camera->Move(1, false, Target[0], Target[1], Target[2]); + Camera->Move(1, false, Target); Camera->UpdatePosition(1); gMainWindow->UpdateFocusObject(Camera); diff --git a/common/view.cpp b/common/view.cpp index 6cc8764f..f8d12b6e 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -1744,7 +1744,8 @@ void View::OnMouseMove() else Direction = lcVector3(0.0, 0.0f, 1.0f); - Direction = lcMul30(Direction, mProject->GetRelativeRotation()); + lcMatrix44 RelativeRotation = mProject->GetRelativeRotation(); + Direction = lcMul30(Direction, RelativeRotation); lcVector3 Intersection; lcClosestPointsBetweenLines(Center, Center + Direction, CurrentStart, CurrentEnd, &Intersection, NULL); @@ -1753,6 +1754,7 @@ void View::OnMouseMove() lcClosestPointsBetweenLines(Center, Center + Direction, MouseDownStart, MouseDownEnd, &MoveStart, NULL); lcVector3 Distance = Intersection - MoveStart; + Distance = lcMul30(Distance, lcMatrix44AffineInverse(RelativeRotation)); mProject->UpdateMoveTool(Distance); } else if (mTrackTool == LC_TRACKTOOL_MOVE_XY || mTrackTool == LC_TRACKTOOL_MOVE_XZ || mTrackTool == LC_TRACKTOOL_MOVE_YZ) @@ -1766,7 +1768,8 @@ void View::OnMouseMove() else PlaneNormal = lcVector3(1.0f, 0.0f, 0.0f); - PlaneNormal = lcMul30(PlaneNormal, mProject->GetRelativeRotation()); + lcMatrix44 RelativeRotation = mProject->GetRelativeRotation(); + PlaneNormal = lcMul30(PlaneNormal, RelativeRotation); lcVector4 Plane(PlaneNormal, -lcDot(PlaneNormal, Center)); lcVector3 Intersection; @@ -1777,6 +1780,7 @@ void View::OnMouseMove() if (lcLinePlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane)) { lcVector3 Distance = Intersection - MoveStart; + Distance = lcMul30(Distance, lcMatrix44AffineInverse(RelativeRotation)); mProject->UpdateMoveTool(Distance); } }