Any examples on DetectSnapping Lib ?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 17/01/2010 at 03:40, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   9.6-11.5 
Platform:   Windows  ; Mac  ;  
Language(s) :     C++  ;

---------
Hi,

i want to add some snapping functionality to my Tool plugin, so I'm currently asking myself if i have to compute everything myself, or if I can use the DetectSnapping lib.

So I included the standart snapping tab in my toolPlugin.res, and alloc'd a DetectSnapping object.
Also I added the 'PLUGINFLAG_TOOL_SNAPSETTINGS' flag when registering the ToolPlugin.

Then I try to detect a snap in my MouseInput function, like this:

  
BaseObject* obj = doc->GetActiveObject();   
.   
.   
AutoAlloc<DetectSnapping> detect;   
detect->Init(doc,bd,obj,NULL,0,TRUE,TRUE,TRUE);   
Vector delta;   
.   
.   
if(button==KEY_MLEFT){   
               if(detect->IsEnabled(doc)){   
                    GePrint("snap is on");   
                    detect->SnapTo(res.hitpos,δ);   
                    Utils::printVec("",delta);   
               }   
               else GePrint("Snap is off!");   
.   
.   

res.hitpos is the rayCollider hit position on obj, that i click with the mouse.

'IsEnabled' works as it should, it gives me TRUE when its enabled in my snapping tab, but the result in delta seems to be incorrect.

When i set mode to 'Snap3D' and enable point-snap, delta is off like 100-200 units even though i click directly onto a point of obj, in the perspective view.

So my question is how to use the DetectSnapping.lib and does it provide the complete snapping functionality that for example the move tool has ?
Am I on the right track with the above code, or does it not work like that ?

When i call SnapTo() does it take into account all the settings i did in the snapping tab of my plugin automatically,as it is the standart c4d snapping tab, and i set the snapping flag in registerToolPlugin(..) ?

There dont seem to be any examples on how to use it, so the above code is actually just my guess on how to use it.

greetings,
Daniel

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/01/2010 at 03:08, xxxxxxxx wrote:

so nobody has any experience with this ?
(aka bump ..)

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/01/2010 at 09:19, xxxxxxxx wrote:

does anbody know what delta exactly returns ?
i always assumed it was the difference between the argument vector of SnapTo, and the nearest possible snap point, according to the snap settings.

seems to give me some unrealistic values though in my tests..

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/01/2010 at 00:41, xxxxxxxx wrote:

The delta is indeed the difference between the position to check for snapping and the snap position. Check if SnapTo returns TRUE and if so a snapping was found and delta filled accordingly.

This is the code I used in one of my plugins.

  
AutoAlloc<DetectSnapping> snap;  
if (!snap) return FALSE;  
snap->Init(doc, bd, NULL, Vector(), 0, FALSE, TRUE, TRUE);  
  
Vector pos = ...; //pos is the position i want to check for snapping  
Vector delta;  
  
if (snap->SnapTo(pos, &delta))  
{  
  pos += delta; //if pos can be snapped it is set accordingly  
}  

cheers,
Matthias