static inline int GetCollidingSide2( Rect A,Rect B ){ if (!IsColliding(A,B)) return -1; Point Center1 = A.GetCenter(); Point Center2 = B.GetCenter(); int dir = 0; float angle = Center2.GetDirection(Center1); /* 0 left 1 top 2 right 3 bottom */ angle = Geometry::toDeg(angle); if (angle <= 45 || angle > 315){ dir = 0; }else if(angle > 45 && angle <= 135){ dir = 1; }else if(angle > 135 && angle <= 225){ dir = 2; }else if(angle > 225 && angle <= 315){ dir = 3; } return dir; }
// Essa é uma implementação do SAT feita pelo Lucas Neves. // Recebe dois Rects e suas rotações, e detecta se os retângulos colidem. // Mais informações sobre o método podem ser encontradas nos seguintes links: // http://www.metanetsoftware.com/technique/tutorialA.html // http://www.gamedev.net/page/resources/_/technical/game-programming/2d-rotated-rectangle-collision-r2604 static inline bool IsColliding(Rect& a, Rect& b, float angleOfA, float angleOfB) { if (angleOfA == 0.0f && angleOfB == 0.0f){ return IsColliding(a,b); } Point A[] = { Point( a.x, a.y + a.h ), Point( a.x + a.w, a.y + a.h ), Point( a.x + a.w, a.y ), Point( a.x, a.y ) }; Point B[] = { Point( b.x, b.y + b.h ), Point( b.x + b.w, b.y + b.h ), Point( b.x + b.w, b.y ), Point( b.x, b.y ) }; for (auto& v : A) { v = Rotate(v - a.GetCenter(), angleOfA) + a.GetCenter(); } for (auto& v : B) { v = Rotate(v - b.GetCenter(), angleOfB) + b.GetCenter(); } Point axes[] = { Norm(A[0] - A[1]), Norm(A[1] - A[2]), Norm(B[0] - B[1]), Norm(B[1] - B[2]) }; for (auto& axis : axes) { float P[4]; for (int i = 0; i < 4; ++i) P[i] = Dot(A[i], axis); float minA = *std::min_element(P, P + 4); float maxA = *std::max_element(P, P + 4); for (int i = 0; i < 4; ++i) P[i] = Dot(B[i], axis); float minB = *std::min_element(P, P + 4); float maxB = *std::max_element(P, P + 4); if (maxA <= minB || minA >= maxB) return false; } return true; }
void UIMovieView::SystemDraw(const UIGeometricData &geometricData) { UIControl::SystemDraw(geometricData); #ifdef DRAW_PLACEHOLDER_FOR_STUB_UIMOVIEVIEW Color curDebugDrawColor = GetDebugDrawColor(); RenderManager::Instance()->ClipPush(); Rect absRect = GetRect(true); RenderManager::Instance()->SetColor(Color(1.0f, 0.4f, 0.8f, 1.0f)); RenderHelper::Instance()->DrawRect(absRect, RenderState::RENDERSTATE_2D_BLEND); float32 minRadius = Min(GetSize().x, GetSize().y); RenderHelper::Instance()->DrawCircle(absRect.GetCenter(), minRadius / 2, RenderState::RENDERSTATE_2D_BLEND); RenderHelper::Instance()->DrawCircle(absRect.GetCenter(), minRadius / 3, RenderState::RENDERSTATE_2D_BLEND); RenderHelper::Instance()->DrawCircle(absRect.GetCenter(), minRadius / 4, RenderState::RENDERSTATE_2D_BLEND); RenderManager::Instance()->ClipPop(); SetDebugDrawColor(curDebugDrawColor); #endif }
/** 0 top left 1 top right 2 bottom right 3 bottom left */ static inline int GetCollidingSide( Rect A,Rect B ){ int direction = -1; Point Center1 = A.GetCenter(); Point Center2 = B.GetCenter(); if (Center1.y >= Center2.y){ //Means top if (Center1.x <= Center2.x){ direction = 1; }else{ direction = 0; } }else{ //means Bottom if (Center1.x <= Center2.x){ direction = 3; }else{ direction = 2; } } return direction; }
Vector2 ResultScreen::GetVecInRect(const Rect & rect, float32 angleInRad) { Vector2 retVec; Matrix2 m; m.BuildRotation(angleInRad); angleInRad += DAVA::PI_05; while(angleInRad > DAVA::PI_05) angleInRad -= DAVA::PI_05; if(angleInRad > DAVA::PI_05 / 2) angleInRad = DAVA::PI_05 - angleInRad; Vector2 v = Vector2((Point2f(rect.GetSize().x / 2, 0) * m).data) / Abs(cosf(angleInRad)); retVec = v + rect.GetCenter(); return retVec; }
void Test::PrepareCameraAnimation() { Rect rect = rectSequence.front(); curCameraPosition = GetRealPoint(rect.GetCenter()); Camera* cam = GetCamera(); cam->SetPosition(curCameraPosition); cam->SetDirection(DEF_CAMERA_DIRECTION); nextRectNum = 0; curCameraAngle = 0.f; float32 maxRotateAngle = 360.f; float32 timeToRotate = maxRotateAngle / SettingsManager::Instance()->GetCameraRotationSpeed(); camRotateAnimation = new LinearAnimation<float32>(this, &curCameraAngle, maxRotateAngle, timeToRotate, Interpolation::LINEAR); camRotateAnimation->SetRepeatCount(-1); }
ControlsPositionData BaseAlignHandler::AlignCenter(const List<UIControl*>& controlsList, bool isHorizontal) { ControlsPositionData resultData; for (List<UIControl*>::const_iterator iter = controlsList.begin(); iter != controlsList.end(); iter ++) { UIControl* uiControl = *iter; if (!uiControl) { continue; } resultData.AddControl(uiControl); } // Perform the alignment on the first or last control, depending on the flag. UIControl* referenceControl = GetReferenceControl(controlsList); Vector2 referenceCenter = referenceControl->GetRect(true).GetCenter(); // Second pass - update. for (List<UIControl*>::const_iterator iter = controlsList.begin(); iter != controlsList.end(); iter ++) { UIControl* uiControl = *iter; if (!uiControl) { continue; } Rect absoluteRect = uiControl->GetRect(true); Vector2 currentCenter = absoluteRect.GetCenter(); if (isHorizontal) { absoluteRect.x -= (currentCenter.x - referenceCenter.x); } else { absoluteRect.y -= (currentCenter.y - referenceCenter.y); } uiControl->SetRect(absoluteRect, true); } return resultData; }
void ResultScreen::DrawStatImage(Rect rect) { RenderHelper *helper = RenderHelper::Instance(); RenderManager *manager = RenderManager::Instance(); for(uint32 i = 0; i < testData.GetItemCount(); ++i) { FpsStatItem item = testData.GetItem(i); Rect curRect = testData.TranslateRect(item.rect, rect); for(uint32 j = 0; j < SECTORS_COUNT; j++) { manager->SetColor(SettingsManager::Instance()->GetColorByFps(item.avFps[j])); Polygon2 curSector; curSector.AddPoint(curRect.GetCenter()); curSector.AddPoint(GetVecInRect(curRect, DegToRad((SECTORS_COUNT - j) * 45.f - 22.5f))); curSector.AddPoint(GetVecInRect(curRect, DegToRad((SECTORS_COUNT - j) * 45.f))); curSector.AddPoint(GetVecInRect(curRect, DegToRad((SECTORS_COUNT - j) * 45.f + 22.5f))); helper->FillPolygon(curSector); manager->SetColor(Color::Black()); helper->DrawPolygon(curSector, true); } } }
void Test::MoveToNextPoint() { ++nextRectNum; if(nextRectNum < rectSequence.size()) { Rect nextRect = rectSequence[nextRectNum]; Vector3 endPoint = GetRealPoint(nextRect.GetCenter()); float32 pathSegmentLength = (endPoint - curCameraPosition).Length(); float32 timeToMove = pathSegmentLength / SettingsManager::Instance()->GetCameraMovementSpeed(); camMoveAnimation = new LinearAnimation<Vector3>(this, &curCameraPosition, endPoint, timeToMove, Interpolation::LINEAR); camMoveAnimation->AddEvent(Animation::EVENT_ANIMATION_END, Message(this, &Test::AnimationFinished)); if(!skipFrames) camMoveAnimation->Start(CAMERA_ANIMATION_MOVE); } else { SaveFpsStat(); isFinished = true; } }