Alvaro Cassinelli
/
skinGames_II
save loops
classRigidScafold.cpp@1:3be7b7d050f4, 2014-12-02 (annotated)
- Committer:
- mbedalvaro
- Date:
- Tue Dec 02 08:29:59 2014 +0000
- Revision:
- 1:3be7b7d050f4
- Parent:
- 0:df6fdd9b99f0
updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:df6fdd9b99f0 | 1 | #include "classRigidScafold.h" |
mbedalvaro | 0:df6fdd9b99f0 | 2 | |
mbedalvaro | 0:df6fdd9b99f0 | 3 | RigidScafold::RigidScafold() { |
mbedalvaro | 0:df6fdd9b99f0 | 4 | } |
mbedalvaro | 0:df6fdd9b99f0 | 5 | |
mbedalvaro | 0:df6fdd9b99f0 | 6 | RigidScafold::~RigidScafold() { |
mbedalvaro | 0:df6fdd9b99f0 | 7 | } |
mbedalvaro | 0:df6fdd9b99f0 | 8 | |
mbedalvaro | 0:df6fdd9b99f0 | 9 | |
mbedalvaro | 0:df6fdd9b99f0 | 10 | void RigidScafold::buildCircularScafold(float _radius, vector2Dd _pos, int _numScafoldPoints) { |
mbedalvaro | 0:df6fdd9b99f0 | 11 | sizeScafold=_radius; |
mbedalvaro | 0:df6fdd9b99f0 | 12 | centerScafold=_pos; |
mbedalvaro | 0:df6fdd9b99f0 | 13 | scafold.resize(_numScafoldPoints); |
mbedalvaro | 0:df6fdd9b99f0 | 14 | float angInc= 2.0 * PI / _numScafoldPoints; |
mbedalvaro | 0:df6fdd9b99f0 | 15 | float ang=0; |
mbedalvaro | 0:df6fdd9b99f0 | 16 | for (int i = 0; i < scafold.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 17 | scafold[i]= vector2Dd( cos(ang)* _radius, sin(ang)* sizeScafold ) + centerScafold; |
mbedalvaro | 0:df6fdd9b99f0 | 18 | // note: I cannot do vector2Dd( cos(ang), sin(ang) ) * _radius because vector2Dd would give (0,0) |
mbedalvaro | 0:df6fdd9b99f0 | 19 | ang+=angInc; |
mbedalvaro | 0:df6fdd9b99f0 | 20 | } |
mbedalvaro | 0:df6fdd9b99f0 | 21 | } |
mbedalvaro | 0:df6fdd9b99f0 | 22 | |
mbedalvaro | 0:df6fdd9b99f0 | 23 | // Modifying the scafold (resizing, rotating): |
mbedalvaro | 0:df6fdd9b99f0 | 24 | // Note: in case of elastic loop, the mass-loop may be reinitialized or not (if the rigid loop is used as "attractor" only): |
mbedalvaro | 0:df6fdd9b99f0 | 25 | |
mbedalvaro | 0:df6fdd9b99f0 | 26 | void RigidScafold::resizeDimensionScafold(float _newSize) { |
mbedalvaro | 0:df6fdd9b99f0 | 27 | resizeFactorDimensionScafold(_newSize/sizeScafold); |
mbedalvaro | 0:df6fdd9b99f0 | 28 | sizeScafold=_newSize; |
mbedalvaro | 0:df6fdd9b99f0 | 29 | } |
mbedalvaro | 0:df6fdd9b99f0 | 30 | |
mbedalvaro | 0:df6fdd9b99f0 | 31 | void RigidScafold::resizeFactorDimensionScafold(float _factor) { |
mbedalvaro | 0:df6fdd9b99f0 | 32 | for (int i = 0; i < scafold.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 33 | scafold[i] = ( scafold[i]-centerScafold)*_factor+centerScafold; |
mbedalvaro | 0:df6fdd9b99f0 | 34 | } |
mbedalvaro | 0:df6fdd9b99f0 | 35 | sizeScafold*=_factor; |
mbedalvaro | 0:df6fdd9b99f0 | 36 | } |
mbedalvaro | 0:df6fdd9b99f0 | 37 | |
mbedalvaro | 0:df6fdd9b99f0 | 38 | void RigidScafold::rotateScafold(float alphadeg) { |
mbedalvaro | 0:df6fdd9b99f0 | 39 | // note: rotate around the centerScafold: |
mbedalvaro | 0:df6fdd9b99f0 | 40 | for (int i = 0; i < scafold.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 41 | scafold[i]=(scafold[i]-centerScafold).getRotatedRad(alphadeg)+centerScafold; |
mbedalvaro | 0:df6fdd9b99f0 | 42 | } |
mbedalvaro | 0:df6fdd9b99f0 | 43 | } |
mbedalvaro | 0:df6fdd9b99f0 | 44 | |
mbedalvaro | 0:df6fdd9b99f0 | 45 | void RigidScafold::buildLine(float _length, float _angleDeg, vector2Dd _pos, int _numScafoldPoints) { |
mbedalvaro | 0:df6fdd9b99f0 | 46 | scafold.resize(_numScafoldPoints); |
mbedalvaro | 0:df6fdd9b99f0 | 47 | vector2Dd auxStep = vector2Dd(_length * cos(_angleDeg/180.0 * PI)/_numScafoldPoints, sin(_length * _angleDeg/180.0 * PI)/_numScafoldPoints ) ; |
mbedalvaro | 0:df6fdd9b99f0 | 48 | for (int i = 0; i < scafold.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 49 | scafold[i]= auxStep * i + _pos; |
mbedalvaro | 0:df6fdd9b99f0 | 50 | } |
mbedalvaro | 0:df6fdd9b99f0 | 51 | } |
mbedalvaro | 0:df6fdd9b99f0 | 52 | |
mbedalvaro | 0:df6fdd9b99f0 | 53 | // Other functions to create letters, text, etc. |
mbedalvaro | 0:df6fdd9b99f0 | 54 | // ... TO DO .... |
mbedalvaro | 0:df6fdd9b99f0 | 55 | |
mbedalvaro | 0:df6fdd9b99f0 | 56 |