-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpring.cpp
More file actions
47 lines (37 loc) · 1.08 KB
/
Spring.cpp
File metadata and controls
47 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Spring.cpp
* openFrameworks
*
* Created by Joshua Walton on 12/11/08.
* Copyright 2008 Lab at Rockwell Group. All rights reserved.
*
*/
#include "Spring.h"
//---------------------------------------------------------------------
Spring::Spring(){
particleA = NULL;
particleB = NULL;
}
//---------------------------------------------------------------------
void Spring::update(){
if ((particleA == NULL) || (particleB == NULL)){
return;
}
ofxVec3f pta = particleA->pos;
ofxVec3f ptb = particleB->pos;
float theirDistance = (pta - ptb).length();
float springForce = (springiness * (distance - theirDistance));
ofxVec3f frcToAdd = (pta-ptb).normalized() * springForce;
particleA->addForce(frcToAdd);
particleB->addForce(-frcToAdd);
}
//---------------------------------------------------------------------
void Spring::draw(){
if ((particleA == NULL) || (particleB == NULL)){
return;
}
//ofEnableAlphaBlending();
ofSetColor(255, 255, 255, 10);
ofLine(particleA->pos.x, particleA->pos.y, particleB->pos.x, particleB->pos.y);
//ofDisableAlphaBlending();
}