Created
February 21, 2018 21:40
-
-
Save indefinit/edc5cc81f0d2728579f1650aedf95b81 to your computer and use it in GitHub Desktop.
Example of a custom cpp class Ball with boolean methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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