summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpixel <pixel>2003-04-11 15:13:29 +0000
committerpixel <pixel>2003-04-11 15:13:29 +0000
commit102649b120a762b760cf618d6a61bdabb910f945 (patch)
treeb9ebb7d390b06693233d390e74f6405822c30c85 /lib
parentf9ede32a30a16a5078e51c6e959e275d9dbc7ad9 (diff)
maths...
Diffstat (limited to 'lib')
-rw-r--r--lib/font.cc2
-rw-r--r--lib/shape.cc166
2 files changed, 163 insertions, 5 deletions
diff --git a/lib/font.cc b/lib/font.cc
index 72d7de9..efdd9bd 100644
--- a/lib/font.cc
+++ b/lib/font.cc
@@ -142,7 +142,6 @@ mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), w
Uint8 * curtex = (Uint8 *) fonttex[0]->GetSurface()->pixels;
Uint32 curU = 0, curV = 0, curT = 0;
for (i = 0; i < nbentries; i++) {
- printm(M_INFO, "Reading entry %i at offset 0x%x\n", i, ffont->tell());
sizes[i] = ffont->readU8();
for (int v = 0; v < maxY; v++) {
for (int u = 0; u < maxX; u++) {
@@ -179,7 +178,6 @@ mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), w
corresp = (Uint16 *) malloc(nbentries * 2 * sizeof(Uint16));
for (i = 0; i < 2 * nbentries; i++) {
- printm(M_INFO, "Reading translation entry number %i at offset 0x%x\n", i, ffont->tell());
corresp[i] = ffont->readU16();
}
}
diff --git a/lib/shape.cc b/lib/shape.cc
index 5120a3c..84e89fd 100644
--- a/lib/shape.cc
+++ b/lib/shape.cc
@@ -1,6 +1,8 @@
#include <math.h>
#include <limits.h>
#include <SDL.h>
+#include <sys/types.h>
+#include <generic.h>
#include "engine.h"
#include "base.h"
#include "shape.h"
@@ -35,6 +37,7 @@ void mogltk::fill::walk(fillwalker * w) {
}
void mogltk::fill::insert(int x, int y) {
+ printm(M_INFO, "Inserting %i %i\n", x, y);
if (cached) {
delete cached;
cached = 0;
@@ -58,6 +61,30 @@ void mogltk::fill::insert(int x, int y) {
minY = y;
}
+void mogltk::fill::insert(int x1, int y1, int x2, int y2) {
+ int dx, dy, y;
+ double x, i, i2;
+
+ printm(M_INFO, "Adding line (%i, %i)-(%i, %i)\n", x1, y1, x2, y2);
+
+ if (y1 == y2)
+ return;
+
+ if (y2 < y1) {
+ SWAP(x1, x2);
+ SWAP(y1, y2);
+ }
+
+ dx = x1 - x2;
+ dy = y1 - y2;
+
+ x = x1;
+ i = ((double) dx) / ((double) dy);
+ i2 = i / 2;
+ for (y = y1; y < y2; y++, x += i)
+ insert(x + i2, y);
+}
+
int mogltk::fill::GetMaxX() const {
return maxX;
}
@@ -264,6 +291,124 @@ void mogltk::shape::vline3d(int x, int y1, int y2, ColorP shade1, ColorP shade2,
LEAVE;
}
+void mogltk::shape::bsubline_1(int x1, int y1, int x2, int y2, ColorP c) {
+ int x, y, ddx, ddy, e;
+ ddx = abs(x2 - x1);
+ ddy = abs(y2 - y1) << 1;
+ e = ddx - ddy;
+ ddx <<= 1;
+
+ if (x1 > x2) {
+ SWAP(x1, x2);
+ SWAP(y1, y2);
+ }
+
+ ENTER;
+
+ for (x = x1, y = y1; x <= x2; x++) {
+ pixel(x, y, c);
+ if (e < 0) {
+ y++;
+ e += ddx - ddy;
+ } else {
+ e -= ddy;
+ }
+ }
+
+ LEAVE;
+}
+
+void mogltk::shape::bsubline_2(int x1, int y1, int x2, int y2, ColorP c) {
+ int x, y, ddx, ddy, e;
+ ddx = abs(x2 - x1) << 1;
+ ddy = abs(y2 - y1);
+ e = ddy - ddx;
+ ddy <<= 1;
+
+ if (y1 > y2) {
+ SWAP(x1, x2);
+ SWAP(y1, y2);
+ }
+
+ ENTER;
+
+ for (y = y1, x = x1; y <= y2; y++) {
+ pixel(x, y, c);
+ if (e < 0) {
+ x++;
+ e += ddy - ddx;
+ } else {
+ e -= ddx;
+ }
+ }
+
+ LEAVE;
+}
+
+void mogltk::shape::bsubline_3(int x1, int y1, int x2, int y2, ColorP c) {
+ int x, y, ddx, ddy, e;
+ ddx = abs(x1 - x2) << 1;
+ ddy = abs(y2 - y1);
+ e = ddy - ddx;
+ ddy <<= 1;
+
+ if (y1 > y2) {
+ SWAP(x1, x2);
+ SWAP(y1, y2);
+ }
+
+ ENTER;
+
+ for (y = y1, x = x1; y <= y2; y++) {
+ pixel(x, y, c);
+ if (e < 0) {
+ x--;
+ e += ddy - ddx;
+ } else {
+ e -= ddx;
+ }
+ }
+
+ LEAVE;
+}
+
+void mogltk::shape::bsubline_4(int x1, int y1, int x2, int y2, ColorP c) {
+ int x, y, ddx, ddy, e;
+ ddy = abs(y2 - y1) << 1;
+ ddx = abs(x1 - x2);
+ e = ddx - ddy;
+ ddx <<= 1;
+
+ if (x1 > x2) {
+ SWAP(x1, x2);
+ SWAP(y1, y2);
+ }
+
+ for (x = x1, y = y1; x <= x2; x++) {
+ pixel(x, y, c);
+ if (e < 0) {
+ y--;
+ e += ddx - ddy;
+ } else {
+ e -= ddy;
+ }
+ }
+}
+
+void mogltk::shape::line(int x1, int y1, int x2, int y2, ColorP c) {
+ float k = float(y2 - y1) / float(x2 - x1);
+
+ if ((k >= 0) && (k <= 1))
+ bsubline_1(x1, y1, x2, y2, c);
+ else if (k > 1)
+ bsubline_2(x1, y1, x2, y2, c);
+ else if ((k < 0) && (k >= -1))
+ bsubline_3(x1, y1, x2, y2, c);
+ else
+ bsubline_4(x1, y1, x2, y2, c);
+
+}
+
void mogltk::shape::pixel(int x, int y, ColorP c) {
ENTER;
@@ -341,9 +486,11 @@ mogltk::fill * mogltk::shape::fcircle(int x0, int y0, int r) {
int dI = 10 - 4 * r;
int rI = 6;
mogltk::fill * f = new fill();
- bool t = true;
+ bool t = false;
+ int ox, oy;
while (x <= y) {
+/*
if (t) {
f->insert(x0 - x, y0 - y);
f->insert(x0 + x, y0 - y);
@@ -354,15 +501,28 @@ mogltk::fill * mogltk::shape::fcircle(int x0, int y0, int r) {
f->insert(x0 + y, y0 - x);
f->insert(x0 - y, y0 + x);
f->insert(x0 + y, y0 + x);
+*/
+ printm(M_INFO, "fcircle: processing point %i %i\n", x, y);
+ if (t) {
+ f->insert(x0 - ox, y0 - oy, x0 - x, y0 - y);
+ f->insert(x0 + ox, y0 - oy, x0 + x, y0 - y);
+ f->insert(x0 - ox, y0 + oy, x0 - x, y0 + y);
+ f->insert(x0 + ox, y0 + oy, x0 + x, y0 + y);
+ f->insert(x0 - oy, y0 - ox, x0 - y, y0 - x);
+ f->insert(x0 + oy, y0 - ox, x0 + y, y0 - x);
+ f->insert(x0 - oy, y0 + ox, x0 - y, y0 + x);
+ f->insert(x0 + oy, y0 + ox, x0 + y, y0 + x);
+ }
+ ox = x;
+ oy = y;
+ t = true;
if (d >= 0) {
d += dI;
dI += 8;
y -= 1;
- t = true;
} else {
d += rI;
dI += 4;
- t = false;
}
rI += 4;
x += 1;