summaryrefslogtreecommitdiffstats
path: root/kue/cue.cpp
blob: 561ad89a8887f2a9f3c1e98fe68db14d83926225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <math.h>
#include <tqcolor.h>

#include <GL/gl.h>
#include <GL/glu.h>

#include "cue.h"
#include "texture.h"

const int CUE_DISPLAY_LIST = 4;
const int TIP_DISPLAY_LIST = 5;

const double RADIUS = 0.00286;

void cue::draw(double x, double y, double angle, KueTexture &texture, const TQColor &tip_color)
{
    glPushMatrix();

    // Go to the specified location
    glTranslated(x, y, RADIUS);

    // Rotate to the specificed angle
    glRotated(angle, 0.0, 0.0, 1.0);
    // And tip the cue upwards
    glRotated(80, 0.0, 1.0, 0.0);

    // Have we built the cue display list?
    if (!glIsList(CUE_DISPLAY_LIST) == GL_TRUE)
    {
        // Make a new quadtic object
        GLUquadricObj *qobj = gluNewQuadric();

        // We need normals and texturing for lighting and textures
        gluQuadricNormals(qobj, GLU_SMOOTH);
        gluQuadricTexture(qobj, GL_TRUE);

        // Make a new display list
        glNewList(TIP_DISPLAY_LIST, GL_COMPILE);

        // Draw the tip
        gluCylinder(qobj, RADIUS / 2.5, RADIUS / 2.5, 0.003, 10, 10);

        // End the tip list
        glEndList();

        // Make a new display list
        glNewList(CUE_DISPLAY_LIST, GL_COMPILE);

        // Draw the main part of the cue
        glTranslated(0.0, 0.0, 0.003);
        gluCylinder(qobj, RADIUS / 2.5, RADIUS / 1.5, 0.047, 10, 10);

        // End the cue list
        glEndList();

        // Draw the quadric
        gluDeleteQuadric(qobj);
    }


    KueTexture::null().makeCurrent();
    glColor3d(
              tip_color.red() / 255.0,
              tip_color.green() / 255.0,
              tip_color.blue() / 255.0
             );
    glCallList(TIP_DISPLAY_LIST);

    texture.makeCurrent();
    glColor3d(1.0, 1.0, 1.0);
    glCallList(CUE_DISPLAY_LIST);

    glPopMatrix();
}