1 /* pipeConnector.cc
2 Connects pipes
3
4 Copyright (C) 2000 Mathias Broxvall
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "pipeConnector.h"
22
23 #include "game.h"
24
PipeConnector(Game & g,const Coord3d & pos,Real r)25 PipeConnector::PipeConnector(Game &g, const Coord3d &pos, Real r)
26 : Animated(g, Role_PipeConnector, 1), radius(r) {
27 position = pos;
28 primaryColor = Color(0.6, 0.6, 0.6, 1.0);
29
30 boundingBox[0][0] = -radius;
31 boundingBox[0][1] = -radius;
32 boundingBox[0][2] = -radius;
33 boundingBox[1][0] = radius;
34 boundingBox[1][1] = radius;
35 boundingBox[1][2] = radius;
36 }
37
generateBuffers(const GLuint * idxbufs,const GLuint * databufs,const GLuint * vaolist,bool mustUpdate) const38 void PipeConnector::generateBuffers(const GLuint *idxbufs, const GLuint *databufs,
39 const GLuint *vaolist, bool mustUpdate) const {
40 if (!mustUpdate) return;
41
42 int ntries = 0;
43 int nverts = 0;
44 int detail = 6;
45 countObjectSpherePoints(&ntries, &nverts, detail);
46 GLfloat *data = new GLfloat[nverts * 8];
47 ushort *idxs = new ushort[ntries * 3];
48 GLfloat pos[3] = {(GLfloat)position[0], (GLfloat)position[1], (GLfloat)position[2]};
49 Matrix3d identity = {{1.f, 0.f, 0.f}, {0.f, 1.f, 0.f}, {0.f, 0.f, 1.f}};
50
51 placeObjectSphere(data, idxs, 0, pos, identity, radius, detail, primaryColor);
52
53 glBindVertexArray(vaolist[0]);
54 glBindBuffer(GL_ARRAY_BUFFER, databufs[0]);
55 glBufferData(GL_ARRAY_BUFFER, nverts * 8 * sizeof(GLfloat), data, GL_STATIC_DRAW);
56 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idxbufs[0]);
57 glBufferData(GL_ELEMENT_ARRAY_BUFFER, ntries * 3 * sizeof(ushort), idxs, GL_STATIC_DRAW);
58 configureObjectAttributes();
59 delete[] data;
60 delete[] idxs;
61 }
drawBuffers1(const GLuint * vaolist) const62 void PipeConnector::drawBuffers1(const GLuint *vaolist) const {
63 if (primaryColor.v[3] >= 65535) drawMe(vaolist);
64 }
drawBuffers2(const GLuint * vaolist) const65 void PipeConnector::drawBuffers2(const GLuint *vaolist) const {
66 if (activeView.calculating_shadows && primaryColor.v[3] < 45000) return;
67 if (primaryColor.v[3] < 65535) drawMe(vaolist);
68 }
drawMe(const GLuint * vaolist) const69 void PipeConnector::drawMe(const GLuint *vaolist) const {
70 if (primaryColor.v[3] < 65535) {
71 glEnable(GL_BLEND);
72 glDisable(GL_CULL_FACE);
73 } else {
74 glDisable(GL_BLEND);
75 glEnable(GL_CULL_FACE);
76 }
77
78 int ntries = 0;
79 int nverts = 0;
80 int detail = 6;
81 countObjectSpherePoints(&ntries, &nverts, detail);
82
83 setActiveProgramAndUniforms(Shader_Object);
84 setObjectUniforms(specularColor, 1., Lighting_Regular);
85 glBindTexture(GL_TEXTURE_2D, textureBlank);
86
87 glBindVertexArray(vaolist[0]);
88 glDrawElements(GL_TRIANGLES, 3 * ntries, GL_UNSIGNED_SHORT, (void *)0);
89 }
tick(Real t)90 void PipeConnector::tick(Real t) { Animated::tick(t); }
91