Esempio n. 1
0
Vector3d Polygon::velocity(const Grid &g, const Vector3d &w) const
{
    const double SMALL = Vector3d::get_small();
    Vector3d u;
    double d;
    double s = 0.0;
    for (size_t i = 0; i < size(); ++i)
    {
        d = (POINT(i) - w).norm();
        if (d < SMALL) return VELOCITY(i);
        d = 1.0 / d;
        s += d;
        u += d * VELOCITY(i);
    }
    return u / s;
}
static int 
_elitaire_card_flip_cb(void * data)
{
    Elitaire_Card_Job * job;
    Evas_Object * card, * image, * shadow;
    Elitaire_Card * eli_card;
    Evas_Coord w, h;
    Evas_Coord im_x, im_w, im_y;
    Evas_Coord new_x, new_w;
    Evas_Coord sh_y, sh_x;
    Evas_Coord x;
    
    job = (Elitaire_Card_Job *) data;
    card = job->card;
    eli_card = (Elitaire_Card *) evas_object_smart_data_get(card);
    image = eli_card->image;
    shadow = eli_card->shadow;
    
    evas_object_geometry_get(card, &x, NULL, &w, &h);
    evas_object_geometry_get(image, &im_x, &im_y, &im_w, NULL);
    if (shadow)
        evas_object_geometry_get(shadow, &sh_x, &sh_y, NULL, NULL);
    
    new_w = im_w + job->y.ec * (Evas_Coord) (VELOCITY(eli_card->eli)
                                              / eli_card->eli->frame_rate);
    if (new_w < 0) {
        job->y.ec = 1;
        new_w = ABS(new_w);
        elitaire_card_reinit(card);
    }
    if (new_w >= w) {
        /* Job now ends */
        new_w = eli_card->eli->card_w;
        new_x = x;
        evas_object_resize(image, new_w, h);
        evas_object_move(image, new_x, im_y);
        if (shadow) {
            sh_x += (im_w - new_w) / 2;
            evas_object_resize(shadow, new_w, h);
            evas_object_move(shadow, sh_x, sh_y);
        }
        elitaire_job_del(eli_card->jobs, data);
        return 0;
    }
    new_x = im_x + (im_w - new_w) / 2;
    evas_object_resize(image, new_w, h);
    evas_object_move(image, new_x, im_y);
    if (shadow) {
        sh_x += (im_w - new_w) / 2;
        evas_object_resize(shadow, new_w, h);
        evas_object_move(shadow, sh_x, sh_y);
    }

    return 1;
}
static int 
_elitaire_card_drop_cb(void * data)
{
    Elitaire_Card_Job * job;
    Evas_Object * card = NULL;
    Evas_Coord x, y, w, d;
    Evas_Coord image_x, image_y;
    Elitaire_Card * eli_card;

    job = (Elitaire_Card_Job *) data;
    card = job->card;

    eli_card = (Elitaire_Card *) evas_object_smart_data_get(card);

    evas_object_geometry_get(card, &x, &y, &w, NULL);
    evas_object_geometry_get(eli_card->image, &image_x, &image_y, NULL, NULL);

    d = (Evas_Coord) (VELOCITY(eli_card->eli) / eli_card->eli->frame_rate);
    image_x += d;
    image_y += d;

    if (image_x >= x || image_y >= y) {
        /* Job now ends */
        evas_object_move(eli_card->image, x, y);
        if (eli_card->next_card) {
            Evas_Coord dy;

            dy = elitaire_card_offset_get(eli_card->eli);
            evas_object_move(eli_card->next_card, x, y + dy);
        }
        _elitaire_card_shadow_off(card);
        elitaire_stack_layer_reinit(eli_card->eli, eli_card->pcard);
        elitaire_job_del(eli_card->jobs, data);
        return 0;
    }

    evas_object_move(eli_card->image, image_x, image_y);

    if (eli_card->next_card) {
        Evas_Coord dy;

        dy = elitaire_card_offset_get(eli_card->eli);
        evas_object_move(eli_card->next_card, image_x, image_y + dy);
    }
    return 1;
}
static int 
_elitaire_card_drag_cb(void * data)
{
    Elitaire_Card_Job * job;
    Elitaire_Card * eli_card;
    Evas_Coord x, y, w, d;
    Evas_Coord image_x, image_y;
    Evas_Object * card = NULL;

    job = (Elitaire_Card_Job *) data;
    card = job->card;
    eli_card = (Elitaire_Card *) evas_object_smart_data_get(card);

    evas_object_geometry_get(eli_card->shadow, &x, &y, &w, NULL);
    evas_object_geometry_get(eli_card->image, &image_x, &image_y, NULL, NULL);

    d = (Evas_Coord) (VELOCITY(eli_card->eli) / (eli_card->eli->frame_rate * 2));
    image_x -= d;
    image_y -= d;

    if (abs(x - image_x) >= w / 10) {
        /* Job now ends */
        evas_object_move(eli_card->image, x - w / 10, y - w / 10);
        
        if (eli_card->next_card) {
            Evas_Coord dy;

            dy = elitaire_card_offset_get(eli_card->eli);
            evas_object_move(eli_card->next_card, x - w / 10, y - w / 10 + dy);
        }

        elitaire_job_del(eli_card->jobs, data);
        return 0;
    }

    evas_object_move(eli_card->image, image_x, image_y);

    if (eli_card->next_card) {
        Evas_Coord dy;

        dy = elitaire_card_offset_get(eli_card->eli);
        evas_object_move(eli_card->next_card, image_x, image_y + dy);
    }

    return 1;
}
/* ***************************************************************************
 * callbacks
 * ***************************************************************************/
