//-------------------------------------------------------------- void testApp::draw(){ // world A boundsA.inside(ofGetMouseX(), ofGetMouseY()) ? ofSetColor(80) : ofSetColor(100); ofFill(); ofRect(boundsA); // world A boundsB.inside(ofGetMouseX(), ofGetMouseY()) ? ofSetColor(180) : ofSetColor(200); ofFill(); ofRect(boundsB); ofFill(); // A World Circles for (int i=0; i<circlesA.size(); i++) { ofSetHexColor(0xBFE364); circlesA[i].draw(); } // B World Circles for (int i=0; i<circlesB.size(); i++) { ofSetHexColor(0xE83AAB); circlesB[i].draw(); } // Shared Rects for (int i=0; i<sharedRects.size(); i++) { ofSetHexColor(0x2F9BA1); ofFill(); sharedRects[i].draw(); } ofSetColor(255); ofDrawBitmapString("World A\nGravity "+ofToString(box2dA.getGravity().x, 1)+","+ofToString(box2dA.getGravity().y, 1), 250, ofGetHeight()/2); ofSetColor(90); ofDrawBitmapString("World B\nGravity "+ofToString(box2dB.getGravity().x, 1)+","+ofToString(box2dB.getGravity().y, 1), 750, ofGetHeight()/2); ofPoint centerA(250, 250); ofPoint centerB(750, 250); ofSetColor(255); drawGravity(centerA, box2dA.getGravity()); drawGravity(centerB, box2dB.getGravity()); }
Vector2 Rect::IntersectionDepth(Rect r) { Vector2 retVector; int halfWidth = w/2; int halfHeight = h/2; int halfWidthR = r.w/2; int halfHeightR = r.h/2; Vector2 centerA(x + halfWidth,y + halfHeight); Vector2 centerB(r.x + halfWidthR, r.y + halfHeightR); int distX = centerA.x - centerB.x; int distY = centerA.y - centerB.y; int minDistX = halfWidth + halfWidthR; int minDistY = halfHeight + halfHeightR; if(abs(distX) >= minDistX || abs(distY) >= minDistY) { return retVector; } retVector.x = distX > 0 ? minDistX - distX : -minDistX - distX; retVector.y = distY > 0 ? minDistY - distY : -minDistY - distY; return retVector; }