Improved moving rotated parts.

This commit is contained in:
leo 2014-06-22 17:39:15 +00:00
parent a28ae91a52
commit 98541ed1f2
9 changed files with 47 additions and 62 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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<Light*>& Lights);
bool FileLoad(lcFile& file);

View file

@ -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;

View file

@ -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);
}

View file

@ -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();

View file

@ -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);

View file

@ -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);
}
}