Sat, 16 Mar 2013 03:12:31 +0200
oops, forgot the new dialog files out
0 | 1 | #include "common.h" |
2 | #include "bbox.h" | |
3 | #include "ldtypes.h" | |
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
4 | #include "io.h" |
0 | 5 | |
6 | void bbox::calculate () { | |
3
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
7 | if (!g_CurrentFile) |
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
8 | return; |
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
9 | |
0 | 10 | // The bounding box, bbox for short, is the |
11 | // box that encompasses the model we have open. | |
12 | // v0 is the minimum vertex, v1 is the maximum vertex. | |
13 | for (uint i = 0; i < g_CurrentFile->objects.size(); i++) { | |
14 | LDObject* obj = g_CurrentFile->objects[i]; | |
15 | switch (obj->getType ()) { | |
16 | ||
17 | case OBJ_Line: | |
18 | { | |
19 | LDLine* line = static_cast<LDLine*> (obj); | |
20 | for (short i = 0; i < 2; ++i) | |
21 | checkVertex (line->vaCoords[i]); | |
22 | } | |
23 | break; | |
24 | ||
25 | case OBJ_Triangle: | |
26 | { | |
27 | LDTriangle* tri = static_cast<LDTriangle*> (obj); | |
28 | for (short i = 0; i < 3; ++i) | |
29 | checkVertex (tri->vaCoords[i]); | |
30 | } | |
31 | break; | |
32 | ||
33 | case OBJ_Quad: | |
34 | { | |
35 | LDQuad* quad = static_cast<LDQuad*> (obj); | |
36 | for (short i = 0; i < 4; ++i) | |
37 | checkVertex (quad->vaCoords[i]); | |
38 | } | |
39 | break; | |
40 | ||
41 | case OBJ_CondLine: | |
42 | { | |
43 | LDCondLine* line = static_cast<LDCondLine*> (obj); | |
44 | for (short i = 0; i < 2; ++i) { | |
45 | checkVertex (line->vaCoords[i]); | |
46 | checkVertex (line->vaControl[i]); | |
47 | } | |
48 | } | |
49 | break; | |
50 | ||
51 | default: | |
52 | break; | |
53 | } | |
54 | } | |
55 | } | |
56 | ||
57 | #define CHECK_DIMENSION(V,X) \ | |
58 | if (V.X < v0.X) v0.X = V.X; \ | |
59 | if (V.X > v1.X) v1.X = V.X; | |
60 | void bbox::checkVertex (vertex v) { | |
61 | CHECK_DIMENSION (v, x) | |
62 | CHECK_DIMENSION (v, y) | |
63 | CHECK_DIMENSION (v, z) | |
64 | } | |
65 | #undef CHECK_DIMENSION | |
66 | ||
67 | bbox::bbox () { | |
68 | memset (&v0, 0, sizeof v0); | |
69 | memset (&v1, 0, sizeof v1); | |
70 | } |