Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SDL_Point rotatePoint(const SDL_Point & origin, const SDL_Point & point, const float & s, const float & c){
- float xDif = point.x - origin.x;
- float yDif = point.y - origin.y;
- float x3 = c * xDif + (-s * yDif) + origin.x;
- float y3 = s * xDif + c * yDif + origin.y;
- return {(int)x3, (int)y3};
- }
- bool pointOnSideOfEdge(const SDL_Point &A,const SDL_Point &B,const SDL_Point &test){
- int a = -(B.y - A.y);
- int b = B.x - A.x;
- int c = -(a * A.x + b * A.y);
- int d = a * test.x + b * test.y + c;
- return d > 0;
- }
- bool pointInRotatedRect(const SDL_Point & M, const SDL_Rect & R, const float & angle){
- SDL_SetRenderDrawColor(gRenderer, 0xFF, 0, 0, 0xFF);
- //SDL_RenderFillRect(gRenderer, &overLapRect);
- float inRad = degreeToRadian(angle);
- float cosineOfAngle = std::cos(inRad);
- float sineOfAngle = std::sin(inRad);
- SDL_Point center = { R.x + R.w / 2, R.y + R.h / 2 };
- SDL_Point A = rotatePoint(center, { R.x, R.y }, sineOfAngle, cosineOfAngle);
- SDL_Point B = rotatePoint(center, { R.x + R.w, R.y }, sineOfAngle, cosineOfAngle);
- SDL_Point C = rotatePoint(center, { R.x + R.w, R.y + R.h }, sineOfAngle, cosineOfAngle);
- SDL_Point D = rotatePoint(center, { R.x, R.y + R.h }, sineOfAngle, cosineOfAngle);
- return pointOnSideOfEdge(A, B, M) && pointOnSideOfEdge(B, C, M) && pointOnSideOfEdge(C, D, M) && pointOnSideOfEdge(D, A, M);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement