void Character::checkCollision() { isGrounded=false; for (Rect* g: *grounds) { if (g->getMidX() - draw_Sprite->getPositionX()<1500 && g->getMidY() - draw_Sprite->getPositionY()<1500 ) { checkGround(g); checkTop(g); checkSide(true,g); checkSide(false,g); } } if (collidingWith==nullptr){ } else if (rCollider.intersectsRect(*collidingWith)){ } else if (lCollider.intersectsRect(*collidingWith)){ } else { collidingWith==nullptr; } }
/* * Checks if a (mergeable) op can be merged into this batch * * If true, the op's multiDraw must be guaranteed to handle both ops simultaneously, so it is * important to consider all paint attributes used in the draw calls in deciding both a) if an * op tries to merge at all, and b) if the op can merge with another set of ops * * False positives can lead to information from the paints of subsequent merged operations being * dropped, so we make simplifying qualifications on the ops that can merge, per op type. */ bool canMergeWith(BakedOpState* op) const { bool isTextBatch = getBatchId() == OpBatchType::Text || getBatchId() == OpBatchType::ColorText; // Overlapping other operations is only allowed for text without shadow. For other ops, // multiDraw isn't guaranteed to overdraw correctly if (!isTextBatch || PaintUtils::hasTextShadow(op->op->paint)) { if (intersects(op->computedState.clippedBounds)) return false; } const BakedOpState* lhs = op; const BakedOpState* rhs = mOps[0]; if (!MathUtils::areEqual(lhs->alpha, rhs->alpha)) return false; // Identical round rect clip state means both ops will clip in the same way, or not at all. // As the state objects are const, we can compare their pointers to determine mergeability if (lhs->roundRectClipState != rhs->roundRectClipState) return false; // Local masks prevent merge, since they're potentially in different coordinate spaces if (lhs->computedState.localProjectionPathMask || rhs->computedState.localProjectionPathMask) return false; /* Clipping compatibility check * * Exploits the fact that if a op or batch is clipped on a side, its bounds will equal its * clip for that side. */ const int currentFlags = mClipSideFlags; const int newFlags = op->computedState.clipSideFlags; if (currentFlags != OpClipSideFlags::None || newFlags != OpClipSideFlags::None) { const Rect& opBounds = op->computedState.clippedBounds; float boundsDelta = mBounds.left - opBounds.left; if (!checkSide(currentFlags, newFlags, OpClipSideFlags::Left, boundsDelta)) return false; boundsDelta = mBounds.top - opBounds.top; if (!checkSide(currentFlags, newFlags, OpClipSideFlags::Top, boundsDelta)) return false; // right and bottom delta calculation reversed to account for direction boundsDelta = opBounds.right - mBounds.right; if (!checkSide(currentFlags, newFlags, OpClipSideFlags::Right, boundsDelta)) return false; boundsDelta = opBounds.bottom - mBounds.bottom; if (!checkSide(currentFlags, newFlags, OpClipSideFlags::Bottom, boundsDelta)) return false; } const SkPaint* newPaint = op->op->paint; const SkPaint* oldPaint = mOps[0]->op->paint; if (newPaint == oldPaint) { // if paints are equal, then modifiers + paint attribs don't need to be compared return true; } else if (newPaint && !oldPaint) { return paintIsDefault(*newPaint); } else if (!newPaint && oldPaint) { return paintIsDefault(*oldPaint); } return paintsAreEquivalent(*newPaint, *oldPaint); }
bool Poly::hit(const Poly& p, float t) const { for(int i=0 ; i<3 ; i++) { const auto& p0 = point[i]; for(int j=0 ; j<3 ; j++) { const auto& p1 = p.point[j]; Line line(p0, (p1-p0).normalization()); auto res0 = checkSide(line, t), res1 = p.checkSide(line, t); if(res0 != res1 && res0 != LineDivision::Bridge && res1 != LineDivision::Bridge) return false; } } return true; }
int main () { initSocket(); sleep(3); encodersReset(); double toFront = 0; dist toBack = {0,0}, toSide = {0,0}, scale = {1,1}; volts speed = {30,30}; // This is a new cycle, first check and then move while(1) { if (req.setWallAuto) { if (r.s.wall == LEFT) req.considerSide = LEFT; else if (r.s.wall == RIGHT) req.considerSide = RIGHT; else req.considerSide = 0; req.setWallAuto = false; } if (req.checkSideStatic == true) { toSide = checkSideStatic(ACCURATE); printf("toSide %lF %lF ", toSide.l, toSide.r); req.checkSideStatic == false; } if (req.checkFrontStatic == true) { toFront = checkFrontStatic(ACCURATE); printf("toFront2 %lF ", toFront); req.checkFrontStatic = false; } if (req.checkFront == true) { toFront = checkFront(ACCURATE); printf("toFront %lF ", toFront); req.checkFront = false; } if (req.checkSide == true) { toSide = checkSide(ACCURATE, 0, 0); printf("toSide %lF %lF ", toSide.l, toSide.r); req.checkSide == false; } if (req.checkBack == true) { toBack = checkBack(ACCURATE); printf("toBack %lF %lF ", toBack.l, toBack.r); req.checkBack = false; } if (req.checkEncoders == true) { encodersGet(&r.s); printf("encoders %i %i\n", r.s.encodersL, r.s.encodersR);} /**/printf("frontRisk %d frontLRisk %d frontLRisk %d sideLRisk %d sideRRisk %d backLRisk %d backRRisk %d wall %d\n", frontRisk, frontLRisk, frontLRisk, sideLRisk, sideRRisk, backLRisk, backRRisk, r.s.wall);/**/ if (req.rotate180 == true) { if (frontRisk && sideLRisk && sideRRisk) { reposition(&r.s, 400, 400, 10, -10); req = DEFAULT_REQUEST; continue; } } if (req.calculateBack == true) { // In case of no risk if (!frontLRisk && !frontRRisk && !sideLRisk && !sideRRisk && !backLRisk && !backRRisk) { // Case 1: No risks. No wall. Go straight if (r.s.wall == 0) { backVal = (dist) {0,0}; /**/printf("No risks. No wall. Go straight\n"); }/**/ // Case 2: No risks. Left wall. Touching back. We are in a deep corner. Turn else if (r.s.wall == LEFT && sideLFar && !backLisInfinite) { /**/printf("No risks. Left wall. Touching back. Turn\n");/**/ backConsidered = toBack.l; backDif = 0 - backConsidered; if (backConsidered < 38 && backConsidered >= 25) {backVal = (dist) {-15,-15};} // Too far else if (backConsidered < 25 && backConsidered >= 18) {backVal = (dist) {backDif/1.5,backDif/1.5};} // Far else if (backConsidered < 18 && backConsidered >= 8) {backVal = (dist) {backDif/1.5,backDif/1.5};} // In range // Case 3: No risks. Left wall. Touching back. We are in a deep corner. Turn } else if (r.s.wall == RIGHT && sideLInfinite && !backLisInfinite) {/**/printf("No Risks. Right Wall is being followed %i.\n", r.s.wall);/**/ backConsidered = toBack.r; backDif = 0 - backConsidered; if (backConsidered < 38 && backConsidered >= 25) {backVal = (dist) {+15,+15};} // Too far else if (backConsidered < 25 && backConsidered >= 18) {backVal = (dist) {-backDif/1.5,-backDif/1.5};} // Far else if (backConsidered < 18 && backConsidered >= 8) {backVal = (dist) {-backDif/1.5,-backDif/1.5};} // In range } // Default else {backVal = (dist){999, 999};} // Risks, skip } else { /**/printf("Risks, skip.\n");/**/ backVal = (dist){999, 999}; } printf("backVal %lF %lF\n", backVal.l, backVal.r);// TODO check the other side tooooooo! req.calculateBack = false; } // might be used for scale in tunnels to moderate velocity if (req.calculateSide == true) { if (r.s.wall == LEFT) { sideConsidered = toSide.l; sideDif = 27 - sideConsidered; /*/printf("sideDif %i\n", sideDif);/**/ if (sideConsidered < 100 && sideConsidered >= 60) { sideVal = (dist) {sideDif, sideDif};} // Too far else if (sideConsidered < 60 && sideConsidered >= 30) { sideVal = (dist) {sideDif, sideDif};} // Far else if (sideConsidered < 30 && sideConsidered >= 21) { sideVal = (dist) {0, 0};} // In range else if (sideConsidered < 21) { sideVal = (dist) {sideDif, sideDif};} // Close } else { sideConsidered = toSide.r; sideDif = 27 - sideConsidered; /*/printf("sideDif %i\n", sideDif);/**/ if (sideConsidered < 100 && sideConsidered >= 60) { sideVal = (dist) {-sideDif, -sideDif};} // Too far else if (sideConsidered < 60 && sideConsidered >= 30) { sideVal = (dist) {-sideDif, -sideDif};} // Far else if (sideConsidered < 30 && sideConsidered >= 21) { sideVal = (dist) {0, 0};} // In range else if (sideConsidered < 21) { sideVal = (dist) {-sideDif, -sideDif};} // Close } /**/printf("sideVal %lF %lF\n", sideVal.l, sideVal.r);/**/ // TODO check the other side tooooooo! req.calculateSide = false; } // might be used for scale in tunnels to moderate velocity if (req.calculateFront == true) { frontConsidered = toFront; frontDif = frontOk - frontConsidered; /*/printf("frontDif %i\n", frontDif);/**/ frontVal = frontDif; if (-frontRange <= frontDif && frontDif <= frontRange) { frontVal = 0; /*/printf("front in Range\n");/**/ } if (frontVal <= -frontMinimum) { } /*/printf("frontVal %i\n", frontVal);/**/ // TODO check the other side tooooooo! req.calculateFront = false; } // Calculate scale // Check for risk // - recalculate speed if (frontVal != 999) speed = (volts){frontVal,-frontVal}; if (sideVal.l != 999 && sideVal.r != 999) speed = (volts){sideVal.l,-sideVal.r}; if (backVal.l != 999 && backVal.r != 999) speed = (volts){backVal.l,-backVal.r}; // Assign voltage r.v = setVoltage(speed, scale); // Finally arrived here moveAtVoltage(r.v.l, r.v.r); printf("* Speed chosen: %i %i\n\n", r.v.l, r.v.r ); req = DEFAULT_REQUEST; } return 0; }