[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
[534] | 2 | // Copyright (C) 1999-2016 Maciej Komosinski and Szymon Ulatowski. |
---|
[286] | 3 | // See LICENSE.txt for details. |
---|
[121] | 4 | |
---|
[109] | 5 | #include <stdio.h> |
---|
| 6 | #include <frams/model/model.h> |
---|
| 7 | #include <frams/model/modelparts.h> |
---|
| 8 | |
---|
| 9 | int main() |
---|
| 10 | { |
---|
[139] | 11 | Model m; |
---|
| 12 | Part *p1, *p2; |
---|
[109] | 13 | |
---|
[139] | 14 | m.open(); |
---|
[109] | 15 | |
---|
[139] | 16 | // chain of ellipsoids - subsequent parts are placed relative to the previous part's orientation and location |
---|
| 17 | p1 = m.addNewPart(Part::SHAPE_ELLIPSOID); //initial part |
---|
| 18 | p1->scale = Pt3D(1.0, 0.7, 0.4); |
---|
[109] | 19 | |
---|
[139] | 20 | Orient rotation = Orient_1; //must be initialized explicitly because the default Orient constructor does not initialize anything |
---|
| 21 | rotation.rotate(Pt3D(0.1, 0.2, 0.3)); |
---|
[109] | 22 | |
---|
[139] | 23 | for (int N = 10; N > 0; N--, p1 = p2) |
---|
[109] | 24 | { |
---|
[139] | 25 | p2 = m.addNewPart(Part::SHAPE_ELLIPSOID); |
---|
| 26 | p2->scale = p1->scale*0.9; //each part is smaller than its predecessor |
---|
[109] | 27 | |
---|
[139] | 28 | Pt3D advance(p1->scale.x, 0, 0); //advance by previous part's ellipsoid x radius |
---|
| 29 | p2->p = p1->p + p1->o.transform(advance); //advance vector transformed by p1's orientation (i.e., in p1's local coordinates) |
---|
| 30 | p2->setOrient(p1->o.transform(rotation)); //rotation transformed by p1's orientation |
---|
| 31 | |
---|
[544] | 32 | m.addNewJoint(p1, p2, Joint::SHAPE_FIXED); //all parts must be connected |
---|
[109] | 33 | } |
---|
| 34 | |
---|
[139] | 35 | // 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) |
---|
| 36 | Pt3D prev, next; |
---|
| 37 | p1 = m.getPart(0); |
---|
| 38 | for (float a = 0; a<M_PI; a += M_PI / 10) |
---|
[109] | 39 | { |
---|
[139] | 40 | Pt3D next(2 - 2 * cos(a), 0, 2 * sin(a)); |
---|
| 41 | if (a>0) |
---|
[109] | 42 | { |
---|
[139] | 43 | p2 = m.addNewPart(Part::SHAPE_CYLINDER); |
---|
| 44 | p2->setPositionAndRotationFromAxis(prev, next); |
---|
| 45 | p2->scale = Pt3D(prev.distanceTo(next)*0.5, 0.05, 0.05);// distance*0.5 because scale is "radius", not cylinder length |
---|
[109] | 46 | |
---|
[544] | 47 | m.addNewJoint(p1, p2, Joint::SHAPE_FIXED); //all parts must be connected |
---|
[109] | 48 | } |
---|
[139] | 49 | p1 = p2; |
---|
| 50 | prev = next; |
---|
[109] | 51 | } |
---|
| 52 | |
---|
[139] | 53 | m.close(); |
---|
[534] | 54 | puts(m.getF0Geno().getGenesAndFormat().c_str()); |
---|
[139] | 55 | // the genotype can be fed directly to the genotype viewer, like this: |
---|
[152] | 56 | // part_shapes | theater -g - |
---|
[109] | 57 | } |
---|