static int 
_elitaire_card_slide_cb(void * data)
{
    Elitaire_Card_Job * job;
    Evas_Object * card;
    Elitaire_Card * eli_card;
    Evas_Coord to_x, to_y;
    Evas_Coord from_x, from_y;
    Evas_Coord new_x, new_y;
    double m, ft;

    job = (Elitaire_Card_Job *) data;
    card = job->card;
    eli_card = (Elitaire_Card *) evas_object_smart_data_get(card);
    ft = _elitaire_card_job_frametime_get(job);

    if (job->w == eli_card->eli->w) {
        to_x = job->x.ec;
        to_y = job->y.ec;
    }
    else {
        elitaire_card_xy_get(card, &to_x, &to_y);
        job->w = eli_card->eli->w;
        job->x.ec = to_x;
        job->y.ec = to_y;
    }

    evas_object_geometry_get(card, &from_x, &from_y, NULL, NULL);

    m = VELOCITY(eli_card->eli) * ft
        / sqrt((double) (SQR(to_x - from_x) + SQR(to_y - from_y)));

    new_x = (Evas_Coord) (m * (to_x - from_x)) + from_x;
    new_y = (Evas_Coord) (m * (to_y - from_y)) + from_y;

    if (ABS(new_x - from_x) >= ABS(to_x - from_x)
        && ABS(new_y - from_y) >= ABS(to_y - from_y)) {
        /* Job now ends */
        evas_object_move(card, to_x, to_y);
        elitaire_job_del(eli_card->jobs, data);
        return 0;
    }
    evas_object_move(card, new_x, new_y);

    return 1;
}
Esempio n. 6
0
OP_ERROR aaOceanSOP::cookMySop(OP_Context &context)
{
    if (lockInputs(context) >= UT_ERROR_ABORT)
        return error();

    duplicateSource(0, context);
    setVariableOrder(3, 2, 0, 1);
    setCurGdh(0, myGdpHandle);
    setupLocalVars();

    // variable declarations
    float now  = context.getTime();

    // Flag the SOP as being time dependent (i.e. cook on time changes)
    flags().timeDep = 1;
    
    // start pulling in SOP inputs and send to aaOcean 
    enableEigens = (ENABLEEIGENS() != 0);
    if(pOcean->isChoppy() && enableEigens)
        enableEigens = TRUE;
    now = now + TIMEOFFSET(now);

    pOcean->input(  RESOLUTION(), 
                    SEED(),
                    OCEANSCALE(now),
                    OCEANDEPTH(now),
                    SURFACETENSION(now),
                    VELOCITY(now), 
                    CUTOFF(now), 
                    WINDDIR(now), 
                    WINDALIGN(), 
                    DAMP(now), 
                    WAVESPEED(now), 
                    WAVEHEIGHT(now),
                    CHOP(now), 
                    now,
                    LOOPTIME(now),
                    enableEigens,
                    FALSE);

    // get the user-specified attribute that holds uv-data
    getUVAttributeName(UvAttribute);
    if(UvAttribute.length() == 0)
        UvAttribute = "uv";
    const char* UVAttribName = (const char *)UvAttribute;
    uvRef = gdp->findFloatTuple(GA_ATTRIB_POINT, UVAttribName, 3);

    if(uvRef.isValid() == TRUE)
    {
        uvAttribute = uvRef.getAttribute();
        uvTuple = uvRef.getAIFTuple(); 
    }
    else
    {
        // uv attribute not found
        char msg[256];
        sprintf(msg, "[aaOcean] Specified UV attribute \'%s\' not found on geometry.\
                     \nUV's are required for aaOcean to cook", UVAttribName);
        std::cout<<msg;
        std::cout.flush();
        addError(SOP_MESSAGE, msg); 
        unlockInputs();
        return error();
    }

    // setup local variables to output Eigens
    if(enableEigens)
    {
        eVecPlusRef  = gdp->addFloatTuple(GA_ATTRIB_POINT, eVecPlusName,    3);
        eVecMinusRef = gdp->addFloatTuple(GA_ATTRIB_POINT, eVecMinusName,   3);
        eValuesRef   = gdp->addFloatTuple(GA_ATTRIB_POINT, eValuesName,     1);

        eVecPlusHandle  = GA_RWHandleV3(eVecPlusRef.getAttribute());
        eVecMinusHandle = GA_RWHandleV3(eVecMinusRef.getAttribute());
        eValuesHandle   = GA_RWHandleF(eValuesRef.getAttribute());
    }
    
    // inputs validated. Begin writing ocean data to output handles
    int npts = gdp->getNumPoints();
    #pragma omp parallel for 
    for (int pt_offset = 0; pt_offset < npts; ++pt_offset)
    {
        UT_Vector3F pos = gdp->getPos3(pt_offset);
        UT_Vector3F UV;
        
        uvTuple->get(uvAttribute, pt_offset, UV.data(), 3);
        // Houdini V coord runs in opposite direction compared to Softimage/Maya
        // Conforming with other apps to make ocean shape consistent across apps
        float u = UV.x();
        float v = 1.0f - (fmod(UV.y(), 1.0f));

        pos.y() += pOcean->getOceanData(u, v, aaOcean::eHEIGHTFIELD);
        if(pOcean->isChoppy())
        {
            pos.x() += pOcean->getOceanData(u, v, aaOcean::eCHOPX);
            pos.z() += pOcean->getOceanData(u, v, aaOcean::eCHOPZ);
        }
        gdp->setPos3(pt_offset, pos);

       if(enableEigens)
        {
            UT_Vector3F eigenVectorPlusValue;
            UT_Vector3F eigenVectorMinusValue;
            float eigenValue;

            eigenVectorPlusValue.x() =  pOcean->getOceanData(u, v, aaOcean::eEIGENPLUSX);
            eigenVectorPlusValue.y() =  0.0f;
            eigenVectorPlusValue.z() =  pOcean->getOceanData(u, v, aaOcean::eEIGENPLUSZ);

            eigenVectorMinusValue.x() = pOcean->getOceanData(u, v, aaOcean::eEIGENMINUSX);
            eigenVectorMinusValue.y() = 0.0f;
            eigenVectorMinusValue.z() = pOcean->getOceanData(u, v, aaOcean::eEIGENMINUSZ);

            eigenValue = pOcean->getOceanData(u, v, aaOcean::eFOAM);

            eVecPlusHandle.set(pt_offset,eigenVectorPlusValue);
            eVecMinusHandle.set(pt_offset,eigenVectorMinusValue);
            eValuesHandle.set(pt_offset,eigenValue);
        }
    }
    unlockInputs();

    return error();
}