|
|
d2b2b5 |
|
|
|
8ee194 |
#include <gl gl.h=""></gl>
|
|
|
8ee194 |
|
|
|
d2b2b5 |
#include "tool.h"
|
|
|
d2b2b5 |
|
|
|
8ee194 |
|
|
|
8ee194 |
void FlatTool::draw(const Vector3 &pos, const Vector3 &dir) const {
|
|
|
8ee194 |
const int segments = 16;
|
|
|
8ee194 |
const Real len = 10*radius;
|
|
|
8ee194 |
|
|
|
8ee194 |
glPushMatrix();
|
|
|
8ee194 |
glEnable(GL_NORMALIZE);
|
|
|
8ee194 |
glEnable(GL_LIGHTING);
|
|
|
8ee194 |
|
|
|
8ee194 |
glTranslated(pos.x, pos.y, pos.z);
|
|
|
8ee194 |
Vector3 vx = dir.cross(Vector3(dir.y, dir.z, dir.x));
|
|
|
8ee194 |
vx = vx*(1/vx.len());
|
|
|
8ee194 |
Vector3 vy = vx.cross(dir);
|
|
|
8ee194 |
|
|
|
8ee194 |
Real matrix[16] = {
|
|
|
8ee194 |
vx.x, vx.y, vx.z, 0,
|
|
|
8ee194 |
vy.x, vy.y, vy.z, 0,
|
|
|
8ee194 |
dir.x, dir.y, dir.z, 0,
|
|
|
8ee194 |
0, 0, 0, 1 };
|
|
|
8ee194 |
glMultMatrixd(matrix);
|
|
|
8ee194 |
|
|
|
8ee194 |
glBegin(GL_TRIANGLE_STRIP);
|
|
|
8ee194 |
for(int i = 0; i <= segments; ++i) {
|
|
|
8ee194 |
Real a = 2*M_PI*i/segments;
|
|
|
8ee194 |
Real c = cos(a);
|
|
|
8ee194 |
Real s = sin(a);
|
|
|
8ee194 |
glNormal3b(c, s, 0);
|
|
|
8ee194 |
glVertex3d(c, s, 0);
|
|
|
8ee194 |
glVertex3d(c, s, -len);
|
|
|
8ee194 |
}
|
|
|
8ee194 |
glEnd();
|
|
|
8ee194 |
|
|
|
8ee194 |
glBegin(GL_TRIANGLE_FAN);
|
|
|
8ee194 |
glNormal3b(0, 0, 1);
|
|
|
8ee194 |
for(int i = 0; i < segments; ++i) {
|
|
|
8ee194 |
Real a = 2*M_PI*i/segments;
|
|
|
8ee194 |
glVertex3d(cos(a), sin(a), 0);
|
|
|
8ee194 |
}
|
|
|
8ee194 |
glEnd();
|
|
|
8ee194 |
|
|
|
8ee194 |
glBegin(GL_TRIANGLE_FAN);
|
|
|
8ee194 |
glNormal3b(0, 0, -1);
|
|
|
8ee194 |
for(int i = 0; i < segments; ++i) {
|
|
|
8ee194 |
Real a = 2*M_PI*i/segments;
|
|
|
8ee194 |
glVertex3d(cos(a), sin(a), -len);
|
|
|
8ee194 |
}
|
|
|
8ee194 |
glEnd();
|
|
|
8ee194 |
|
|
|
8ee194 |
glDisable(GL_LIGHTING);
|
|
|
8ee194 |
glDisable(GL_NORMALIZE);
|
|
|
8ee194 |
glPopMatrix();
|
|
|
8ee194 |
}
|