On 03/12/2014 at 02:51, xxxxxxxx wrote:
Thanks Sebastian,
the example is great I stuck on the distance calculation.
I try to calc a offset from the activeObject to subpoints and calculate for each subpoints
second question -
i like to rotate the activeObject - snapping to fit the rotation of the target point - but when move it away to rotate on origin rotation
Thanks
Bool MagnetsData::Snap(const Vector& p, const SnapStruct& ss, SnapPoint& result)
{
const BaseObject* const activeObject = ss.doc->GetActiveObject();
...
Vector screenPos = ss.bd->WS(p);
screenPos.z = 0.0f;
Float64 minDistance = LIMIT<Float64>::Max();
_targetObject = nullptr;
for(Int32 si = 0; si < SubSourceObjectCount; ++si)
{
//calculate offset to subobjects
const Matrix sourcesubobjectOffset = subobejct->GetMg() - activeObject->GetMg();
Vector subscreenPos = screenPos - sourcemagnetOffset.off;
for(Int32 i = 0; i < targetsObjectCount; ++i)
{
...
const Vector objectPosition = _targetObject->GetMg().off;
Vector objectScreenSpacePosition = ss.bd->WS(objectPosition);
objectScreenSpacePosition.z = 0;
const Vector difference = subscreenPos - objectScreenSpacePosition;
const Float64 screenSpaceDistance = difference.GetSquaredLength();
...
}
}
}