For the life of me I can't figure this out. I've read many tutorials and looked at other examples about rotation, and to be honest I'm ready to pull all my hair out. LOL
Can somebody please take a look at this and tell me what I should do to fix it?
I want to draw a star and rotate it on itself by its center.
void drawRotatedStar(buffer &buf, int centerX, int centerY, int radius, double angle, int rgb) {
line line1;
line line2;
line line3;
line line4;
line line5;
double matrix[2][2]; //Matrix of 2 * 2
double radians = angle*(PI/180);
matrix[0][0] = cos(angle);
matrix[1][0] = -sin(angle);
matrix[0][1] = sin(angle);
matrix[1][1] = cos(angle);
int oldX, oldY;
//Create our Stars
line1.x1 = centerX;
line1.y1 = centerY + radius;
line1.x2 = (centerX + sin(4*PI/5) * radius);
line1.y2 = (centerY + cos(4*PI/5) * radius);
line2.x1 = (centerX + sin(4*PI/5) * radius);
line2.y1 = (centerY + cos(4*PI/5) * radius);
line2.x2 = (centerX + sin(8*PI/5) * radius);
line2.y2 = (centerY + cos(8*PI/5) * radius);
line3.x1 = (centerX + sin(8*PI/5) * radius);
line3.y1 = (centerY + cos(8*PI/5) * radius);
line3.x2 = (centerX + sin(2*PI/5) * radius);
line3.y2 = (centerY + cos(2*PI/5) * radius);
line4.x1 = (centerX + sin(2*PI/5) * radius);
line4.y1 = (centerY + cos(2*PI/5) * radius);
line4.x2 = (centerX + sin(6*PI/5) * radius);
line4.y2 = (centerY + cos(6*PI/5) * radius);
line5.x1 = (centerX + sin(6*PI/5) * radius);
line5.y1 = (centerY + cos(6*PI/5) * radius);
line5.x2 = centerX;
line5.y2 = centerY + radius;
//Rotate our stars
oldX = line1.x1;
oldY = line1.y1;
line1.x1 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
line1.y1 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line1.x2;
oldY = line1.y2;
line1.x2 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
line1.y2 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line2.x1;
oldY = line2.y1;
line2.x1 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
line2.y1 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line2.x2;
oldY = line2.y2;
line2.x2 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
line2.y2 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line3.x1;
oldY = line3.y1;
line3.x1 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
line3.y1 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line3.x2;
oldY = line3.y2;
line3.x2 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
line3.y2 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line4.x2;
oldY = line4.y2;
line4.x2 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
line4.y2 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line4.x1;
oldY = line4.y1;
line4.x1 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
line4.y1 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line5.x1;
oldY = line5.y1;
line5.x1 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
line5.y1 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
oldX = line5.x2;
oldY = line5.y2;
line5.x2 = (oldX * matrix[0][0]) + (oldY * matrix[0][1]) + centerX;
line5.y2 = (oldX * matrix[1][0]) + (oldY * matrix[1][1]) + centerY;
//Draw our stars
drawLine(buf, line1.x1, line1.x2, line1.y1, line1.y2, rgb);
drawLine(buf, line2.x1, line2.x2, line2.y1, line2.y2, rgb);
drawLine(buf, line3.x1, line3.x2, line3.y1, line3.y2, rgb);
drawLine(buf, line4.x1, line4.x2, line4.y1, line4.y2, rgb);
drawLine(buf, line5.x1, line5.x2, line5.y1, line5.y2, rgb);
}
Thanks in advance! I plan on release the sourcecode to this little demo when I'm done.