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, ...@@ -208,8 +208,8 @@ void draw_sunriset(Window win,
x, y, width, height, 0 * 64, 359 * 64); x, y, width, height, 0 * 64, 359 * 64);
return; return;
} }
angle1 = (int) round(start * 15.0); angle1 = (int) rint(start * 15.0);
angle2 = (int) round(end * 15.0); angle2 = (int) rint(end * 15.0);
angle2 -= (angle1 + 360) % 360; angle2 -= (angle1 + 360) % 360;
angle1 += loc_time->tm_gmtoff * 0.004166667; angle1 += loc_time->tm_gmtoff * 0.004166667;
if (state.counterclockwise) { if (state.counterclockwise) {
...@@ -383,9 +383,6 @@ void draw_window(Window win) ...@@ -383,9 +383,6 @@ void draw_window(Window win)
state.lon, state.lat, civil_pix, SUNRISET_SIZE, CIVIL_TWILIGHT); state.lon, state.lat, civil_pix, SUNRISET_SIZE, CIVIL_TWILIGHT);
draw_sunriset(win, loc_time, draw_sunriset(win, loc_time,
state.lon, state.lat, day_pix, SUNRISET_SIZE, SUNRISESET); 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 */ /* draw filled polygonal hands */
for (i = 2; i >= 0; i--) { for (i = 2; i >= 0; i--) {
......
...@@ -19,20 +19,21 @@ void RotateCoordinates(short *x, short *y, short center_x, short center_y, ...@@ -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, void RotateCoordinates(short *x, short *y, short center_x, short center_y,
short angle) short angle)
{ {
double r_angle = (angle / 64) % 360 * (M_PI / 180.0); double r_angle;
int x_coord = x[0], y_coord = y[0]; short x_coord, y_coord;
x[0] = center_x + cos(r_angle) * (x_coord - center_x)
- sin(r_angle) * (y_coord - center_y); r_angle = (angle / 64) * (M_PI / 180.0);
y[0] = center_y + sin(r_angle) * (x_coord - center_x) x_coord = x[0] - center_x;
- cos(r_angle) * (y_coord - center_y); y_coord = y[0] - center_y;
printf("x = %d, y = %d\n", x_coord, y_coord); 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, void CalculateTriangleCoordinates(XPoint *points, short x, short y,
unsigned short width, unsigned short height, short angle) 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[0].y = y;
points[1].x = x + width / 2; points[1].x = x + (width / 2);
points[1].y = y; points[1].y = y;
points[2].x = x; points[2].x = x;
points[2].y = y + height; points[2].y = y + height;
...@@ -41,10 +42,11 @@ void CalculateTriangleCoordinates(XPoint *points, short x, short y, ...@@ -41,10 +42,11 @@ void CalculateTriangleCoordinates(XPoint *points, short x, short y,
{ {
int i; int i;
for (i = 0; i < 4; 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, int DrawTriangle(Display *display, Drawable d, GC gc,
short x, short y, unsigned short width, unsigned short height, short x, short y, unsigned short width, unsigned short height,
short angle) short angle)
...@@ -53,6 +55,7 @@ int DrawTriangle(Display *display, Drawable d, GC gc, ...@@ -53,6 +55,7 @@ int DrawTriangle(Display *display, Drawable d, GC gc,
CalculateTriangleCoordinates(points, x, y, width, height, angle); CalculateTriangleCoordinates(points, x, y, width, height, angle);
return XDrawLines(display, d, gc, points, 4, CoordModeOrigin); return XDrawLines(display, d, gc, points, 4, CoordModeOrigin);
} }
int FillTriangle(Display *display, Drawable d, GC gc, int FillTriangle(Display *display, Drawable d, GC gc,
short x, short y, unsigned short width, unsigned short height, short x, short y, unsigned short width, unsigned short height,
short angle) short angle)
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
* This software is distributed under GPL. For details see LICENSE file. * 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, int DrawTriangle(Display *display, Drawable d, GC gc,
short x, short y, unsigned short width, unsigned short height, short x, short y, unsigned short width, unsigned short height,
short angle); 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