mirror of
https://github.com/leozide/leocad
synced 2025-01-29 20:34:50 +01:00
Moved snap functions to project.
This commit is contained in:
parent
2ca5665235
commit
56b09b03b0
4 changed files with 103 additions and 108 deletions
|
@ -636,8 +636,102 @@ void lcModel::RemoveEmptyGroups()
|
|||
while (Removed);
|
||||
}
|
||||
|
||||
#include "project.h"
|
||||
#include "lc_application.h"
|
||||
lcVector3 lcModel::LockVector(const lcVector3& Vector) const
|
||||
{
|
||||
lcVector3 NewVector(Vector);
|
||||
|
||||
if (gMainWindow->GetLockX())
|
||||
NewVector[0] = 0;
|
||||
|
||||
if (gMainWindow->GetLockY())
|
||||
NewVector[1] = 0;
|
||||
|
||||
if (gMainWindow->GetLockZ())
|
||||
NewVector[2] = 0;
|
||||
|
||||
return NewVector;
|
||||
}
|
||||
|
||||
lcVector3 lcModel::SnapPosition(const lcVector3& Distance) const
|
||||
{
|
||||
lcVector3 NewDistance(Distance);
|
||||
|
||||
if (gMainWindow->GetMoveXYSnap())
|
||||
{
|
||||
float SnapXY = (float)gMainWindow->GetMoveXYSnap();
|
||||
int i = (int)(NewDistance[0] / SnapXY);
|
||||
float Leftover = NewDistance[0] - (SnapXY * i);
|
||||
|
||||
if (Leftover > SnapXY / 2)
|
||||
{
|
||||
Leftover -= SnapXY;
|
||||
i++;
|
||||
}
|
||||
else if (Leftover < -SnapXY / 2)
|
||||
{
|
||||
Leftover += SnapXY;
|
||||
i--;
|
||||
}
|
||||
|
||||
NewDistance[0] = SnapXY * i;
|
||||
|
||||
i = (int)(NewDistance[1] / SnapXY);
|
||||
Leftover = NewDistance[1] - (SnapXY * i);
|
||||
|
||||
if (Leftover > SnapXY / 2)
|
||||
{
|
||||
Leftover -= SnapXY;
|
||||
i++;
|
||||
}
|
||||
else if (Leftover < -SnapXY / 2)
|
||||
{
|
||||
Leftover += SnapXY;
|
||||
i--;
|
||||
}
|
||||
|
||||
NewDistance[1] = SnapXY * i;
|
||||
}
|
||||
|
||||
if (gMainWindow->GetMoveZSnap())
|
||||
{
|
||||
float SnapZ = (float)gMainWindow->GetMoveZSnap();
|
||||
int i = (int)(NewDistance[2] / SnapZ);
|
||||
float Leftover = NewDistance[2] - (SnapZ * i);
|
||||
|
||||
if (Leftover > SnapZ / 2)
|
||||
{
|
||||
Leftover -= SnapZ;
|
||||
i++;
|
||||
}
|
||||
else if (Leftover < -SnapZ / 2)
|
||||
{
|
||||
Leftover += SnapZ;
|
||||
i--;
|
||||
}
|
||||
|
||||
NewDistance[2] = SnapZ * i;
|
||||
}
|
||||
|
||||
return NewDistance;
|
||||
}
|
||||
|
||||
lcVector3 lcModel::SnapRotation(const lcVector3& Angles) const
|
||||
{
|
||||
int AngleSnap = gMainWindow->GetAngleSnap();
|
||||
lcVector3 NewAngles(Angles);
|
||||
|
||||
if (AngleSnap)
|
||||
{
|
||||
int Snap[3];
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
Snap[i] = (int)(Angles[i] / (float)AngleSnap);
|
||||
|
||||
NewAngles = lcVector3((float)(AngleSnap * Snap[0]), (float)(AngleSnap * Snap[1]), (float)(AngleSnap * Snap[2]));
|
||||
}
|
||||
|
||||
return NewAngles;
|
||||
}
|
||||
|
||||
lcMatrix44 lcModel::GetRelativeRotation() const
|
||||
{
|
||||
|
@ -742,7 +836,6 @@ bool lcModel::RotateSelectedPieces(const lcVector3& Angles)
|
|||
else
|
||||
Center = lcVector3((Bounds[0] + Bounds[3]) / 2.0f, (Bounds[1] + Bounds[4]) / 2.0f, (Bounds[2] + Bounds[5]) / 2.0f);
|
||||
|
||||
// Create the rotation matrix.
|
||||
lcVector4 RotationQuaternion(0, 0, 0, 1);
|
||||
lcVector4 WorldToFocusQuaternion, FocusToWorldQuaternion;
|
||||
|
||||
|
@ -1260,7 +1353,7 @@ void lcModel::UpdateCameraTool(const lcVector3& Target)
|
|||
|
||||
void lcModel::UpdateMoveTool(const lcVector3& Distance)
|
||||
{
|
||||
lcVector3 PieceDistance = lcGetActiveProject()->LockVector(lcGetActiveProject()->SnapVector(Distance) - lcGetActiveProject()->SnapVector(mMouseToolDistance));
|
||||
lcVector3 PieceDistance = LockVector(SnapPosition(Distance) - SnapPosition(mMouseToolDistance));
|
||||
lcVector3 ObjectDistance = Distance - mMouseToolDistance;
|
||||
|
||||
MoveSelectedObjects(PieceDistance, ObjectDistance);
|
||||
|
@ -1272,7 +1365,7 @@ void lcModel::UpdateMoveTool(const lcVector3& Distance)
|
|||
|
||||
void lcModel::UpdateRotateTool(const lcVector3& Angles)
|
||||
{
|
||||
lcVector3 Delta = lcGetActiveProject()->LockVector(lcGetActiveProject()->SnapRotation(Angles) - lcGetActiveProject()->SnapRotation(mMouseToolDistance));
|
||||
lcVector3 Delta = LockVector(SnapRotation(Angles) - SnapRotation(mMouseToolDistance));
|
||||
RotateSelectedPieces(Delta);
|
||||
mMouseToolDistance = Angles;
|
||||
|
||||
|
|
|
@ -156,6 +156,9 @@ public:
|
|||
|
||||
void FindPiece(bool FindFirst, bool SearchForward);
|
||||
|
||||
lcVector3 LockVector(const lcVector3& Vector) const;
|
||||
lcVector3 SnapPosition(const lcVector3& Delta) const;
|
||||
lcVector3 SnapRotation(const lcVector3& Delta) const;
|
||||
lcMatrix44 GetRelativeRotation() const;
|
||||
|
||||
const lcVector3& GetMouseToolDistance() const
|
||||
|
|
|
@ -4602,7 +4602,7 @@ bool Project::AnyObjectsSelected(bool PiecesOnly) const
|
|||
void Project::GetPieceInsertPosition(lcPiece* OffsetPiece, lcVector3& Position, lcVector4& Rotation)
|
||||
{
|
||||
lcVector3 Dist(0, 0, OffsetPiece->mPieceInfo->m_fDimensions[2] - m_pCurPiece->m_fDimensions[5]);
|
||||
Dist = SnapVector(Dist);
|
||||
Dist = SnapPosition(Dist);
|
||||
|
||||
Position = lcMul31(Dist, OffsetPiece->mModelWorld);
|
||||
Rotation = OffsetPiece->mRotation;
|
||||
|
@ -4627,7 +4627,7 @@ void Project::GetPieceInsertPosition(View* view, lcVector3& Position, lcVector4&
|
|||
lcVector3 Intersection;
|
||||
if (lcLinePlaneIntersection(&Intersection, ClickPoints[0], ClickPoints[1], lcVector4(0, 0, 1, m_pCurPiece->m_fDimensions[5])))
|
||||
{
|
||||
Intersection = SnapVector(Intersection);
|
||||
Intersection = SnapPosition(Intersection);
|
||||
Position = Intersection;
|
||||
Rotation = lcVector4(0, 0, 1, 0);
|
||||
return;
|
||||
|
@ -4638,103 +4638,6 @@ void Project::GetPieceInsertPosition(View* view, lcVector3& Position, lcVector4&
|
|||
Rotation = lcVector4(0, 0, 1, 0);
|
||||
}
|
||||
|
||||
lcVector3 Project::LockVector(const lcVector3& Vector) const
|
||||
{
|
||||
lcVector3 NewVector(Vector);
|
||||
|
||||
if (gMainWindow->GetLockX())
|
||||
NewVector[0] = 0;
|
||||
|
||||
if (gMainWindow->GetLockY())
|
||||
NewVector[1] = 0;
|
||||
|
||||
if (gMainWindow->GetLockZ())
|
||||
NewVector[2] = 0;
|
||||
|
||||
return NewVector;
|
||||
}
|
||||
|
||||
lcVector3 Project::SnapVector(const lcVector3& Distance) const
|
||||
{
|
||||
lcVector3 NewDistance(Distance);
|
||||
|
||||
if (gMainWindow->GetMoveXYSnap())
|
||||
{
|
||||
float SnapXY = (float)gMainWindow->GetMoveXYSnap();
|
||||
int i = (int)(NewDistance[0] / SnapXY);
|
||||
float Leftover = NewDistance[0] - (SnapXY * i);
|
||||
|
||||
if (Leftover > SnapXY / 2)
|
||||
{
|
||||
Leftover -= SnapXY;
|
||||
i++;
|
||||
}
|
||||
else if (Leftover < -SnapXY / 2)
|
||||
{
|
||||
Leftover += SnapXY;
|
||||
i--;
|
||||
}
|
||||
|
||||
NewDistance[0] = SnapXY * i;
|
||||
|
||||
i = (int)(NewDistance[1] / SnapXY);
|
||||
Leftover = NewDistance[1] - (SnapXY * i);
|
||||
|
||||
if (Leftover > SnapXY / 2)
|
||||
{
|
||||
Leftover -= SnapXY;
|
||||
i++;
|
||||
}
|
||||
else if (Leftover < -SnapXY / 2)
|
||||
{
|
||||
Leftover += SnapXY;
|
||||
i--;
|
||||
}
|
||||
|
||||
NewDistance[1] = SnapXY * i;
|
||||
}
|
||||
|
||||
if (gMainWindow->GetMoveZSnap())
|
||||
{
|
||||
float SnapZ = (float)gMainWindow->GetMoveZSnap();
|
||||
int i = (int)(NewDistance[2] / SnapZ);
|
||||
float Leftover = NewDistance[2] - (SnapZ * i);
|
||||
|
||||
if (Leftover > SnapZ / 2)
|
||||
{
|
||||
Leftover -= SnapZ;
|
||||
i++;
|
||||
}
|
||||
else if (Leftover < -SnapZ / 2)
|
||||
{
|
||||
Leftover += SnapZ;
|
||||
i--;
|
||||
}
|
||||
|
||||
NewDistance[2] = SnapZ * i;
|
||||
}
|
||||
|
||||
return NewDistance;
|
||||
}
|
||||
|
||||
lcVector3 Project::SnapRotation(const lcVector3& Angles) const
|
||||
{
|
||||
int AngleSnap = gMainWindow->GetAngleSnap();
|
||||
lcVector3 NewAngles(Angles);
|
||||
|
||||
if (AngleSnap)
|
||||
{
|
||||
int Snap[3];
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
Snap[i] = (int)(Angles[i] / (float)AngleSnap);
|
||||
|
||||
NewAngles = lcVector3((float)(AngleSnap * Snap[0]), (float)(AngleSnap * Snap[1]), (float)(AngleSnap * Snap[2]));
|
||||
}
|
||||
|
||||
return NewAngles;
|
||||
}
|
||||
|
||||
void Project::TransformSelectedObjects(lcTransformType Type, const lcVector3& Transform)
|
||||
{
|
||||
switch (Type)
|
||||
|
|
|
@ -117,10 +117,6 @@ public:
|
|||
|
||||
void GetPieceInsertPosition(View* view, lcVector3& Position, lcVector4& Orientation);
|
||||
|
||||
lcVector3 LockVector(const lcVector3& Vector) const;
|
||||
lcVector3 SnapVector(const lcVector3& Delta) const;
|
||||
lcVector3 SnapRotation(const lcVector3& Delta) const;
|
||||
|
||||
void HandleCommand(LC_COMMANDS id);
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Add table
Reference in a new issue