bbox.cpp

Wed, 20 Mar 2013 03:25:49 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 20 Mar 2013 03:25:49 +0200
changeset 44
4c2fdadb9262
parent 40
215b9f8f0cd7
child 60
961663d05463
permissions
-rw-r--r--

With removal of vectors, I don't need to keep the bearing class around either

30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
1 /*
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
2 * LDForge: LDraw parts authoring CAD
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
3 * Copyright (C) 2013 Santeri `arezey` Piippo
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
4 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
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: 26
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: 26
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: 26
diff changeset
8 * (at your option) any later version.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
9 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
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: 26
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: 26
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: 26
diff changeset
13 * GNU General Public License for more details.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
14 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
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: 26
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: 26
diff changeset
17 */
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
18
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include "common.h"
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "bbox.h"
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "ldtypes.h"
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 7
diff changeset
22 #include "file.h"
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 void bbox::calculate () {
3
2b78cf8634c3 don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
25 if (!g_CurrentFile)
2b78cf8634c3 don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
26 return;
2b78cf8634c3 don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
27
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 // The bounding box, bbox for short, is the
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 // box that encompasses the model we have open.
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 // v0 is the minimum vertex, v1 is the maximum vertex.
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 for (uint i = 0; i < g_CurrentFile->objects.size(); i++) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 LDObject* obj = g_CurrentFile->objects[i];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 switch (obj->getType ()) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 case OBJ_Line:
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 LDLine* line = static_cast<LDLine*> (obj);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 for (short i = 0; i < 2; ++i)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 checkVertex (line->vaCoords[i]);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 break;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 case OBJ_Triangle:
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 LDTriangle* tri = static_cast<LDTriangle*> (obj);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 for (short i = 0; i < 3; ++i)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 checkVertex (tri->vaCoords[i]);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 break;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 case OBJ_Quad:
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 LDQuad* quad = static_cast<LDQuad*> (obj);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 for (short i = 0; i < 4; ++i)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 checkVertex (quad->vaCoords[i]);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 break;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 case OBJ_CondLine:
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 LDCondLine* line = static_cast<LDCondLine*> (obj);
40
215b9f8f0cd7 Added triangle, quad and condline to the add object dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
62 for (short i = 0; i < 4; ++i)
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 checkVertex (line->vaCoords[i]);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 break;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 default:
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 break;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 #define CHECK_DIMENSION(V,X) \
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 if (V.X < v0.X) v0.X = V.X; \
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 if (V.X > v1.X) v1.X = V.X;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 void bbox::checkVertex (vertex v) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 CHECK_DIMENSION (v, x)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 CHECK_DIMENSION (v, y)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 CHECK_DIMENSION (v, z)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 #undef CHECK_DIMENSION
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 bbox::bbox () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 memset (&v0, 0, sizeof v0);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 memset (&v1, 0, sizeof v1);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 }

mercurial