Пример #1
0
Acad::ErrorStatus
AsdkSmiley::dwgInFields(AcDbDwgFiler *filer)
{
    assertWriteEnabled();

    AcDbEntity::dwgInFields( filer );

    // Read version number
    double version;
    filer->readItem( &version );

    if ( version > kCurrentVersionNumber ){
        ads_printf( "\nNew version of AsdkSmiley object found (version %.1f found, version %.1f supported): upgrade your Smiley.dbx to enable these objects.", version, kCurrentVersionNumber );
        return Acad::eMakeMeProxy;
    }

    AcGePoint3d center, mouthleftpt, mouthbottompt, mouthrightpt;
    double radius;
    filer->readItem( &center );
    filer->readItem( &radius );
    setCenter( center );
    setRadius( radius );
    filer->readItem( &mnormal );
    filer->readItem( &meyesapart );
    filer->readItem( &meyesheight );
    filer->readItem( &meyesize );
    filer->readItem( &mouthleftpt );
    filer->readItem( &mouthbottompt );
    filer->readItem( &mouthrightpt );
    setMouth( mouthleftpt, mouthbottompt, mouthrightpt );

    return filer->filerStatus();
}
Пример #2
0
void
AsdkSmiley::scaleRadius(const double r)       
{
    assertWriteEnabled();
    AcGePoint3d center( center() );
    double rad = radius(),
           factor = r / rad;
    setEyesApart( factor * meyesapart );
    setEyesHeight( factor * meyesheight );
    setEyeSize( factor * meyesize );
    AcGePoint3d left( mouthLeft() ),
                bottom( mouthBottom() ),
                right( mouthRight() );
    setMouth( left.scaleBy( factor, center ), bottom.scaleBy( factor, center ), right.scaleBy( factor, center ) );
    setRadius( r );
    recordGraphicsModified();
} // smiley radius
Пример #3
0
Acad::ErrorStatus
AsdkSmiley::moveGripPointsAt(
    const AcDbIntArray& indices,
    const AcGeVector3d& offset)
{
    assertWriteEnabled();

    AcGePoint3dArray eyearray;
    AcGePoint3d oldquad, newquad, newmouthcenter, newmouthbottom,
                smilecen, startpt, endpt, midpt, newpt;
    AcGeVector3d vecstart(0,0,0), vecend(0,0,0), newvec(0,0,0);

    eyes( eyearray );
    for( int i = 0; i < indices.length(); i++ ) {
        int idx = indices[i];
        switch( idx ) {

        // Stretch smiley center
        //
        case 0:
            setCenter( center() + offset );
            continue;

        // Stretch smiley radius
        //
        case 1:
            oldquad = center() + AcGeVector3d( radius(), 0, 0 );
            break;
        case 2:
            oldquad = center() + AcGeVector3d( 0, radius(), 0 );
            break;
        case 3:
            oldquad = center() - AcGeVector3d( radius(), 0, 0 );
            break;
        case 4:
            oldquad = center() - AcGeVector3d( 0, radius(), 0 );
            break;

        // Stretch smiley mouth
        //
        case 5:
            // Left hand edge of mouth
            //
            setMouthLeft( mouthLeft() + offset );
            ensureRadius();

            continue;

        case 6:
            // Right hand edge of mouth
            //
            setMouthRight( mouthRight() + offset );
            ensureRadius();

            continue;

        case 7:
            // Middle mouth chord
            //
            setMouth( mouthLeft() + offset, mouthBottom() + offset, mouthRight() + offset );
            ensureRadius();

            continue;

        case 8:
            // Bottom of mouth arc
            //
            setMouthBottom( mouthBottom() + offset );
            ensureRadius();

            continue;

        // Stretch smiley eyes
        //
        default:
            if(( eyearray.length() * 5 ) + 9 > idx ){
                
                // Get eye number, extracting it from the array
                //
                int eyepos = (int)(( idx - 9 ) / 5 );
                AcGePoint3d eyecen = eyearray.at( eyepos );
                
                // Handle the grip for the eye
                //
                int subidx = idx - 9;
                while ( subidx >= 5 ){ subidx -= 5; }
                switch( subidx ){

                // Stretch eye center
                //
                case 0:
                    // Keep the minimum eye height at zero
                    //
                    if( meyesheight+offset[Y] < 0 )
                        setEyesHeight( 0 );
                    else
                        setEyesHeight( meyesheight + offset[Y] );

                    // Keep the eyes from overlapping
                    //
                    if( eyecen[X] < center()[X] ){    // left eye
                        if( meyesapart - ( offset[X] * 2 ) < meyesize * 2 )
                            setEyesApart( meyesize * 2 );
                        else
                            setEyesApart( meyesapart - ( offset[X] * 2 ));
                    }
                    else {                          // right eye
                        if( meyesapart + ( offset[X] * 2 ) < meyesize * 2 )
                            setEyesApart( meyesize * 2 );
                        else
                            setEyesApart( meyesapart + ( offset[X] * 2));
                    }
                    ensureRadius();
                    continue;

                // Stretch eye radius
                //
                case 1:
                    oldquad = eyecen + AcGeVector3d( meyesize, 0, 0 );
                    break;
                case 2:
                    oldquad = eyecen + AcGeVector3d( 0, meyesize, 0 );
                    break;
                case 3:
                    oldquad = eyecen - AcGeVector3d( meyesize, 0, 0 );
                    break;
                case 4:
                    oldquad = eyecen - AcGeVector3d( 0, meyesize, 0 );
                    break;
                }
                newquad = oldquad + offset;
                
                // Keep eyes from touching
                //
                if( newquad.distanceTo( eyecen ) > meyesapart / 2 )
                    setEyeSize( meyesapart / 2 );
                else
                    setEyeSize( newquad.distanceTo( eyecen ));
                ensureRadius();
            }
            continue;
        }
        newquad = oldquad + offset;
        scaleRadius( newquad.distanceTo( center() ));
    }

    return Acad::eOk;
}
Пример #4
0
void GameMapRecrusive::generate(int rs, int cs, int re, int ce)
{
    int ro = generateRow(rs, cs, re, ce);
    int co = generateCol(rs, cs, re, ce);

    if(ro==co && ro==-1)
        return;

    bool allowTrap = (m_vLevel>1);

    if(ro!=-1 && co==-1)
    {
        int cm = rand(cs, ce);
        setMouth(ro, cm, allowTrap);
        generate(rs, cs, ro, ce);
        generate(ro+1, cs, re, ce);
    }
    else if(ro==-1 && co!=-1)
    {
        int rm = rand(rs, re);
        setMouth(rm, co, allowTrap);
        generate(rs, cs, re, co);
        generate(rs, co+1, re, ce);
    }
    else
    {
        int candy[] = {0, 1, 2, 3};
        std::random_shuffle(candy, candy+4);

        for(int i=0; i<3; ++i)
        {
            int r,c;

            switch(candy[i])
            {
            case 0:
                r = rand(rs, ro);
                c = co;
                break;

            case 1:
                r = ro;
                c = rand(co+1, ce);
                break;

            case 2:
                r = rand(ro+1, re);
                c = co;
                break;

            case 3:
                r = ro;
                c = rand(cs+1, co);
                break;

            default:
                break;
            }

            setMouth(r, c, allowTrap);
        }

        generate(rs, cs, ro, co);
        generate(rs, co+1, ro, ce);
        generate(ro+1, co+1, re, ce);
        generate(ro+1, cs, re, co);
    }
}