1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "bladerunner/boundingbox.h"
24 
25 #include "bladerunner/savefile.h"
26 
27 namespace BladeRunner {
28 
29 // TO VERIFY
30 // First vertex is typically the bottom left point (x0, y0, z0)
31 // and second vertex is the top right (x1, y1, z1)
32 // Hence, we also assume that x0 < x1, y0 < y1 and z0 < z1 (ie. see how the inside() method makes its calculation)
33 // TODO Maybe add a check here to catch any exceptions?
BoundingBox(float x0,float y0,float z0,float x1,float y1,float z1)34 BoundingBox::BoundingBox(float x0, float y0, float z0, float x1, float y1, float z1) {
35 	_vertices[0].x = x0;
36 	_vertices[0].y = y0;
37 	_vertices[0].z = z0;
38 
39 	_vertices[1].x = x1;
40 	_vertices[1].y = y1;
41 	_vertices[1].z = z1;
42 }
43 
expand(float x0,float y0,float z0,float x1,float y1,float z1)44 void BoundingBox::expand(float x0, float y0, float z0, float x1, float y1, float z1) {
45 	_vertices[0].x += x0;
46 	_vertices[0].y += y0;
47 	_vertices[0].z += z0;
48 
49 	_vertices[1].x += x1;
50 	_vertices[1].y += y1;
51 	_vertices[1].z += z1;
52 }
53 
inside(float x,float y,float z) const54 bool BoundingBox::inside(float x, float y, float z) const {
55 	return x >= _vertices[0].x && x <= _vertices[1].x
56 	    && y >= _vertices[0].y && y <= _vertices[1].y
57 	    && z >= _vertices[0].z && z <= _vertices[1].z;
58 }
59 
inside(Vector3 & position) const60 bool BoundingBox::inside(Vector3 &position) const {
61 	return inside(position.x, position.y, position.z);
62 }
63 
setXYZ(float x0,float y0,float z0,float x1,float y1,float z1)64 void BoundingBox::setXYZ(float x0, float y0, float z0, float x1, float y1, float z1) {
65 	_vertices[0].x = x0;
66 	_vertices[0].y = y0;
67 	_vertices[0].z = z0;
68 
69 	_vertices[1].x = x1;
70 	_vertices[1].y = y1;
71 	_vertices[1].z = z1;
72 }
73 
getXYZ(float * x0,float * y0,float * z0,float * x1,float * y1,float * z1) const74 void BoundingBox::getXYZ(float *x0, float *y0, float *z0, float *x1, float *y1, float *z1) const {
75 	*x0 = _vertices[0].x;
76 	*y0 = _vertices[0].y;
77 	*z0 = _vertices[0].z;
78 
79 	*x1 = _vertices[1].x;
80 	*y1 = _vertices[1].y;
81 	*z1 = _vertices[1].z;
82 }
83 
getZ0() const84 float BoundingBox::getZ0() const {
85 	return _vertices[0].z;
86 }
87 
getZ1() const88 float BoundingBox::getZ1() const {
89 	return _vertices[1].z;
90 }
91 
92 } // End of namespace BladeRunner
93