How can I do ofGetPreviousMouseX() for ofPoint()

I want to get the position of a ofPoint, the previous frame;

the exact same thing as

but for points

I actually want to track the previous version of an OpenCv Blob

thanks guys


I have no idea if there is some kind of support for getPreviousPoint in OF, but one way around is to make your own class. The example below might work (have not tested it). By creating your own class holding the values of both present and previous points you will have access to both points through the same object.


class PointWithHistory

	void setPoint(ofPoint newPoint);
	ofPoint getPoint();
	ofPoint getPreviousPoint();

	ofPoint point;
	ofPoint previousPoint;



#include "PointWithHistory.h"

void PointWithHistory::setPoint(ofPoint newPoint)
	previousPoint = point;
	point = newPoint;

ofPoint PointWithHistory::getPoint()
	return point;

ofPoint PointWithHistory::getPreviousPoint()
	return previousPoint;


//Variables declared in testApp
ofPoint myOfPoint;
PointWithHistory myExtendedPoint;
ofPoint result;

void update()
	myOfPoint(ofRandom(0, 100), ofRandom(0, 100));

	result = myExtendedPoint.getPoint();	//result from this iteration
	result = myExtendedPoint.getPreviousPoint();	//result from previous iteration


By using set(newPoint) both the new value and the previous value will be set. Make sure to only set the point once per iteration! Keep in mind that getPreviousPoint will return an uninitialized point the first iteration.

1 Like

I’ve been really busy lately
thanks for your reply @Wiklund ,
I’ll try it soon.

I’ve just tried it and it works :smile:
I also understood the way its works, took me a couple of minutes though :stuck_out_tongue:
thanks a lot @Wiklund