-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton3D.cpp
More file actions
142 lines (122 loc) · 3.36 KB
/
Button3D.cpp
File metadata and controls
142 lines (122 loc) · 3.36 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "Button3D.h"
#include <iostream>
#ifdef __APPLE__
# include <GLUT/glut.h>
#else
# include <GL/glut.h>
#endif
Button3D::Button3D()
{
xCenter = yCenter = zCenter = xRotation = yRotation = zRotation = 0.0;
direction = 'u';
clicked = false;
}
Button3D::Button3D(float x, float y, float z,
float xR, float yR, float zR)
{
xCenter = x; yCenter = y; zCenter = z;
xRotation = xR; yRotation = yR; zRotation = zR;
direction = 'd'; // down
clicked = false;
}
Button3D::~Button3D()
{
}
void Button3D::draw(bool selectionModeEnabled, unsigned int closestName, int highlightFrames)
{
float hWidth = 2.5, hHeight = 2.5, zOff = 0.5;
glPushMatrix();
glTranslatef(xCenter, yCenter, zCenter); // translate before rotate
glRotatef(xRotation, 1.0, 0.0, 0.0);
glRotatef(yRotation, 0.0, 1.0, 0.0);
glRotatef(zRotation, 0.0, 0.0, 1.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if (selectionModeEnabled)
glLoadName(1); // name is 1 for this object
if (highlightFrames > 0 && closestName == 1)
{
clicked = true;
}
glColor3f(1.0, 1.0, 1.0);
//glutSolidCube(3.0);
glBegin(GL_POLYGON);
glVertex3f(-hWidth, hHeight, zOff); // top left front
glVertex3f(-hWidth, hHeight, -zOff); // top left back
glVertex3f(-hWidth, hHeight, zOff); // top left front
//glColor3f(0.0, 1.0, 1.0);
glVertex3f(hWidth, hHeight, zOff); // top right front
glVertex3f(hWidth, hHeight, -zOff); // top right back
glVertex3f(hWidth, hHeight, zOff); // top right front
//glColor3f(1.0, 0.0, 1.0);
glVertex3f(hWidth, -hHeight, zOff); // bottom right front
glVertex3f(hWidth, -hHeight, -zOff); // bottom right back
glVertex3f(hWidth, -hHeight, zOff); // bottom right front
//glColor3f(1.0, 1.0, 0.0);
glVertex3f(-hWidth, -hHeight, zOff); // bottom left front
glVertex3f(-hWidth, -hHeight, -zOff); // bottom left back
glVertex3f(-hWidth, -hHeight, zOff); // bottom left front
glVertex3f(-hWidth, hHeight, zOff); // top left front
// back
//glColor3f(1.0, 1.0, 1.0);
glVertex3f(-hWidth, hHeight, -zOff); // top left back
//glColor3f(0.0, 1.0, 1.0);
glVertex3f(hWidth, hHeight, -zOff); // top right back
//glColor3f(1.0, 0.0, 1.0);
glVertex3f(hWidth, -hHeight, -zOff); // bottom right back
//glColor3f(1.0, 1.0, 0.0);
glVertex3f(-hWidth, -hHeight, -zOff); // bottom left back
//glColor3f(1.0, 1.0, 1.0);
glVertex3f(-hWidth, hHeight, -zOff); // top left back
glEnd();
glEnable(GL_AUTO_NORMAL);
glPopMatrix();
// Clear name stack
if (selectionModeEnabled)
glPopName();
}
void Button3D::rotate(float increment)
{
xRotation += increment; yRotation += increment; zRotation += increment;
// bring the angles back to 0
if (xRotation >= 360.0)
xRotation = 0.0;
if (yRotation >= 360.0)
yRotation = 0.0;
if (zRotation >= 360.0)
zRotation = 0.0;
}
void Button3D::move(float xChange, float yChange, float zChange)
{
xCenter += xChange;
yCenter += yChange;
zCenter += zChange;
}
void Button3D::verticalScroll(float yLow, float yHigh, float increment)
{
if (yCenter >= yLow && yCenter <= yHigh) // must be in the range
{
switch (direction)
{
case 'u':
if (yCenter + increment > yHigh)
{
yCenter = yHigh;
direction = 'd';
}
else
yCenter += increment;
break;
case 'd':
if (yCenter - increment < yLow)
{
yCenter = yLow;
direction = 'u'; // switch direction
}
else
yCenter -= increment;
break;
default:
break;
}
}
}