![](/media/cache/profiles/68a15b5278e4f7c4c056df9d5f1d3b1f.jpg.50x50_q85.jpg)
save loops
classSpring.cpp@0:df6fdd9b99f0, 2014-12-02 (annotated)
- Committer:
- mbedalvaro
- Date:
- Tue Dec 02 04:39:15 2014 +0000
- Revision:
- 0:df6fdd9b99f0
this new version of skinGames will have a function that stops scanning as the laser reaches the same position (i.e., loops) with a certain precision. It is for extracting contours for Takashita project. It can then save on a file or send on osc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:df6fdd9b99f0 | 1 | #include "classSpring.h" |
mbedalvaro | 0:df6fdd9b99f0 | 2 | #include "myVectorClass.h" |
mbedalvaro | 0:df6fdd9b99f0 | 3 | |
mbedalvaro | 0:df6fdd9b99f0 | 4 | //--------------------------------------------------------------------- |
mbedalvaro | 0:df6fdd9b99f0 | 5 | spring::spring(){ |
mbedalvaro | 0:df6fdd9b99f0 | 6 | massA = NULL; |
mbedalvaro | 0:df6fdd9b99f0 | 7 | massB = NULL; |
mbedalvaro | 0:df6fdd9b99f0 | 8 | } |
mbedalvaro | 0:df6fdd9b99f0 | 9 | |
mbedalvaro | 0:df6fdd9b99f0 | 10 | //--------------------------------------------------------------------- |
mbedalvaro | 0:df6fdd9b99f0 | 11 | void spring::update(){ |
mbedalvaro | 0:df6fdd9b99f0 | 12 | if ((massA == NULL) || (massB == NULL)){ |
mbedalvaro | 0:df6fdd9b99f0 | 13 | return; |
mbedalvaro | 0:df6fdd9b99f0 | 14 | } |
mbedalvaro | 0:df6fdd9b99f0 | 15 | |
mbedalvaro | 0:df6fdd9b99f0 | 16 | vector2Df pta = massA->pos; |
mbedalvaro | 0:df6fdd9b99f0 | 17 | vector2Df ptb = massB->pos; |
mbedalvaro | 0:df6fdd9b99f0 | 18 | |
mbedalvaro | 0:df6fdd9b99f0 | 19 | float theirDistance = (pta - ptb).length(); |
mbedalvaro | 0:df6fdd9b99f0 | 20 | float springForce = (springiness * (distance - theirDistance)); |
mbedalvaro | 0:df6fdd9b99f0 | 21 | vector2Df frcToAdd = (pta-ptb).normalize() * springForce; |
mbedalvaro | 0:df6fdd9b99f0 | 22 | |
mbedalvaro | 0:df6fdd9b99f0 | 23 | massA->addForce(frcToAdd); |
mbedalvaro | 0:df6fdd9b99f0 | 24 | massB->addForce(-frcToAdd); |
mbedalvaro | 0:df6fdd9b99f0 | 25 | //massA->totalForce.x+=frcToAdd.x;massA->totalForce.y+=frcToAdd.y; |
mbedalvaro | 0:df6fdd9b99f0 | 26 | //massB->totalForce.x-=frcToAdd.x;massB->totalForce.y-=frcToAdd.y; |
mbedalvaro | 0:df6fdd9b99f0 | 27 | } |
mbedalvaro | 0:df6fdd9b99f0 | 28 | |
mbedalvaro | 0:df6fdd9b99f0 | 29 | void spring::assymetricUpdate(){ // only second mass suffers a force |
mbedalvaro | 0:df6fdd9b99f0 | 30 | if ((massA == NULL) || (massB == NULL)){ |
mbedalvaro | 0:df6fdd9b99f0 | 31 | return; |
mbedalvaro | 0:df6fdd9b99f0 | 32 | } |
mbedalvaro | 0:df6fdd9b99f0 | 33 | |
mbedalvaro | 0:df6fdd9b99f0 | 34 | vector2Df pta = massA->pos; |
mbedalvaro | 0:df6fdd9b99f0 | 35 | vector2Df ptb = massB->pos; |
mbedalvaro | 0:df6fdd9b99f0 | 36 | |
mbedalvaro | 0:df6fdd9b99f0 | 37 | float theirDistance = (pta - ptb).length(); |
mbedalvaro | 0:df6fdd9b99f0 | 38 | float springForce = (springiness * (distance - theirDistance)); |
mbedalvaro | 0:df6fdd9b99f0 | 39 | vector2Df frcToAdd = (pta-ptb).normalize() * springForce; |
mbedalvaro | 0:df6fdd9b99f0 | 40 | |
mbedalvaro | 0:df6fdd9b99f0 | 41 | //massA->addForce(frcToAdd); |
mbedalvaro | 0:df6fdd9b99f0 | 42 | massB->addForce(-frcToAdd); |
mbedalvaro | 0:df6fdd9b99f0 | 43 | //massA->totalForce.x+=frcToAdd.x;massA->totalForce.y+=frcToAdd.y; |
mbedalvaro | 0:df6fdd9b99f0 | 44 | //massB->totalForce.x-=frcToAdd.x;massB->totalForce.y-=frcToAdd.y; |
mbedalvaro | 0:df6fdd9b99f0 | 45 | } |