THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/04/2012 at 14:13, xxxxxxxx wrote:
Hi,
Yannick code is fine you only have to apply it in your case.
here a little example try to put it in liquid tool in c4dsdk example and remember to turn on and set snap settings:
Bool LiquidToolData::MouseInput(BaseDocument *doc, BaseContainer &data;, BaseDraw *bd,EditorWindow *win, const BaseContainer &msg;)
{
//get mouse position
Real mx = msg.GetReal(BFM_INPUT_X);
Real my = msg.GetReal(BFM_INPUT_Y);
Vector pos = bd->SW(Vector(mx, my, 500)); // bring mouse pos in world space
Vector delta = Vector();
BaseObject *active = doc->GetActiveObject(); // get the active object
LONG button;
switch (msg.GetLong(BFM_INPUT_CHANNEL))
{
case BFM_INPUT_MOUSELEFT : button=KEY_MLEFT; break;
case BFM_INPUT_MOUSERIGHT: button=KEY_MRIGHT; break;
default: return TRUE;
}
if (!active) // if no active object create a new sphere and inser it in document
{
active = BaseObject::Alloc(Osphere);
if (!active) return FALSE;
doc->InsertObject(active, NULL, NULL, TRUE);
active->SetAbsPos(pos);
}
AutoAlloc<DetectSnapping>snap; // alloc the snap
if (!snap) return FALSE;
snap->Init(doc, bd, NULL, Vector(), 0, FALSE, TRUE, TRUE); // initialize snap
Real dx,dy;
BaseContainer bc;
BaseContainer device;
win->MouseDragStart(button,mx,my,MOUSEDRAGFLAGS_DONTHIDEMOUSE|MOUSEDRAGFLAGS_NOMOVE);
while (win->MouseDrag(&dx;,&dy;,&device;)==MOUSEDRAGRESULT_CONTINUE) // start drag
{
// increment mouse position during drag
mx+=dx;
my+=dy;
pos = bd->SW(Vector(mx, my, 500)); // update pos
if (snap->SnapTo(pos, δ)) // if point snap anywhere
{
pos += delta; // pos will be updated with snapped delta
}
if (active) active->SetAbsPos(pos); // set the object position to the new one!
DrawViews(DRAWFLAGS_ONLY_ACTIVE_VIEW|DRAWFLAGS_NO_THREAD|DRAWFLAGS_NO_ANIMATION); //update viewport
}
win->MouseDragEnd(); // reset viewport status
EventAdd();
return TRUE;
}
i hope this help
Franz