source: cpp/frams/_demos/part_shapes.cpp @ 1310

Last change on this file since 1310 was 544, checked in by Maciej Komosinski, 8 years ago

Renamed:
Model::getShape() ==> Model::getShapeType()
Model::SHAPE_OLD ==> Model::SHAPE_BALL_AND_STICK
Model::SHAPE_NEW ==> Model::SHAPE_SOLIDS
Part::SHAPE_DEFAULT ==> Part::SHAPE_BALL_AND_STICK
Joint::SHAPE_DEFAULT ==> Joint::SHAPE_BALL_AND_STICK
Joint::SHAPE_SOLID ==> Joint::SHAPE_FIXED

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2016  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#include <stdio.h>
6#include <frams/model/model.h>
7#include <frams/model/modelparts.h>
8
9int main()
10{
11        Model m;
12        Part *p1, *p2;
13
14        m.open();
15
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);
19
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));
22
23        for (int N = 10; N > 0; N--, p1 = p2)
24        {
25                p2 = m.addNewPart(Part::SHAPE_ELLIPSOID);
26                p2->scale = p1->scale*0.9; //each part is smaller than its predecessor
27
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
32                m.addNewJoint(p1, p2, Joint::SHAPE_FIXED); //all parts must be connected
33        }
34
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)
39        {
40                Pt3D next(2 - 2 * cos(a), 0, 2 * sin(a));
41                if (a>0)
42                {
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
46
47                        m.addNewJoint(p1, p2, Joint::SHAPE_FIXED); //all parts must be connected
48                }
49                p1 = p2;
50                prev = next;
51        }
52
53        m.close();
54        puts(m.getF0Geno().getGenesAndFormat().c_str());
55        // the genotype can be fed directly to the genotype viewer, like this:
56        // part_shapes | theater -g -
57}
Note: See TracBrowser for help on using the repository browser.