annotate src/paranormal/drawing.c @ 1420:40136e537bd9

wav: update to new tuple API.
author William Pitcock <nenolod@atheme-project.org>
date Fri, 10 Aug 2007 06:23:10 -0500
parents 8aab955fb114
children 3b034150d31e
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 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
8 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
9 {
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 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
11 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
12
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 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
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
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 void
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
17 pn_draw_line (guint _x0, guint _y0, guint _x1, guint _y1, guchar value)
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
18 {
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
19 gint x0 = _x0;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
20 gint y0 = _y0;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
21 gint x1 = _x1;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
22 gint y1 = _y1;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
23
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
24 gint dx = x1 - x0;
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
25 gint dy = y1 - y0;
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
26
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
27 pn_draw_dot(x0, y0, value);
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
28
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
29 if (dx != 0)
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
30 {
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
31 gfloat m = (gfloat) dy / (gfloat) dx;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
32 gfloat b = y0 - m * x0;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
33
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
34 dx = (x1 > x0) ? 1 : - 1;
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
35 while (x0 != x1)
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
36 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
37 x0 += dx;
268
a1be19f8de1f [svn] - calculate FPS for frame limiter
nenolod
parents: 193
diff changeset
38 y0 = m * x0 + b;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
39
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
40 pn_draw_dot(x0, y0, value);
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 192
diff changeset
41 }
192
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
42 }
a7c823478180 [svn] - add fast linedrawing code
nenolod
parents:
diff changeset
43 }