Grid Visualization
Angle: 45° | Spacing: 20px
// Rotate a point around a center point
void RotatePoint(double x1, double y1, double x2, double y2, double angleDegrees, double &finalX, double &finalY) {
// Calculate the difference between the points
double angle = angleDegrees * (M_PI / 180.0);
double tempX = x1 - x2;
double tempY = y1 - y2;
// Apply rotation formula
double rotatedX = (tempX * cos(angle)) - (tempY * sin(angle));
double rotatedY = (tempX * sin(angle)) + (tempY * cos(angle));
// Store the result
finalX = rotatedX;
finalY = rotatedY;
}
// Draw multiple parallel lines with rotation
void drawRotatedGrid1(double cX) {
// Loop to draw multiple parallel lines
for (int off = -max(SCREENWIDTH, SCREENHEIGHT); off < max(SCREENWIDTH, SCREENHEIGHT); off += 10) {
// Define UN-ROTATED endpoints
double p1_unrotates_x = 0;
double p1_unrotates_y = cY + off;
double p2_unrotates_x = SCREENWIDTH;
double p2_unrotates_y = cY + off;
// Rotate points
RotatePoint(p1_unrotates_x, p1_unrotates_y, cX, cY, 5, p1_rotated_x, p1_rotated_y);
RotatePoint(p2_unrotates_x, p2_unrotates_y, cX, cY, 5, p2_rotated_x, p2_rotated_y);
// Draw the modified line segment
SDL_RenderDrawLine(renderer, p1_rotated_x, p1_rotated_y, p2_rotated_x, p2_rotated_y);
}
}