Ignore:
Timestamp:
02/20/14 17:49:28 (6 years ago)
Author:
sz
Message:

class renaming + minor corrections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/part_shapes.cpp

    r121 r139  
    99int main()
    1010{
    11 Model *m=new Model;
    12 Part *p1,*p2;
    13 Joint *j;
     11        Model m;
     12        Part *p1, *p2;
     13        Joint *j;
    1414
    15 m->open();
     15        m.open();
    1616
    17 // chain of ellipsoids - subsequent parts are placed relative to the previous part's orientation and location
    18 p1=m->addNewPart(Part::SHAPE_ELLIPSOID); //initial part
    19 p1->scale=Pt3D(1.0,0.7,0.4);
     17        // chain of ellipsoids - subsequent parts are placed relative to the previous part's orientation and location
     18        p1 = m.addNewPart(Part::SHAPE_ELLIPSOID); //initial part
     19        p1->scale = Pt3D(1.0, 0.7, 0.4);
    2020
    21 Orient rotation=Orient_1; //must be initialized explicitly because the default Orient constructor does not initialize anything
    22 rotation.rotate(Pt3D(0.1,0.2,0.3));
     21        Orient rotation = Orient_1; //must be initialized explicitly because the default Orient constructor does not initialize anything
     22        rotation.rotate(Pt3D(0.1, 0.2, 0.3));
    2323
    24 for(int N=10;N>0;N--,p1=p2)
     24        for (int N = 10; N > 0; N--, p1 = p2)
    2525        {
    26         p2=m->addNewPart(Part::SHAPE_ELLIPSOID);
    27         p2->scale=p1->scale*0.9; //each part is smaller than its predecessor
    28        
    29         Pt3D advance(p1->scale.x,0,0); //advance by previous part's ellipsoid x radius
    30         p2->p = p1->p + p1->o.transform(advance); //advance vector transformed by p1 orientation == in p1 local coordinates
    31         p2->setOrient(p1->o.transform(rotation)); //rotation transformed by p1 orientation
     26                p2 = m.addNewPart(Part::SHAPE_ELLIPSOID);
     27                p2->scale = p1->scale*0.9; //each part is smaller than its predecessor
    3228
    33         m->addNewJoint(p1,p2,Joint::SHAPE_SOLID); //all parts must be connected
     29                Pt3D advance(p1->scale.x, 0, 0); //advance by previous part's ellipsoid x radius
     30                p2->p = p1->p + p1->o.transform(advance); //advance vector transformed by p1's orientation (i.e., in p1's local coordinates)
     31                p2->setOrient(p1->o.transform(rotation)); //rotation transformed by p1's orientation
     32
     33                m.addNewJoint(p1, p2, Joint::SHAPE_SOLID); //all parts must be connected
    3434        }
    3535
    36 // chain of cyllinders - line segments between points calculated from the parametric formula P(a)=(2-2*cos(a),2*sin(a)) (circle with r=2)
    37 Pt3D prev,next;
    38 p1=m->getPart(0);
    39 for(float a=0;a<M_PI;a+=M_PI/10)
     36        // chain of cyllinders - line segments between points calculated from the parametric formula P(a)=(2-2*cos(a),2*sin(a)) (circle with r=2)
     37        Pt3D prev, next;
     38        p1 = m.getPart(0);
     39        for (float a = 0; a<M_PI; a += M_PI / 10)
    4040        {
    41         Pt3D next(2-2*cos(a),0,2*sin(a));
    42         if (a>0)
     41                Pt3D next(2 - 2 * cos(a), 0, 2 * sin(a));
     42                if (a>0)
    4343                {
    44                 p2=m->addNewPart(Part::SHAPE_CYLINDER);
    45                 p2->setPositionAndRotationFromAxis(prev,next);
    46                 p2->scale=Pt3D(prev.distanceTo(next)*0.5,0.05,0.05);// distance*0.5 because scale is "radius", not cylinder length
     44                        p2 = m.addNewPart(Part::SHAPE_CYLINDER);
     45                        p2->setPositionAndRotationFromAxis(prev, next);
     46                        p2->scale = Pt3D(prev.distanceTo(next)*0.5, 0.05, 0.05);// distance*0.5 because scale is "radius", not cylinder length
    4747
    48                 m->addNewJoint(p1,p2,Joint::SHAPE_SOLID); //all parts must be connected
     48                        m.addNewJoint(p1, p2, Joint::SHAPE_SOLID); //all parts must be connected
    4949                }
    50         p1=p2;
    51         prev=next;
     50                p1 = p2;
     51                prev = next;
    5252        }
    5353
    54 m->close();
    55 puts((const char*)m->getF0Geno().toString());
    56 // the genotype can be fed directly to the genotype viewer, like this:
    57 // part_shapes | theater -g -vpart_shapes -
     54        m.close();
     55        puts((const char*)m.getF0Geno().toString());
     56        // the genotype can be fed directly to the genotype viewer, like this:
     57        // part_shapes | theater -g -vpart_shapes -
    5858}
Note: See TracChangeset for help on using the changeset viewer.