SuperTuxKart
Loading...
Searching...
No Matches
bounding_box_3d.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2016 SuperTuxKart-Team
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_NODE_BOUNDING_BOX_3D_HPP
20#define HEADER_NODE_BOUNDING_BOX_3D_HPP
21
22#include "utils/vec3.hpp"
23
28{
29private:
33
34public:
35 // ------------------------------------------------------------------------
36 BoundingBox3D(const Vec3& p0, const Vec3& p1, const Vec3& p2,
37 const Vec3& p3, const Vec3& normal)
38 {
39 // Compute the node bounding box used by pointInside
40 Vec3 box_corners[8];
41 float box_high = 5.0f;
42 float box_low = 1.0f;
43 box_corners[0] = p0 + box_high * normal;
44 box_corners[1] = p1 + box_high * normal;
45 box_corners[2] = p2 + box_high * normal;
46 box_corners[3] = p3 + box_high * normal;
47 box_corners[4] = p0 - box_low * normal;
48 box_corners[5] = p1 - box_low * normal;
49 box_corners[6] = p2 - box_low * normal;
50 box_corners[7] = p3 - box_low * normal;
51
52 Vec3 box_faces[6][4] =
53 {
54 { box_corners[0], box_corners[1], box_corners[2], box_corners[3] },
55 { box_corners[3], box_corners[2], box_corners[6], box_corners[7] },
56 { box_corners[7], box_corners[6], box_corners[5], box_corners[4] },
57 { box_corners[1], box_corners[0], box_corners[4], box_corners[5] },
58 { box_corners[4], box_corners[0], box_corners[3], box_corners[7] },
59 { box_corners[1], box_corners[5], box_corners[6], box_corners[2] }
60 };
61
62 for (unsigned int i = 0; i < 6 ; i++)
63 {
64 for (unsigned int j = 0; j < 4; j++)
65 m_box_faces[i][j] = box_faces[i][j];
66 }
67 }
68 // ------------------------------------------------------------------------
69 bool pointInside(const Vec3& p, bool ignore_vertical = false) const
70 {
71 float side = p.sideofPlane(m_box_faces[0][0], m_box_faces[0][1],
72 m_box_faces[0][2]);
73 for (int i = 1; i < 6; i++)
74 {
75 if (side * p.sideofPlane(m_box_faces[i][0], m_box_faces[i][1],
76 m_box_faces[i][2]) < 0)
77 return false;
78 }
79 return true;
80 }
81
82};
83
84#endif
Definition: bounding_box_3d.hpp:28
Vec3 m_box_faces[6][4]
A 3D box using to check if a point lies inside a quad.
Definition: bounding_box_3d.hpp:32
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35