OpenGL: draw empties without GLU
Also reduced number of matrix ops by generating final positions directly. Also removed a display list (deprecated in modern GL). Tried to reuse sinval & cosval tables but those values are skewed (last value repeats first value, middle values are squished to compensate). Went with sinf & cosf instead. Part of T49042
This commit is contained in:
@@ -5477,54 +5477,56 @@ static void draw_editfont(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *b
|
|||||||
/* draw a sphere for use as an empty drawtype */
|
/* draw a sphere for use as an empty drawtype */
|
||||||
static void draw_empty_sphere(float size)
|
static void draw_empty_sphere(float size)
|
||||||
{
|
{
|
||||||
static GLuint displist = 0;
|
#define NSEGMENTS 16
|
||||||
|
/* a single ring of vertices */
|
||||||
if (displist == 0) {
|
float p[NSEGMENTS][2];
|
||||||
GLUquadricObj *qobj;
|
for (int i = 0; i < NSEGMENTS; ++i) {
|
||||||
|
float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
|
||||||
displist = glGenLists(1);
|
p[i][0] = size * cosf(angle);
|
||||||
glNewList(displist, GL_COMPILE);
|
p[i][1] = size * sinf(angle);
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
|
|
||||||
qobj = gluNewQuadric();
|
|
||||||
gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
|
|
||||||
gluDisk(qobj, 0.0, 1, 16, 1);
|
|
||||||
|
|
||||||
glRotatef(90, 0, 1, 0);
|
|
||||||
gluDisk(qobj, 0.0, 1, 16, 1);
|
|
||||||
|
|
||||||
glRotatef(90, 1, 0, 0);
|
|
||||||
gluDisk(qobj, 0.0, 1, 16, 1);
|
|
||||||
|
|
||||||
gluDeleteQuadric(qobj);
|
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
glEndList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glScalef(size, size, size);
|
glBegin(GL_LINE_LOOP);
|
||||||
glCallList(displist);
|
for (int i = 0; i < NSEGMENTS; ++i)
|
||||||
glScalef(1.0f / size, 1.0f / size, 1.0f / size);
|
glVertex3f(p[i][0], p[i][1], 0.0f);
|
||||||
|
glEnd();
|
||||||
|
glBegin(GL_LINE_LOOP);
|
||||||
|
for (int i = 0; i < NSEGMENTS; ++i)
|
||||||
|
glVertex3f(p[i][0], 0.0f, p[i][1]);
|
||||||
|
glEnd();
|
||||||
|
glBegin(GL_LINE_LOOP);
|
||||||
|
for (int i = 0; i < NSEGMENTS; ++i)
|
||||||
|
glVertex3f(0.0f, p[i][0], p[i][1]);
|
||||||
|
glEnd();
|
||||||
|
#undef NSEGMENTS
|
||||||
}
|
}
|
||||||
|
|
||||||
/* draw a cone for use as an empty drawtype */
|
/* draw a cone for use as an empty drawtype */
|
||||||
static void draw_empty_cone(float size)
|
static void draw_empty_cone(float size)
|
||||||
{
|
{
|
||||||
const float radius = size;
|
#define NSEGMENTS 8
|
||||||
|
/* a single ring of vertices */
|
||||||
|
float p[NSEGMENTS][2];
|
||||||
|
for (int i = 0; i < NSEGMENTS; ++i) {
|
||||||
|
float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
|
||||||
|
p[i][0] = size * cosf(angle);
|
||||||
|
p[i][1] = size * sinf(angle);
|
||||||
|
}
|
||||||
|
|
||||||
GLUquadricObj *qobj = gluNewQuadric();
|
/* cone sides */
|
||||||
gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
|
glBegin(GL_LINES);
|
||||||
|
for (int i = 0; i < NSEGMENTS; ++i) {
|
||||||
glPushMatrix();
|
glVertex3f(0.0f, 2.0f * size, 0.0f);
|
||||||
|
glVertex3f(p[i][0], 0.0f, p[i][1]);
|
||||||
glScalef(radius, size * 2.0f, radius);
|
}
|
||||||
glRotatef(-90.0, 1.0, 0.0, 0.0);
|
glEnd();
|
||||||
gluCylinder(qobj, 1.0, 0.0, 1.0, 8, 1);
|
|
||||||
|
|
||||||
glPopMatrix();
|
/* end ring */
|
||||||
|
glBegin(GL_LINE_LOOP);
|
||||||
gluDeleteQuadric(qobj);
|
for (int i = 0; i < NSEGMENTS; ++i)
|
||||||
|
glVertex3f(p[i][0], 0.0f, p[i][1]);
|
||||||
|
glEnd();
|
||||||
|
#undef NSEGMENTS
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drawspiral(const float cent[3], float rad, float tmat[4][4], int start)
|
static void drawspiral(const float cent[3], float rad, float tmat[4][4], int start)
|
||||||
|
|||||||
Reference in New Issue
Block a user