25 # include <OpenGL/glu.h> 66 glNormal3f(0.f,0.f,1.f);
67 glBegin(GL_TRIANGLES);
69 glVertex2f(len - head_len, 0.5f*head_width);
70 glVertex2f(len - head_len, -0.5f*head_width);
77 glScalef(0.5f,1.f,1.f);
79 glScalef(1.f,0.25f,0.5f);
80 glTranslatef(-0.5f,0.5f,0.f);
81 glColor3f(1.0f, 0.3f, 0.3f);
86 glScalef(1.f,0.25f,0.5f);
87 glTranslatef(-0.5f,-0.5f,0.f);
88 glColor3f(1.0f, 0.1f, 0.1f);
93 glScalef(1.f,0.25f,0.5f);
94 glTranslatef(+0.5f,0.5f,0.f);
95 glColor3f(0.3f, 0.3f, 1.0f);
100 glScalef(1.f,0.25f,0.5f);
101 glTranslatef(+0.5f,-0.5f,0.f);
102 glColor3f(0.1f, 0.1f, 1.f);
116 glNormal3f( 0.0f, 0.0f,-1.0f);
117 glVertex3f(-sx, -sy, -sz);
118 glVertex3f(-sx, sy, -sz);
119 glVertex3f(sx, sy, -sz);
120 glVertex3f(sx, -sy, -sz);
122 glNormal3f( 0.0f, 0.0f,1.0f);
123 glVertex3f(-sx, -sy, sz);
124 glVertex3f(-sx, sy, sz);
125 glVertex3f(sx, sy, sz);
126 glVertex3f(sx, -sy, sz);
128 glNormal3f(-1.0f, 0.0f, 0.0f);
129 glVertex3f(-sx, -sy, -sz);
130 glVertex3f(-sx, sy, -sz);
131 glVertex3f(-sx, sy, sz);
132 glVertex3f(-sx, -sy, sz);
134 glNormal3f( 1.0f, 0.0f, 0.0f);
135 glVertex3f(sx, -sy, -sz);
136 glVertex3f(sx, sy, -sz);
137 glVertex3f(sx, sy, sz);
138 glVertex3f(sx, -sy, sz);
140 glNormal3f( 0.0f, -1.0f, 0.0f);
141 glVertex3f(-sx, -sy, -sz);
142 glVertex3f(sx, -sy, -sz);
143 glVertex3f(sx, -sy, sz);
144 glVertex3f(-sx, -sy, sz);
146 glNormal3f( 0.0f, 1.0f, 0.0f);
147 glVertex3f(-sx, sy, -sz);
148 glVertex3f(sx, sy, -sz);
149 glVertex3f(sx, sy, sz);
150 glVertex3f(-sx, sy, sz);
160 glNormal3f( 0.0f, 0.0f, 1.0f);
161 glVertex3f(-sx, -sy, 0.f);
162 glVertex3f(-sx, sy, 0.f);
163 glVertex3f(sx, sy, 0.f);
164 glVertex3f(sx, -sy, 0.f);
175 GLboolean hasNormalization = glIsEnabled(GL_NORMALIZE);
176 if (!hasNormalization)
177 glEnable(GL_NORMALIZE);
179 glScalef(r1, r2, r3);
182 if (!hasNormalization)
183 glDisable(GL_NORMALIZE);
189 glRotatef(-90.f, 1.f, 0.f, 0.f);
190 glTranslatef(0.f, 0.f, - height/2.0f);
199 glRotatef(-90, 1.f, 0.f, 0.f);
200 glTranslatef(0.f, 0.f, + height/2.0f);
202 glTranslatef(0, 0, - height);
204 glRotatef(180, 1.f, 0.f, 0.f);
211 glRotatef(90, 0.f, 1.f, 0.f);
218 glTranslatef(0.f, 0.f, - height/2.0f);
219 glRotatef(45, 0.f, 0.f, 1.f);
228 glRotatef((fov/2.0f) - 90, 0.f, 0.f, 1.f);
233 void drawSlice(GLfloat radius, GLfloat height, GLfloat fov,
int slices_per_circle)
235 double fov_rad = fov/180.*
M_PI;
236 int num_slices = int(slices_per_circle * (fov_rad / (2*
M_PI))) + 1;
237 double angle_step = fov_rad / num_slices;
238 double angle_step_half = angle_step * 0.5;
240 GLfloat height_half = height * 0.5f;
241 GLfloat lower_z = -height_half;
242 GLfloat upper_z = height_half;
244 GLfloat last_x = float(std::cos(-fov_rad * 0.5f) * radius);
245 GLfloat last_y = float(std::sin(-fov_rad * 0.5f) * radius);
248 glBegin(GL_TRIANGLES);
249 glNormal3f((
float)std::sin(-fov_rad * 0.5), (
float)-std::cos(-fov_rad * 0.5), 0.f);
250 glVertex3f(0.f, 0.f, upper_z);
251 glVertex3f(0.f, 0.f, lower_z);
252 glVertex3f(last_x, last_y, upper_z);
253 glVertex3f(last_x, last_y, upper_z);
254 glVertex3f(last_x, last_y, lower_z);
255 glVertex3f(0.f, 0.f, lower_z);
257 double start_angle = -0.5*fov_rad + angle_step;
258 double angle = start_angle;
259 for (
int i = 0; i < num_slices; ++i) {
260 GLfloat x = float(std::cos(angle) * radius);
261 GLfloat y = float(std::sin(angle) * radius);
262 GLfloat front_normal_x = (float)std::cos(angle + angle_step_half);
263 GLfloat front_normal_y = (float)std::sin(angle + angle_step_half);
266 glNormal3f(0.f, 0.f, -1.f);
267 glVertex3f(0.f, 0.f, lower_z);
268 glVertex3f(x, y, lower_z);
269 glVertex3f(last_x, last_y, lower_z);
271 glNormal3f(0.f, 0.f, 1.f);
272 glVertex3f(0.f, 0.f, upper_z);
273 glVertex3f(x, y, upper_z);
274 glVertex3f(last_x, last_y, upper_z);
276 glNormal3f(front_normal_x, front_normal_y, 0.f);
277 glVertex3f(last_x, last_y, upper_z);
278 glVertex3f(last_x, last_y, lower_z);
279 glVertex3f(x, y, upper_z);
280 glVertex3f(x, y, upper_z);
281 glVertex3f(x, y, lower_z);
282 glVertex3f(last_x, last_y, lower_z);
289 glNormal3f(
float(-std::sin(fov_rad * 0.5)),
float(std::cos(fov_rad * 0.5)), -0.f);
290 glVertex3f(0.f, 0.f, upper_z);
291 glVertex3f(0.f, 0.f, lower_z);
292 glVertex3f(last_x, last_y, upper_z);
293 glVertex3f(last_x, last_y, upper_z);
294 glVertex3f(last_x, last_y, lower_z);
295 glVertex3f(0.f, 0.f, lower_z);
302 glPointSize(pointSize);
GLUquadricObj * _quadratic
static GLUquadricObj * getQuadradic()
void drawDisk(GLfloat radius)
void drawArrow2D(float len, float head_width, float head_len)
void drawEllipsoid(GLfloat r1, GLfloat r2, GLfloat r3)
void drawPlane(GLfloat l, GLfloat w)
void drawBox(GLfloat l, GLfloat w, GLfloat h)
void drawPoint(float pointSize)
void drawCone(GLfloat radius, GLfloat height)
void drawSphere(GLfloat radius)
void drawSlice(GLfloat radius, GLfloat height, GLfloat fov, int slices_per_circle)
void drawRangeRing(GLfloat range, GLfloat fov, GLfloat range_width)
void drawCylinder(GLfloat radius, GLfloat height)
void drawPyramid(GLfloat length, GLfloat height)