|
|
d2b2b5 |
|
|
|
8ee194 |
#include <gl gl.h=""></gl>
|
|
|
8ee194 |
|
|
|
d2b2b5 |
#include "tool.h"
|
|
|
d2b2b5 |
|
|
|
8ee194 |
|
|
|
b2ca59 |
static void draw_disc(const Vector3 &p, const Vector3 &axis, Real r, bool flip = false, int segments = 16) {
|
|
|
b2ca59 |
Vector3 n = axis.norm();
|
|
|
b2ca59 |
Vector3 vx = n.perp().norm();
|
|
|
b2ca59 |
Vector3 vy = vx.cross(n);
|
|
|
b2ca59 |
if (flip) glNormal3d(-n.x, -n.y, -n.z); else glNormal3dv(n.c);
|
|
|
b2ca59 |
glBegin(GL_TRIANGLE_FAN);
|
|
|
b2ca59 |
glVertex3dv(p.c);
|
|
|
b2ca59 |
for(int i = 0; i <= segments; ++i) {
|
|
|
b2ca59 |
Real a = 2*M_PI*(flip ? segments - i - 1 : i)/segments;
|
|
|
b2ca59 |
Vector3 n = vx*cos(a) + vy*sin(a);
|
|
|
b2ca59 |
glVertex3dv((p + n*r).c);
|
|
|
b2ca59 |
}
|
|
|
b2ca59 |
glEnd();
|
|
|
b2ca59 |
}
|
|
|
8ee194 |
|
|
|
b2ca59 |
static void draw_cone(const Vector3 &p0, const Vector3 &p1, Real r0, Real r1, bool flip = false, int segments = 16) {
|
|
|
b2ca59 |
Vector3 dir = (p1 - p0).norm();
|
|
|
b2ca59 |
Vector3 vx = dir.perp().norm();
|
|
|
8ee194 |
Vector3 vy = vx.cross(dir);
|
|
|
8ee194 |
glBegin(GL_TRIANGLE_STRIP);
|
|
|
8ee194 |
for(int i = 0; i <= segments; ++i) {
|
|
|
8ee194 |
Real a = 2*M_PI*i/segments;
|
|
|
b2ca59 |
Vector3 n = vx*cos(a) + vy*sin(a);
|
|
|
b2ca59 |
if (flip) {
|
|
|
b2ca59 |
glNormal3d(-n.x, -n.y, -n.z);
|
|
|
b2ca59 |
glVertex3dv((p1 + n*r1).c);
|
|
|
b2ca59 |
glVertex3dv((p0 + n*r0).c);
|
|
|
b2ca59 |
} else {
|
|
|
b2ca59 |
glNormal3dv(n.c);
|
|
|
b2ca59 |
glVertex3dv((p0 + n*r0).c);
|
|
|
b2ca59 |
glVertex3dv((p1 + n*r1).c);
|
|
|
b2ca59 |
}
|
|
|
8ee194 |
}
|
|
|
8ee194 |
glEnd();
|
|
|
b2ca59 |
}
|
|
|
8ee194 |
|
|
|
b2ca59 |
|
|
|
b2ca59 |
void FlatTool::draw(const Vector3 &pos, const Vector3 &dir) const {
|
|
|
b2ca59 |
Vector3 p0 = pos - dir.norm()*10*radius;
|
|
|
b2ca59 |
|
|
|
b2ca59 |
glEnable(GL_LIGHTING);
|
|
|
b2ca59 |
glColor4d(1, 1, 0, 0.25);
|
|
|
8ee194 |
|
|
|
b2ca59 |
draw_cone(p0, pos, radius, radius);
|
|
|
b2ca59 |
draw_disc(p0, pos - p0, radius, true);
|
|
|
b2ca59 |
draw_disc(pos, pos - p0, radius);
|
|
|
b2ca59 |
|
|
|
b2ca59 |
glDisable(GL_LIGHTING);
|
|
|
b2ca59 |
glPopMatrix();
|
|
|
b2ca59 |
}
|
|
|
b2ca59 |
|
|
|
b2ca59 |
|
|
|
b2ca59 |
void ConeTool::draw(const Vector3 &pos, const Vector3 &dir) const {
|
|
|
b2ca59 |
glEnable(GL_LIGHTING);
|
|
|
b2ca59 |
glColor4d(1, 1, 0, 0.25);
|
|
|
b2ca59 |
|
|
|
b2ca59 |
Real r = fabs(radius);
|
|
|
b2ca59 |
Real cr = fabs(cut_radius);
|
|
|
b2ca59 |
Real h = fabs(height);
|
|
|
b2ca59 |
Real cl = 10*r;
|
|
|
b2ca59 |
|
|
|
b2ca59 |
Vector3 p1 = pos;
|
|
|
b2ca59 |
if (h > precision && cr < r - precision) {
|
|
|
b2ca59 |
p1 = pos - dir.norm()*h;
|
|
|
b2ca59 |
draw_cone(p1, pos, r, cr);
|
|
|
b2ca59 |
if (cr > precision)
|
|
|
b2ca59 |
draw_disc(pos, pos - p1, cr);
|
|
|
b2ca59 |
cl = std::max(2*r, cl - h);
|
|
|
8ee194 |
}
|
|
|
b2ca59 |
Vector3 p0 = p1 - dir.norm()*cl;
|
|
|
b2ca59 |
draw_cone(p0, p1, r, r);
|
|
|
b2ca59 |
draw_disc(p0, p1 - p0, r, true);
|
|
|
8ee194 |
|
|
|
8ee194 |
glDisable(GL_LIGHTING);
|
|
|
8ee194 |
glPopMatrix();
|
|
|
8ee194 |
}
|
|
|
b2ca59 |
|