Skip to content

Instantly share code, notes, and snippets.

@indefinit
Created February 21, 2018 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indefinit/edc5cc81f0d2728579f1650aedf95b81 to your computer and use it in GitHub Desktop.
Save indefinit/edc5cc81f0d2728579f1650aedf95b81 to your computer and use it in GitHub Desktop.
Example of a custom cpp class Ball with boolean methods
#include "ofApp.h" //include ofApp so you can use OF defined functions and vars
class Ball {
public:
Ball();//constructor
~Ball();//destructor
//current ball position, you'll need to initialize
//this somewhere in your constructor or another method
ofVec2f mBallPos;
bool checkIntersects(const ofVec2f &positionToCheck);
}
//implementation of your Ball methods
bool Ball::checkPosition(const ofVec2f &positionToCheck){
if(ofDist(positionToCheck.x, positionToCheck.y, mBallPos.x, mBallPos.y) < 5.0f){
return true;
}
return false;
}
//somewhere in ofApp.cpp
if (ball.checkPosition(ofVec2f(45.0f,23.0f))){
//set your ofApp public variable to true here
}
else {
//set your ofApp public variable to false here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment