[Teleus-cvs] teleus/src/gfx gfx.cpp,1.18,1.19 gfx.hpp,1.14,1.15
Status: Inactive
Brought to you by:
spiffgq
|
From: Daniel R. <sp...@us...> - 2004-05-25 23:00:07
|
Update of /cvsroot/teleus/teleus/src/gfx In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15157/src/gfx Modified Files: gfx.cpp gfx.hpp Log Message: Added a few new gfx methods (renderSphere, renderQuad) Index: gfx.hpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/gfx/gfx.hpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** gfx.hpp 25 Feb 2004 06:34:01 -0000 1.14 --- gfx.hpp 25 May 2004 22:59:57 -0000 1.15 *************** *** 39,42 **** --- 39,43 ---- namespace obj{ class Cube; + class Sphere; } *************** *** 154,157 **** --- 155,160 ---- void renderWireSphere (const math::ApproxSphere&, unsigned int, float, float*); void renderSphere (const math::ApproxSphere&, unsigned int, float); + void renderSphere (const obj::Sphere&, bool solid = true); + void renderQuad (float width, float height); } // END NAMESPACE gfx Index: gfx.cpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/gfx/gfx.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** gfx.cpp 25 Feb 2004 06:34:01 -0000 1.18 --- gfx.cpp 25 May 2004 22:59:57 -0000 1.19 *************** *** 41,44 **** --- 41,45 ---- #include "math/geometry.hpp" #include "obj/cube.hpp" + #include "obj/sphere.hpp" #include "debug.hpp" *************** *** 833,837 **** double x, y, z, angle; ! c->rot().getAxisAngle (x, y, z, angle); glPushMatrix (); --- 834,838 ---- double x, y, z, angle; ! c->rotation().getAxisAngle (x, y, z, angle); glPushMatrix (); *************** *** 888,891 **** --- 889,893 ---- glEnd (); + glPopMatrix (); *************** *** 967,972 **** --- 969,982 ---- unsigned int rad, float angle, float* pos) { + assert (s.slices() != 0 && s.stacks() != 0, "Trying to render " "a null ApproxSphere"); + #if 0 + if (pos){ + DEBUG_PRINT("Rendering wire sphere of radius %d at pos <%f, %f, %f>\n", rad, pos[0], pos[1], pos[2]); + }else{ + DEBUG_PRINT("Rendering wire sphere of radius %d at origin\n", rad); + } + #endif double radius = (double)rad; *************** *** 1085,1088 **** --- 1095,1152 ---- //assertNotReached(); + } + + void renderSphere (const obj::Sphere& s, bool solid) { + + assert (s.geometry().slices() != 0 && s.geometry().stacks() != 0, + "Trying to render a null ApproxSphere"); + + assert (solid, "Rendering wire spheres not supported in this method yet."); + + double radius = s.radius(); + double z0, z1, r0, r1, x, y; + int stackCount = (s.geometry().stackSize() - 1)/2; + int sliceCount = s.geometry().sliceSize()-1 ; + + setColor(s.color()); + glPushMatrix(); + glTranslatef (s.pos().x, s.pos().y, s.pos().z); + + z0 = 1.0; + z1 = s.geometry().stackCos(1); + r0 = 0.0; + r1 = s.geometry().stackSin(1); + + //DEBUG_PRINT ("Drawing %d stacks:\n", stackCount); + + for (int i = 0; i <= stackCount; ++i){ + + z0 = z1; + z1 = s.geometry().stackCos(i); + + r0 = r1; + r1 = s.geometry().stackSin(i); + + //DEBUG_PRINT ("\t Drawing stack %d (z = %0.3f; r = %0.3f)\n", i, z1, r1); + //DEBUG_PRINT ("\t Drawing %d slices\n", sliceCount); + + glBegin(GL_QUAD_STRIP); + for (int j = sliceCount; j >= 0; --j){ + + x = s.geometry().sliceCos(j); + y = s.geometry().sliceSin(j); + + //DEBUG_PRINT ("\t\t Drawing slice %d (x = %0.3f; y = %0.3f)\n", j, x, y); + + glNormal3f(x*r1, y*r1, z1); + glVertex3d(x*r1*radius, y*r1*radius, z1*radius); + + glNormal3f(x*r0, y*r0, z0); + glVertex3d(x*r0*radius, y*r0*radius, z0*radius); + } + glEnd(); + } + + glPopMatrix(); } *************** *** 1126,1129 **** --- 1190,1209 ---- } + void renderQuad (float width, float height) { + + setColor(0.0, 0.0, 0.0); + glPushMatrix (); + glLoadIdentity(); + //glScalef (width, height, 1.0); + glTranslatef (0.0, screenHeight-height, 0.0); + glBegin (GL_QUADS); + glVertex3d (0.0, 0.0, 0.0); + glVertex3d (width, 0.0, 0.0); + glVertex3d (width, height, 0.0); + glVertex3d (0.0, height, 0.0); + glEnd(); + glPopMatrix(); + } + /** * \brief Enables 2D textures. |