/
ofxPhysicalOfPoint.cpp
executable file
·113 lines (75 loc) · 2.11 KB
/
ofxPhysicalOfPoint.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// ofxPhysicalOfPoint.cpp
// ofxPhysical
//
// Created by jvelazqueztraut on 06/05/13.
//
// masOTROS SRL
#include "ofxPhysicalOfPoint.h"
ofxPhysicalOfPoint::ofxPhysicalOfPoint(){
ofxPhysical::setup(); //defaults to (0,0,0) >> (0,0,0)
}
void ofxPhysicalOfPoint::update(float dt){
ofxPhysical::update( dt );
}
void ofxPhysicalOfPoint::draw(){
ofPushMatrix();
ofPoint p = getCurrentPosition();
ofTranslate(p.x, p.y, p.z);
float s = 10.0f;
ofRect( -s * 0.5f, -s * 0.5f, s, s );
ofPopMatrix();
}
void ofxPhysicalOfPoint::setPosition( ofPoint newPos ){
ofxPhysical::reset();
originalPoint_ = newPos;
targetPoint_ = newPos;
}
void ofxPhysicalOfPoint::setPositionX( float newX ){
originalPoint_ = getCurrentPosition();
originalPoint_.x = newX;
targetPoint_ = originalPoint_;
ofxPhysical::reset();
}
void ofxPhysicalOfPoint::setPositionY( float newY ){
originalPoint_ = getCurrentPosition();
originalPoint_.y = newY;
targetPoint_ = originalPoint_;
ofxPhysical::reset();
}
void ofxPhysicalOfPoint::setPositionZ( float newZ ){
originalPoint_ = getCurrentPosition();
originalPoint_.z = newZ;
targetPoint_ = originalPoint_;
ofxPhysical::reset();
}
void ofxPhysicalOfPoint::reset(){
ofxPhysical::reset();
targetPoint_ = originalPoint_;
}
void ofxPhysicalOfPoint::animateTo( ofPoint where ){
originalPoint_ = getCurrentPosition();
targetPoint_ = where;
ofxPhysical::startAnimation();
}
void ofxPhysicalOfPoint::animateToAfterDelay( ofPoint where, float delay ){
if (delay <= 0.0f){
animateTo(where);
}else{
//originalTempPoint_ = getCurrentPosition();
targetTempPoint_ = where;
ofxPhysical::startAnimationAfterDelay(delay);
}
}
void ofxPhysicalOfPoint::animateToIfFinished( ofPoint where ){
if (animating_ == false){
animateTo(where);
}
}
ofPoint ofxPhysicalOfPoint::getCurrentPosition(){
float mappedDistribution = calcCurveAt(percentDone_); ///percentDone_ is [0..1] & tells me where we are between orig and target
return originalPoint_ + ( targetPoint_ - originalPoint_) * mappedDistribution ;
}
void ofxPhysicalOfPoint::startAfterWait(){
animateTo(targetTempPoint_);
}