Hello!
I’m suffering a bit from a month away from programming - I need some help in collision detection between some objects (their y axis value) a ‘cloth’ made from morethanlogics traer library https://github.com/morethanlogic/mtlAddons
I generate a set of scrollevent objects like this:
void testApp::gen_random_events(int n, int tempHipX)
{
hipx = tempHipX;
for(int i=0; i<n; i++)
{
Scrollevent e = Scrollevent();
e.l=3+ofRandom(0, 10);
e.h=5+ofRandom(0, 15);
e.x=ofRandom(0, hipx-(e.l*unitsize));
//e.x=i*unitsize;
e.y=e.h+ofRandom(0, ofGetHeight()-e.h);
std::string st;
std::stringstream outw;
outw << i;
st = outw.str();
e.name=string(st);
e.col.r= ofRandom(0, 255);
e.col.g= ofRandom(0, 255);
e.col.b = ofRandom(0, 255);
e.col.a = 255;
arrEvent[i]=e;
}
}
These are drawn like this:
for(int i=0; i<test; i++)
{
Scrollevent e= arrEvent[i];
e.draw(lpos, unitsize);
}
Elsewhere, I have an instance of a cloth object, and I want to collision detect the cloth hitting the Y values of all the scrollevent objects. I thought this might work:
void handleBoundaryCollisions(Particle* p) {
if (p->getPosition().y == ((testApp*)ofGetAppPtr())->e.y){
//test to set colour and shape
ofSetColor(255, 0, 0);
ofEllipse(100, 100, 30, 30);
p->getVelocity().y *= -.9f;
p->getPosition().set(MIN(MAX(p->getPosition().x, 0), ofGetWidth()), MIN(MAX(p->getPosition().y, 0), ofGetHeight()), 0);
}*/
as a function called from within where the cloth is drawn, but to no avail.
I am getting something fundamentally wrong here, is there enough here for anyone to give me any tips or help?
thanks!
sacculi