AnoPlib - Animlets are not Particles library
|
00001 /* ************************************************************************* 00002 @file AnoPhelpers.cpp 00003 @project AnoPlib 00004 @module AnoPhelpers 00005 @brief Some helper methods and data 00006 @date 29.11.2010 00007 @copyright Daniel Krajzewicz 00008 @licence GPL 00009 @author Daniel Krajzewicz 00010 @email d.krajzewicz@googlemail.com 00011 ------------------------------------------------------------------ 00012 AnoPlib - small "animlet" library, see http://sf.net/projects/anoplib 00013 Copyright (C) 2009-2010 Daniel Krajzewicz 00014 00015 This program is free software: you can redistribute it and/or modify 00016 it under the terms of the GNU General Public License as published by 00017 the Free Software Foundation, either version 3 of the License, or 00018 (at your option) any later version. 00019 00020 This program is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU General Public License for more details. 00024 00025 You should have received a copy of the GNU General Public License 00026 along with this program. If not, see <http://www.gnu.org/licenses/>. 00027 ------------------------------------------------------------------ 00028 Remarks: 00029 ------------------------------------------------------------------ 00030 ToDo: 00031 * *********************************************************************** */ 00032 00033 /* ========================================================================= 00034 * included modules 00035 * ======================================================================= */ 00036 #ifdef _WIN32 00037 #include <windows.h> 00038 #endif 00039 00040 #include "AnoPhelpers.h" 00041 #include <GL/gl.h> 00042 #include <cmath> 00043 00044 00045 /* ========================================================================= 00046 * static members 00047 * ======================================================================= */ 00048 double *AnoPhelpers::sintab; 00049 double *AnoPhelpers::costab; 00050 00051 00052 /* ========================================================================= 00053 * method definitions 00054 * ======================================================================= */ 00055 void AnoPhelpers::init() { 00056 double PI = 3.1415926535897932384626433832795; 00057 sintab = new double[360]; 00058 costab = new double[360]; 00059 for(int i=0; i<360; ++i) { 00060 sintab[i] = 256. * sin(PI/180.*(double)i); 00061 costab[i] = 256. * cos(PI/180.*(double)i); 00062 } 00063 } 00064 00065 00066 void AnoPhelpers::close() { 00067 delete[] sintab; 00068 delete[] costab; 00069 } 00070 00071 00072 void 00073 AnoPhelpers::drawOutlineCircle(double width, double iwidth, int steps, double beg, double end) throw() { 00074 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00075 double p1x = beg==0 ? sintab[0] : sintab[((int) beg)%360]; 00076 double p1y = beg==0 ? costab[0] : costab[((int) beg)%360]; 00077 for (int i=(int)(beg); i<steps&&(360.0/(double) steps *(double) i)<end; i++) { 00078 double p2x = sintab[(size_t)(360.0/(double) steps * (double) i)%360]; 00079 double p2y = costab[(size_t)(360.0/(double) steps * (double) i)%360]; 00080 glBegin(GL_TRIANGLES); 00081 glVertex2d(p1x * width, p1y * width); 00082 glVertex2d(p2x * width, p2y * width); 00083 glVertex2d(p2x * iwidth, p2y * iwidth); 00084 00085 glVertex2d(p2x * iwidth, p2y * iwidth); 00086 glVertex2d(p1x * iwidth, p1y * iwidth); 00087 glVertex2d(p1x * width, p1y * width); 00088 glEnd(); 00089 p1x = p2x; 00090 p1y = p2y; 00091 } 00092 double p2x = end==360 ? sintab[0] : sintab[((int) end)%360]; 00093 double p2y = end==360 ? costab[0] : costab[((int) end)%360]; 00094 glBegin(GL_TRIANGLES); 00095 glVertex2d(p1x * width, p1y * width); 00096 glVertex2d(p2x * width, p2y * width); 00097 glVertex2d(p2x * iwidth, p2y * iwidth); 00098 00099 glVertex2d(p2x * iwidth, p2y * iwidth); 00100 glVertex2d(p1x * iwidth, p1y * iwidth); 00101 glVertex2d(p1x * width, p1y * width); 00102 glEnd(); 00103 } 00104 00105 00106 void 00107 AnoPhelpers::drawOutlineCircle2(double width, double iwidth, int steps, double beg, double end, 00108 float *rgba1, float *rgba2) throw() { 00109 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00110 double p1x = beg==0 ? sintab[0] : sintab[((int) beg)%360]; 00111 double p1y = beg==0 ? costab[0] : costab[((int) beg)%360]; 00112 double s = end - beg; 00113 if(s<0) { 00114 s = 360. + s; 00115 } 00116 for (int i=0; i<steps; ++i) { 00117 double p2x = sintab[(size_t)(s/(double) steps * (double) i + beg)%360]; 00118 double p2y = costab[(size_t)(s/(double) steps * (double) i + beg)%360]; 00119 glBegin(GL_TRIANGLES); 00120 glColor4fv(rgba2); 00121 glVertex2d(p1x * width, p1y * width); 00122 glVertex2d(p2x * width, p2y * width); 00123 glColor4fv(rgba1); 00124 glVertex2d(p2x * iwidth, p2y * iwidth); 00125 00126 glVertex2d(p2x * iwidth, p2y * iwidth); 00127 glVertex2d(p1x * iwidth, p1y * iwidth); 00128 glColor4fv(rgba2); 00129 glVertex2d(p1x * width, p1y * width); 00130 glEnd(); 00131 p1x = p2x; 00132 p1y = p2y; 00133 } 00134 double p2x = end==360 ? sintab[0] : sintab[((int) end)%360]; 00135 double p2y = end==360 ? costab[0] : costab[((int) end)%360]; 00136 glBegin(GL_TRIANGLES); 00137 glColor4fv(rgba2); 00138 glVertex2d(p1x * width, p1y * width); 00139 glVertex2d(p2x * width, p2y * width); 00140 glColor4fv(rgba1); 00141 glVertex2d(p2x * iwidth, p2y * iwidth); 00142 00143 glVertex2d(p2x * iwidth, p2y * iwidth); 00144 glVertex2d(p1x * iwidth, p1y * iwidth); 00145 glColor4fv(rgba2); 00146 glVertex2d(p1x * width, p1y * width); 00147 glEnd(); 00148 }