# source:cpp/frams/_demos/part_shapes.cpp@121

Last change on this file since 121 was 121, checked in by sz, 6 years ago

• Property svn:eol-style set to `native`
File size: 1.9 KB
Line
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include <stdio.h>
6#include <frams/model/model.h>
7#include <frams/model/modelparts.h>
8
9int main()
10{
11Model *m=new Model;
12Part *p1,*p2;
13Joint *j;
14
15m->open();
16
17// chain of ellipsoids - subsequent parts are placed relative to the previous part's orientation and location
19p1->scale=Pt3D(1.0,0.7,0.4);
20
21Orient rotation=Orient_1; //must be initialized explicitly because the default Orient constructor does not initialize anything
22rotation.rotate(Pt3D(0.1,0.2,0.3));
23
24for(int N=10;N>0;N--,p1=p2)
25        {
27        p2->scale=p1->scale*0.9; //each part is smaller than its predecessor
28
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
32
33        m->addNewJoint(p1,p2,Joint::SHAPE_SOLID); //all parts must be connected
34        }
35
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)
37Pt3D prev,next;
38p1=m->getPart(0);
39for(float a=0;a<M_PI;a+=M_PI/10)
40        {
41        Pt3D next(2-2*cos(a),0,2*sin(a));
42        if (a>0)
43                {
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
47
48                m->addNewJoint(p1,p2,Joint::SHAPE_SOLID); //all parts must be connected
49                }
50        p1=p2;
51        prev=next;
52        }
53
54m->close();
55puts((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 -
58}
Note: See TracBrowser for help on using the repository browser.