-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject.cpp
143 lines (130 loc) · 2.07 KB
/
Object.cpp
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
143
//
// Generic Object class
//
#include "Object.h"
//
// Constructor
//
Object::Object()
{
show = true;
// Location
x0 = y0 = z0 = 0;
// Rotation
th = ny = nz = 0;
nx = 1;
// Color
r0 = g0 = b0 = a0 = 1;
// Texture
tex = NULL;
}
//
// Show object
//
void Object::setShow(bool on)
{
show = on;
}
//
// Object position
//
void Object::setTranslate(float x,float y,float z)
{
x0 = x;
y0 = y;
z0 = z;
}
//
// Object rotation
//
void Object::setRotate(float t,float dx,float dy,float dz)
{
th = t;
nx = dx;
ny = dy;
nz = dz;
}
//
// Object color
//
void Object::setColor(Color rgb)
{
r0 = rgb.r;
g0 = rgb.g;
b0 = rgb.b;
a0 = rgb.a;
}
//
// Object color
//
void Object::setColor(float r,float g,float b,float a = 1)
{
r0 = r;
g0 = g;
b0 = b;
a0 = a;
}
//
// Apply transformation
//
void Object::useTransform(float dx,float dy,float dz)
{
glTranslated(x0,y0,z0);
glRotated(th,nx,ny,nz);
glScaled(dx,dy,dz);
}
//
// Apply default color
//
void Object::useColor()
{
useColor(Color(r0,g0,b0,a0));
}
//
// Apply ambient and diffuse color
// Specular is set to white
// Emission is set to black
//
void Object::useColor(Color c)
{
useColor(c,c,Color(1,1,1),Color(0,0,0),16);
}
//
// Apply colors
//
void Object::useColor(Color a,Color d,Color s,Color e,float Ns)
{
glColor4fv(d.fv());
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT ,a.fv());
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE ,d.fv());
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,s.fv());
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,e.fv());
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,&Ns);
}
//
// Set texture
//
void Object::setTexture(QString file)
{
tex = new QOpenGLTexture(QImage(file).mirrored());
tex->setMinificationFilter(QOpenGLTexture::Linear);
tex->setMagnificationFilter(QOpenGLTexture::Linear);
}
//
// Enable texture
//
void Object::EnableTex()
{
if (tex)
{
tex->bind();
glEnable(GL_TEXTURE_2D);
}
}
//
// Disable texture
//
void Object::DisableTex()
{
if (tex) glDisable(GL_TEXTURE_2D);
}