Skip to content
Snippets Groups Projects
Commit ecff83ee authored by siflfran's avatar siflfran
Browse files

Rotation repariert

parent 6620f483
No related branches found
No related tags found
No related merge requests found
......@@ -208,8 +208,8 @@ void draw_sunriset(Window win,
x, y, width, height, 0 * 64, 359 * 64);
return;
}
angle1 = (int) round(start * 15.0);
angle2 = (int) round(end * 15.0);
angle1 = (int) rint(start * 15.0);
angle2 = (int) rint(end * 15.0);
angle2 -= (angle1 + 360) % 360;
angle1 += loc_time->tm_gmtoff * 0.004166667;
if (state.counterclockwise) {
......@@ -383,9 +383,6 @@ void draw_window(Window win)
state.lon, state.lat, civil_pix, SUNRISET_SIZE, CIVIL_TWILIGHT);
draw_sunriset(win, loc_time,
state.lon, state.lat, day_pix, SUNRISET_SIZE, SUNRISESET);
XSetForeground(mainDisplay, mainGC, pix[0]);
/*DrawTriangle(mainDisplay, win, mainGC, center.x, center.y, 300, 300,
loc_time->tm_sec * 6 * 64);*/
}
/* draw filled polygonal hands */
for (i = 2; i >= 0; i--) {
......
......@@ -19,20 +19,21 @@ void RotateCoordinates(short *x, short *y, short center_x, short center_y,
void RotateCoordinates(short *x, short *y, short center_x, short center_y,
short angle)
{
double r_angle = (angle / 64) % 360 * (M_PI / 180.0);
int x_coord = x[0], y_coord = y[0];
x[0] = center_x + cos(r_angle) * (x_coord - center_x)
- sin(r_angle) * (y_coord - center_y);
y[0] = center_y + sin(r_angle) * (x_coord - center_x)
- cos(r_angle) * (y_coord - center_y);
printf("x = %d, y = %d\n", x_coord, y_coord);
double r_angle;
short x_coord, y_coord;
r_angle = (angle / 64) * (M_PI / 180.0);
x_coord = x[0] - center_x;
y_coord = y[0] - center_y;
x[0] = center_x + rint(cos(r_angle) * x_coord + sin(r_angle) * y_coord);
y[0] = center_y + rint(-sin(r_angle) * x_coord + cos(r_angle) * y_coord);
}
void CalculateTriangleCoordinates(XPoint *points, short x, short y,
unsigned short width, unsigned short height, short angle)
{
points[0].x = x - width / 2;
points[0].x = x - (width / 2);
points[0].y = y;
points[1].x = x + width / 2;
points[1].x = x + (width / 2);
points[1].y = y;
points[2].x = x;
points[2].y = y + height;
......@@ -41,10 +42,11 @@ void CalculateTriangleCoordinates(XPoint *points, short x, short y,
{
int i;
for (i = 0; i < 4; i++) {
RotateCoordinates(&points[i].x, &points[i].y, x, y, angle);
RotateCoordinates(&(points[i].x), &(points[i].y), x, y, angle);
}
}
}
int DrawTriangle(Display *display, Drawable d, GC gc,
short x, short y, unsigned short width, unsigned short height,
short angle)
......@@ -53,6 +55,7 @@ int DrawTriangle(Display *display, Drawable d, GC gc,
CalculateTriangleCoordinates(points, x, y, width, height, angle);
return XDrawLines(display, d, gc, points, 4, CoordModeOrigin);
}
int FillTriangle(Display *display, Drawable d, GC gc,
short x, short y, unsigned short width, unsigned short height,
short angle)
......
......@@ -2,6 +2,10 @@
* This software is distributed under GPL. For details see LICENSE file.
*/
#include <X11/Xlib.h>
void RotateCoordinates(short *x, short *y, short center_x, short center_y,
short angle);
int DrawTriangle(Display *display, Drawable d, GC gc,
short x, short y, unsigned short width, unsigned short height,
short angle);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment