Tool Button for the Sphere Interactor

In order to create a sphere, the user must be able to create a interactor object. This is usually done by clicking a tool button.

The sphtool.c source file implements a tool button that creates a sphere interactor.

We already demonstrated how tool buttons work in the Geometric Deformer example. The only difference to the geometric deformer is that the sphere tool button doesn't call an extension method but creates an interactor by calling the R3LAYM_NEWINTERACTOR method.



    static void *r3iam_action(R3CLASS *cl, R3OBJ *obj)
    {
        R3IDATA *self = R3CL_IADDR(cl, obj);
        R3OBJ *layer, *interactor;

        R3GetAttrs(obj, R3TOOLA_Layer, &layer, R3RA_Done);
        if (layer) 
            interactor = R3MAC_SNDMSGA(app, "R3CurrentLayer", layer, R3LAYM_NEWINTERACTOR,
                                       R3CLID_SDKSPHEREINTERACTOR, R3MCTP_INT);
        return obj;
    }
    

Some interactors can be very versatile. For example, the sphere interactor could allow you to create many kind of spheres and you could correspondingly have several tool buttons which all create the very same interactor, only with different options. The following code demonstrates how one can set interactor specific attributes (again, we support macro system here):


    static void *r3iam_action(R3CLASS *cl, R3OBJ *obj)
    {
        R3IDATA *self = R3CL_IADDR(cl, obj);
        R3OBJ *layer, *interactor;

        R3GetAttrs(obj, R3TOOLA_Layer, &layer, R3RA_Done);
        if (layer) 
            interactor = R3MAC_SNDMSGA(app, "R3CurrentLayer", layer, R3LAYM_NEWINTERACTOR,
                                       R3CLID_SDKSPHEREINTERACTOR, R3MCTP_INT);
            if(interactor) {
                /* multiple tools can activate the same interactor, so we need
                to identify us so that the toolbar don't get confused which
                button should be selected */
                R3MAC_SETATTR(app, "R3CurrentInteractor", interactor,
                           R3IAA_Identifier, R3CLID_MYTOOLBUTTON1, R3MCTP_INT);

                /* set some other interactor attributes */
                R3MAC_SETATTR(app, "R3CurrentInteractor", interactor,
                           SPHA_DefineMethod, SPHDM_CENTERRADIUS, R3MCTP_INT);
            }

        return obj;
    }