annotate src/rovascope/drawing.c @ 608:621e6ec66973 trunk

[svn] Obliterate empty tags, just like in mpg123.
author chainsaw
date Sun, 04 Feb 2007 13:40:53 -0800
parents 290588854a9d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
1 #include <math.h>
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
2
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
3 #include "paranormal.h"
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
4 #include "actuators.h"
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
5 #include "pn_utils.h"
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
6
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
7 extern SDL_Surface *screen;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
8
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
9 void
304
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
10 pn_draw_dot (guint x, guint y, guchar value)
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
11 {
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
12 if (x > pn_image_data->width || x < 0 || y > pn_image_data->height || y < 0)
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
13 return;
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
14
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
15 pn_image_data->surface[0][PN_IMG_INDEX(x, y)] = value;
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
16 }
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
17
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
18 void
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
19 pn_draw_line (guint _x0, guint _y0, guint _x1, guint _y1, guchar value)
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
20 {
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
21 gint x0 = _x0;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
22 gint y0 = _y0;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
23 gint x1 = _x1;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
24 gint y1 = _y1;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
25
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
26 gint dx = x1 - x0;
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
27 gint dy = y1 - y0;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
28
304
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
29 pn_draw_dot(x0, y0, value);
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
30
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
31 if (dx != 0)
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
32 {
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
33 gfloat m = (gfloat) dy / (gfloat) dx;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
34 gfloat b = y0 - m * x0;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
35
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
36 dx = (x1 > x0) ? 1 : - 1;
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
37 while (x0 != x1)
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
38 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
39 x0 += dx;
268
a1be19f8de1f [svn] - calculate FPS for frame limiter
nenolod
parents: 193
diff changeset
40 y0 = m * x0 + b;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
41
304
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 298
diff changeset
42 pn_draw_dot(x0, y0, value);
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
43 }
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
44 }
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
45 }