summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac1
-rw-r--r--include/glsprite.h1
-rw-r--r--lib/glsprite.cc37
-rw-r--r--src/test.cc22
4 files changed, 55 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index dd59ccd..91643d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -105,4 +105,3 @@ if test _"$gmakepath" = _; then
else
echo configure complete, now type \'gmake\'
fi
- \ No newline at end of file
diff --git a/include/glsprite.h b/include/glsprite.h
index a7b2bfd..77d0d7f 100644
--- a/include/glsprite.h
+++ b/include/glsprite.h
@@ -15,6 +15,7 @@ namespace mogltk {
glSprite(Uint8 *, int, int);
virtual ~glSprite();
virtual void draw(int, int, ColorP = WHITE);
+ virtual void drawrotate(int, int, double, ColorP = WHITE);
};
};
diff --git a/lib/glsprite.cc b/lib/glsprite.cc
index 478c0ef..18df7eb 100644
--- a/lib/glsprite.cc
+++ b/lib/glsprite.cc
@@ -35,3 +35,40 @@ void mogltk::glSprite::draw(int dx, int dy, ColorP c) {
if (!was2D)
mogltk::engine::glbase_o->Leave2DMode();
}
+
+void mogltk::glSprite::drawrotate(int cx, int cy, double a, ColorP c) {
+ bool was2D;
+
+ int sx, sy;
+
+ sx = GetSX() / 2;
+ sy = GetSY() / 2;
+
+ was2D = mogltk::engine::glbase_o->is2D();
+
+ if (!was2D)
+ mogltk::engine::glbase_o->Enter2DMode();
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glRotated(a, 0, 0, 1);
+ glTranslated(cx, cy, 0);
+
+ glMatrixMode(GL_TEXTURE);
+ glRotated(a, 0, 0, 1);
+
+ c.Bind();
+
+ Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2i(GetPX() , GetPY() ); glVertex2i( - sx, - sy);
+ glTexCoord2i(GetPX() + GetSX(), GetPY() ); glVertex2i(GetSX() - sx, - sy);
+ glTexCoord2i(GetPX() , GetPY() + GetSY()); glVertex2i( - sx, GetSY() - sy);
+ glTexCoord2i(GetPX() + GetSX(), GetPY() + GetSY()); glVertex2i(GetSX() - sx, GetSY() - sy);
+ glEnd();
+
+ glPopMatrix();
+
+ if (!was2D)
+ mogltk::engine::glbase_o->Leave2DMode();
+}
diff --git a/src/test.cc b/src/test.cc
index 9003cab..ec00bfe 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -28,10 +28,10 @@ virtual int startup() throw (GeneralException) {
new Archive("datas.paq");
#if 1
- mogltk::base * gl = new mogltk::glbase();
- mogltk::shape * sh = new mogltk::glshape();
- mogltk::font * font = new mogltk::glfont(&Input("font-2.bin"));
- mogltk::Sprite * s = new mogltk::glSprite(&Input("cursor.rgba"), 25, 25);
+ mogltk::glbase * gl = new mogltk::glbase();
+ mogltk::glshape * sh = new mogltk::glshape();
+ mogltk::glfont * font = new mogltk::glfont(&Input("font-2.bin"));
+ mogltk::glSprite * s = new mogltk::glSprite(&Input("cursor.rgba"), 25, 25);
#else
mogltk::base * gl = new mogltk::base();
mogltk::shape * sh = new mogltk::shape();
@@ -90,8 +90,20 @@ virtual int startup() throw (GeneralException) {
font->printf("my: %i\n", mogltk::engine::mouseY());
font->printf("t: %.2fs\n", (double) SDL_GetTicks() / 1000);
- s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6);
+ double sx, sy, l, a;
+ sx = mogltk::engine::mouseX() - 320;
+ sy = mogltk::engine::mouseY() - 240;
+ l = sqrt(sx * sx + sy * sy);
+ sx /= l;
+ sy /= l;
+ a = acos(sx);
+ if (sy < 0)
+ a = -a;
+
+ font->printf("a: %.2f\n", a);
sh->line(320, 240, mogltk::engine::mouseX(), mogltk::engine::mouseY());
+ s->drawrotate(320, 240, a);
+ s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6);
gl->Leave2DMode();