gldraw.cpp

Sun, 21 Apr 2013 19:03:53 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 21 Apr 2013 19:03:53 +0300
changeset 123
a54d9d5c0c1f
parent 121
7e87c85ad092
child 131
3ccb10f6ed0b
permissions
-rw-r--r--

Added the about dialog.

30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
1 /*
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
2 * LDForge: LDraw parts authoring CAD
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
4 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
5 * This program is free software: you can redistribute it and/or modify
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
6 * it under the terms of the GNU General Public License as published by
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
8 * (at your option) any later version.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
9 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
10 * This program is distributed in the hope that it will be useful,
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
13 * GNU General Public License for more details.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
14 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
15 * You should have received a copy of the GNU General Public License
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
17 */
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
18
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QtGui>
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QGLWidget>
46
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
21 #include <GL/glu.h>
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "common.h"
69
6790dea720a8 Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
23 #include "config.h"
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "file.h"
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "gldraw.h"
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "bbox.h"
52
d71226763607 Colorized polygons now appear colorized in the list view (unless disabled). GL rendered now draws transparent polygons properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
27 #include "colors.h"
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
28 #include "gui.h"
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
30 static double g_faObjectOffset[3];
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
31 static double g_StoredBBoxSize;
32
5d22b7ecf110 Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
32
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
33 static short g_dPulseTick = 0;
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
34 static const short g_dNumPulseTicks = 8;
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
35 static const short g_dPulseInterval = 65;
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
36
69
6790dea720a8 Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
37 cfg (str, gl_bgcolor, "#CCCCD9");
6790dea720a8 Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
38 cfg (str, gl_maincolor, "#707078");
6790dea720a8 Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
39 cfg (float, gl_maincolor_alpha, 1.0);
6790dea720a8 Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
40 cfg (int, gl_linethickness, 2);
6790dea720a8 Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
41 cfg (bool, gl_colorbfc, true);
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
42 cfg (bool, gl_selflash, false);
69
6790dea720a8 Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
43
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
44 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
46 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
47 GLRenderer::GLRenderer (QWidget* parent) {
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 parent = parent; // shhh, GCC
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
49 fRotX = fRotY = fRotZ = 0.0f;
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
50 fZoom = 1.0f;
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
51 bPicking = false;
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
52
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
53 qPulseTimer = new QTimer (this);
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
54 connect (qPulseTimer, SIGNAL (timeout ()), this, SLOT (slot_timerUpdate ()));
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
57 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
59 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
60 void GLRenderer::initializeGL () {
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 glLoadIdentity();
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 glMatrixMode (GL_MODELVIEW);
32
5d22b7ecf110 Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
63
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
64 setBackground ();
46
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
65
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
66 glEnable (GL_POLYGON_OFFSET_FILL);
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
67 glPolygonOffset (1.0f, 1.0f);
32
5d22b7ecf110 Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
68
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 glEnable (GL_DEPTH_TEST);
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 glShadeModel (GL_SMOOTH);
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 glEnable (GL_MULTISAMPLE);
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
46
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
73 glEnable (GL_BLEND);
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
74 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
75
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
76 glEnable (GL_LINE_SMOOTH);
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
77 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
78
53
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
79 glLineWidth (gl_linethickness);
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
80
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
81 setMouseTracking (true);
32
5d22b7ecf110 Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
82 compileObjects ();
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
85 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
87 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
88 QColor GLRenderer::getMainColor () {
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
89 QColor col (gl_maincolor.value.chars());
46
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
90
47
9dd536c1ce39 Made the GL renderer actually use the main color configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
91 if (!col.isValid ())
119
b93a64f5ee67 some GUI tweaks
Santeri Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
92 return QColor (0, 0, 0); // shouldn't happen
47
9dd536c1ce39 Made the GL renderer actually use the main color configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
93
105
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
94 col.setAlpha (gl_maincolor_alpha * 255.f);
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
95 return col;
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
96 }
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
97
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
98 // ------------------------------------------------------------------------- //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
99 void GLRenderer::setBackground () {
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
100 QColor col (gl_bgcolor.value.chars());
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
101
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
102 if (!col.isValid ())
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
103 return;
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
104
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
105 glClearColor (
47
9dd536c1ce39 Made the GL renderer actually use the main color configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
106 ((double)col.red()) / 255.0f,
9dd536c1ce39 Made the GL renderer actually use the main color configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
107 ((double)col.green()) / 255.0f,
9dd536c1ce39 Made the GL renderer actually use the main color configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
108 ((double)col.blue()) / 255.0f,
9dd536c1ce39 Made the GL renderer actually use the main color configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
109 1.0f);
32
5d22b7ecf110 Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
110 }
5d22b7ecf110 Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
111
120
607301744394 Rotation and rounding. Rotation needs work to get proper origin stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
112 // =============================================================================
607301744394 Rotation and rounding. Rotation needs work to get proper origin stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
607301744394 Rotation and rounding. Rotation needs work to get proper origin stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
114 // =============================================================================
67
d523a370a17a 57181.dat (Philo's model of the XL-motor) showcased a new problem.. there was no handling of unknown colors which led into crashes. Added stdout warnings, also added mid and dark stone colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
115 static vector<short> g_daWarnedColors;
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
116 void GLRenderer::setObjectColor (LDObject* obj) {
105
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
117 QColor qCol;
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
118
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
119 if (bPicking) {
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
120 // Make the color by the object's index color if we're picking, so we can
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
121 // make the index from the color we get from the picking results.
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
122 long i = obj->getIndex (g_CurrentFile);
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
123
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
124 // If we couldn't find the index, this object must not be from this file,
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
125 // therefore it must be an object inlined from another file through a
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
126 // subfile reference. Use the reference's index.
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
127 if (i == -1)
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
128 i = obj->topLevelParent ()->getIndex (g_CurrentFile);
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
129
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
130 // We should have the index now.
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
131 assert (i != -1);
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
132
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
133 // Calculate a color based from this index. This method caters for
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
134 // 16777216 objects. I don't think that'll be exceeded anytime soon. :)
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
135 // ATM biggest is 53588.dat with 12600 lines.
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
136 double r = i % 256;
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
137 double g = (i / 256) % 256;
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
138 double b = (i / (256 * 256)) % 256;
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
139
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
140 glColor3f (r / 255.f, g / 255.f, b / 255.f);
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
141 return;
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
142 }
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
143
67
d523a370a17a 57181.dat (Philo's model of the XL-motor) showcased a new problem.. there was no handling of unknown colors which led into crashes. Added stdout warnings, also added mid and dark stone colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
144 if (obj->dColor == -1)
d523a370a17a 57181.dat (Philo's model of the XL-motor) showcased a new problem.. there was no handling of unknown colors which led into crashes. Added stdout warnings, also added mid and dark stone colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
145 return;
d523a370a17a 57181.dat (Philo's model of the XL-motor) showcased a new problem.. there was no handling of unknown colors which led into crashes. Added stdout warnings, also added mid and dark stone colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
146
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
147 #if 0
54
60f328f352c9 Done the rendering end of the red/green BFC view
Santeri Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
148 if (gl_colorbfc &&
60f328f352c9 Done the rendering end of the red/green BFC view
Santeri Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
149 obj->getType () != OBJ_Line &&
60f328f352c9 Done the rendering end of the red/green BFC view
Santeri Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
150 obj->getType () != OBJ_CondLine)
60f328f352c9 Done the rendering end of the red/green BFC view
Santeri Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
151 {
62
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
152 if (bBackSide)
54
60f328f352c9 Done the rendering end of the red/green BFC view
Santeri Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
153 glColor4f (0.9f, 0.0f, 0.0f, 1.0f);
60f328f352c9 Done the rendering end of the red/green BFC view
Santeri Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
154 else
60f328f352c9 Done the rendering end of the red/green BFC view
Santeri Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
155 glColor4f (0.0f, 0.8f, 0.0f, 1.0f);
60f328f352c9 Done the rendering end of the red/green BFC view
Santeri Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
156 return;
60f328f352c9 Done the rendering end of the red/green BFC view
Santeri Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
157 }
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
158 #endif
54
60f328f352c9 Done the rendering end of the red/green BFC view
Santeri Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
159
105
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
160 if (obj->dColor == dMainColor)
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
161 qCol = getMainColor ();
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
162 else {
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
163 color* col = getColor (obj->dColor);
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
164
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
165 if (col != null)
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
166 qCol = col->qColor;
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
167 else {
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
168 // The color was unknown. Use main color to make the object at least
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
169 // not appear pitch-black.
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
170 qCol = getMainColor ();
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
171
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
172 // Warn about the unknown colors, but only once.
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
173 for (short i : g_daWarnedColors)
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
174 if (obj->dColor == i)
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
175 return;
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
176
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
177 printf ("%s: Unknown color %d!\n", __func__, obj->dColor);
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
178 g_daWarnedColors.push_back (obj->dColor);
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
179 return;
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
180 }
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
181 }
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
182
105
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
183 long r = qCol.red (),
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
184 g = qCol.green (),
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
185 b = qCol.blue (),
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
186 a = qCol.alpha ();
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
187
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
188 // If it's selected, brighten it up, also pulse flash it if desired.
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
189 if (g_ForgeWindow->isSelected (obj)) {
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
190 short dTick, dNumTicks;
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
191
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
192 if (gl_selflash) {
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
193 dTick = (g_dPulseTick < (g_dNumPulseTicks / 2)) ? g_dPulseTick : (g_dNumPulseTicks - g_dPulseTick);
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
194 dNumTicks = g_dNumPulseTicks;
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
195 } else {
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
196 dTick = 2;
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
197 dNumTicks = 5;
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
198 }
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
199
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
200 const long lAdd = ((dTick * 128) / dNumTicks);
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
201 r = min (r + lAdd, 255l);
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
202 g = min (g + lAdd, 255l);
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
203 b = min (b + lAdd, 255l);
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
204
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
205 // a = 255;
52
d71226763607 Colorized polygons now appear colorized in the list view (unless disabled). GL rendered now draws transparent polygons properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
206 }
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
207
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 70
diff changeset
208 glColor4f (
105
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
209 ((double) r) / 255.0f,
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
210 ((double) g) / 255.0f,
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
211 ((double) b) / 255.0f,
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
212 ((double) a) / 255.0f);
52
d71226763607 Colorized polygons now appear colorized in the list view (unless disabled). GL rendered now draws transparent polygons properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
213 }
d71226763607 Colorized polygons now appear colorized in the list view (unless disabled). GL rendered now draws transparent polygons properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
214
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
215 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
217 // ========================================================================= //
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
218 void GLRenderer::refresh () {
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
219 paintGL ();
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
220 swapBuffers ();
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
221 }
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
222
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
223 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
224 void GLRenderer::hardRefresh () {
32
5d22b7ecf110 Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
225 compileObjects ();
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
226 refresh ();
53
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
227
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
228 glLineWidth (gl_linethickness);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
231 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
233 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
234 void GLRenderer::resizeGL (int w, int h) {
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 glViewport (0, 0, w, h);
46
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
236 glLoadIdentity ();
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
237 glMatrixMode (GL_PROJECTION);
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
238 gluPerspective (45.0f, (double)w / (double)h, 0.1f, 100.0f);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
241 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
243 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
244 void GLRenderer::paintGL () {
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
46
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
246 glMatrixMode (GL_MODELVIEW);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
248 if (g_CurrentFile == null)
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
249 return;
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
250
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 glPushMatrix ();
46
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
252 glLoadIdentity ();
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
253
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
254 glTranslatef (0.0f, 0.0f, -5.0f);
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
255 glTranslatef (0.0f, 0.0f, -fZoom);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 glRotatef (fRotX, 1.0f, 0.0f, 0.0f);
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 glRotatef (fRotY, 0.0f, 1.0f, 0.0f);
53
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
259 glRotatef (fRotZ, 0.0f, 0.0f, 1.0f);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
261 for (LDObject* obj : g_CurrentFile->objects)
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
262 glCallList ((bPicking == false) ? obj->uGLList : obj->uGLPickList);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 glPopMatrix ();
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
266 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
268 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
269 void GLRenderer::compileObjects () {
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
270 uaObjLists.clear ();
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
271
53
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
272 g_faObjectOffset[0] = -(g_BBox.v0.x + g_BBox.v1.x) / 2;
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
273 g_faObjectOffset[1] = -(g_BBox.v0.y + g_BBox.v1.y) / 2;
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
274 g_faObjectOffset[2] = -(g_BBox.v0.z + g_BBox.v1.z) / 2;
121
7e87c85ad092 Rotation improvements; allow radials be inlined
Santeri Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
275 g_StoredBBoxSize = g_BBox.size ();
53
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
276
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 if (!g_CurrentFile) {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 printf ("renderer: no files loaded, cannot compile anything\n");
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 return;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
282 for (LDObject* obj : g_CurrentFile->objects) {
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
283 GLuint* upaLists[2] = {
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
284 &obj->uGLList,
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
285 &obj->uGLPickList
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
286 };
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
287
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
288 for (GLuint* upMemberList : upaLists) {
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
289 GLuint uList = glGenLists (1);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
290 glNewList (uList, GL_COMPILE);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
291
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
292 bPicking = (upMemberList == &obj->uGLPickList);
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
293 compileOneObject (obj);
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
294 bPicking = false;
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
295
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
296 glEndList ();
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
297 *upMemberList = uList;
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
298 }
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
299
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
300 uaObjLists.push_back (obj->uGLList);
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
301 }
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
304 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
305 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
306 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
307 template<class T> void GLRenderer::compileSubObject (LDObject* obj,
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
308 const GLenum eGLType, const short dVerts)
62
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
309 {
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
310 T* newobj = static_cast<T*> (obj);
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
311 glBegin (eGLType);
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
312
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
313 for (short i = 0; i < dVerts; ++i)
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
314 compileVertex (newobj->vaCoords[i]);
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
315
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
316 glEnd ();
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
317 }
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
318
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
319 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
321 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
322 void GLRenderer::compileOneObject (LDObject* obj) {
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
323 setObjectColor (obj);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 switch (obj->getType ()) {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 case OBJ_Line:
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
327 compileSubObject<LDLine> (obj, GL_LINES, 2);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328 break;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329
53
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
330 case OBJ_CondLine:
62
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
331 glLineStipple (1, 0x6666);
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
332 glEnable (GL_LINE_STIPPLE);
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
333
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
334 compileSubObject<LDCondLine> (obj, GL_LINES, 2);
62
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
335
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
336 glDisable (GL_LINE_STIPPLE);
53
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
337 break;
170cdffe1056 Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
338
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 case OBJ_Triangle:
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
340 compileSubObject<LDTriangle> (obj, GL_TRIANGLES, 3);
62
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
341 break;
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
342
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
343 case OBJ_Quad:
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
344 compileSubObject<LDQuad> (obj, GL_QUADS, 4);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 break;
62
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
346
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
347 case OBJ_Subfile:
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 {
62
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
349 LDSubfile* ref = static_cast<LDSubfile*> (obj);
111
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
350 vector<LDObject*> objs = ref->inlineContents (true, true);
62
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
351
111
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
352 for (LDObject* obj : objs) {
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
353 compileOneObject (obj);
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
354 delete obj;
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
355 }
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
356 }
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
357 break;
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
358
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
359 case OBJ_Radial:
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
360 {
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
361 LDRadial* pRadial = static_cast<LDRadial*> (obj);
125e8031dbf1 Added the radial type, this one sure has been on my wishlist for a while. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
362 std::vector<LDObject*> objs = pRadial->decompose (true);
62
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
363
70
e6b8dab8f81a Phased out FOREACH macro in favor of C++11-style for iteration.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 69
diff changeset
364 for (LDObject* obj : objs) {
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
365 compileOneObject (obj);
70
e6b8dab8f81a Phased out FOREACH macro in favor of C++11-style for iteration.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 69
diff changeset
366 delete obj;
66
12aca5d5a51e Restructured inlining to use a proper caching.. one cache per sub-file reference? What was I thinking? *whacks self with a 55295.dat*
Santeri Piippo <crimsondusk64@gmail.com>
parents: 64
diff changeset
367 }
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 break;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370
103
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
371 #if 0
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
372 TODO: find a proper way to draw vertices without having them be affected by zoom.
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
373 case OBJ_Vertex:
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
374 {
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
375 LDVertex* pVert = static_cast<LDVertex*> (obj);
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
376 LDTriangle* pPoly;
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
377 vertex* vPos = &(pVert->vPosition);
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
378 const double fPolyScale = max (fZoom, 1.0);
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
379
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
380 #define BIPYRAMID_COORD(N) ((((i + N) % 4) >= 2 ? 1 : -1) * 0.3f * fPolyScale)
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
381
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
382 for (int i = 0; i < 8; ++i) {
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
383 pPoly = new LDTriangle;
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
384 pPoly->vaCoords[0] = {vPos->x, vPos->y + ((i >= 4 ? 1 : -1) * 0.4f * fPolyScale), vPos->z};
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
385 pPoly->vaCoords[1] = {
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
386 vPos->x + BIPYRAMID_COORD (0),
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
387 vPos->y,
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
388 vPos->z + BIPYRAMID_COORD (1)
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
389 };
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
390
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
391 pPoly->vaCoords[2] = {
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
392 vPos->x + BIPYRAMID_COORD (1),
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
393 vPos->y,
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
394 vPos->z + BIPYRAMID_COORD (2)
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
395 };
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
396
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
397 pPoly->dColor = pVert->dColor;
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
398 compileOneObject (pPoly);
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
399 delete pPoly;
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
400 }
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
401 }
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
402 break;
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
403 #endif // 0
b0a345196435 Added the ability to add vertices to object corners
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
404
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 default:
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406 break;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
410 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
411 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
412 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
413 void GLRenderer::compileVertex (vertex& vrt) {
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
414 glVertex3d (
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
415 (vrt.x + g_faObjectOffset[0]) / g_StoredBBoxSize,
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
416 -(vrt.y + g_faObjectOffset[1]) / g_StoredBBoxSize,
62
915fc477cb6a Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
417 -(vrt.z + g_faObjectOffset[2]) / g_StoredBBoxSize);
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
418 }
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
419
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
420 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
421 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
422 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
423 void GLRenderer::clampAngle (double& fAngle) {
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 while (fAngle < 0)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 fAngle += 360.0;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426 while (fAngle > 360.0)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 fAngle -= 360.0;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
430 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
431 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
432 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
433 void GLRenderer::mouseReleaseEvent (QMouseEvent* event) {
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
434 if ((qMouseButtons & Qt::LeftButton) && !(event->buttons() & Qt::LeftButton)) {
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
435 if (ulTotalMouseMove < 10)
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
436 pick (event->x(), event->y(), (qKeyMods & Qt::ControlModifier));
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
437
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
438 ulTotalMouseMove = 0;
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
439 }
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
440 }
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
441
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
442 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
443 void GLRenderer::mousePressEvent (QMouseEvent* event) {
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
444 qMouseButtons = event->buttons();
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
445 if (event->buttons() & Qt::LeftButton)
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
446 ulTotalMouseMove = 0;
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
447 }
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
448
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
449 // ========================================================================= //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
450 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
451 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
452 void GLRenderer::mouseMoveEvent (QMouseEvent *event) {
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 int dx = event->x () - lastPos.x ();
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454 int dy = event->y () - lastPos.y ();
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
455 ulTotalMouseMove += abs (dx) + abs (dy);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457 if (event->buttons () & Qt::LeftButton) {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458 fRotX = fRotX + (dy);
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 fRotY = fRotY + (dx);
28
208adc847377 added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
460 clampAngle (fRotX);
208adc847377 added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
461 clampAngle (fRotY);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 if (event->buttons () & Qt::RightButton) {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465 fRotX = fRotX + (dy);
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466 fRotZ = fRotZ + (dx);
28
208adc847377 added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
467 clampAngle (fRotX);
208adc847377 added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
468 clampAngle (fRotZ);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471 if (event->buttons () & Qt::MidButton) {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472 fZoom += (dy / 100.0);
46
69962c85f717 Finally got the renderer to actually draw something! Still needs a lot of work but at least it doesn't show garbage or blank anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
473 fZoom = clamp (fZoom, 0.01, 100.0);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476 lastPos = event->pos();
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 updateGL ();
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
478 }
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
479
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
480 // ========================================================================= //
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
481 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
482 // ========================================================================= //
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
483 void GLRenderer::keyPressEvent (QKeyEvent* qEvent) {
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
484 qKeyMods = qEvent->modifiers ();
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
485 }
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
486
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
487 void GLRenderer::keyReleaseEvent (QKeyEvent* qEvent) {
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
488 qKeyMods = qEvent->modifiers ();
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
489 }
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
490
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
491 // ========================================================================= //
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
492 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
493 // ========================================================================= //
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
494 void GLRenderer::updateSelFlash () {
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
495 if (gl_selflash && g_ForgeWindow->paSelection.size() > 0) {
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
496 qPulseTimer->start (g_dPulseInterval);
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
497 g_dPulseTick = 0;
109
f40b35142586 Improved shared selection handling; added select by color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 108
diff changeset
498 } else
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
499 qPulseTimer->stop ();
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
500 }
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
501
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
502 // ========================================================================= //
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
503 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
504 // ========================================================================= //
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
505 void GLRenderer::pick (uint uMouseX, uint uMouseY, bool bAdd) {
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
506 if (bAdd == false) {
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
507 // Clear the selection if we don't wish to add to it.
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
508 std::vector<LDObject*> paOldSelection = g_ForgeWindow->paSelection;
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
509 g_ForgeWindow->paSelection.clear ();
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
510
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
511 // Recompile the prior selection to remove the highlight color
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
512 for (LDObject* obj : paOldSelection)
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
513 recompileObject (obj);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
514 }
105
53f95a6e351d Highlight selected objects with a different color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 104
diff changeset
515
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
516 glDisable (GL_DITHER);
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
517 glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
518
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
519 bPicking = true;
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
520
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
521 paintGL ();
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
522
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
523 GLubyte ucaPixel[3];
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
524 GLint daViewport[4];
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
525 glGetIntegerv (GL_VIEWPORT, daViewport);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
526 glReadPixels (uMouseX, daViewport[3] - uMouseY, 1, 1, GL_RGB, GL_UNSIGNED_BYTE,
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
527 reinterpret_cast<GLvoid*> (ucaPixel));
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
528
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
529 // If we hit a white pixel, we selected the background. This no object is selected.
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
530 const bool bHasSelection = (ucaPixel[0] != 255 || ucaPixel[1] != 255 || ucaPixel[2] != 255);
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
531
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
532 if (bHasSelection) {
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
533 ulong idx = ucaPixel[0] + (ucaPixel[1] * 256) + (ucaPixel[2] * 256 * 256);
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
534
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
535 LDObject* obj = g_CurrentFile->object (idx);
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
536 g_ForgeWindow->paSelection.push_back (obj);
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
537 }
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
538
109
f40b35142586 Improved shared selection handling; added select by color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 108
diff changeset
539 g_ForgeWindow->buildObjList ();
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
540
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
541 bPicking = false;
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
542 glEnable (GL_DITHER);
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
543
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 103
diff changeset
544 setBackground ();
108
351aef26f444 More selection work - selecting from GUI updates the GL renderer now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
545 updateSelFlash ();
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
546
109
f40b35142586 Improved shared selection handling; added select by color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 108
diff changeset
547 for (LDObject* obj : g_ForgeWindow->selection ())
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
548 recompileObject (obj);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
549
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
550 paintGL ();
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
551 swapBuffers ();
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
552 }
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
553
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
554 // ========================================================================= //
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
556 // ========================================================================= //
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
557 void GLRenderer::recompileObject (LDObject* obj) {
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
558 // Replace the old list with the new one.
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
559 for (ulong i = 0; i < uaObjLists.size(); ++i)
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
560 if (uaObjLists[i] == obj->uGLList)
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
561 uaObjLists.erase (uaObjLists.begin() + i);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
562
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
563 GLuint uList = glGenLists (1);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
564 glNewList (uList, GL_COMPILE);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
565
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
566 compileOneObject (obj);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
567
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
568 glEndList ();
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
569 uaObjLists.push_back (uList);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
570 obj->uGLList = uList;
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
571 }
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
572
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
573 // ========================================================================= //
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
574 void GLRenderer::slot_timerUpdate () {
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
575 ++g_dPulseTick %= g_dNumPulseTicks;
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
576
109
f40b35142586 Improved shared selection handling; added select by color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 108
diff changeset
577 for (LDObject* obj : g_ForgeWindow->selection ())
107
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
578 recompileObject (obj);
195aa036da7f Picking improvements
Santeri Piippo <crimsondusk64@gmail.com>
parents: 106
diff changeset
579
106
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
580 paintGL ();
46e4202a44fc Added additive selection blending, with a toggable flash effect. :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
581 swapBuffers ();
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
582 }

mercurial