eqemu-server/zone/oriented_bounding_box.cpp
Knightly 7ab909ee47 Standardize Licensing
- License was intended to be GPLv3 per earlier commit of GPLv3 LICENSE FILE
- This is confirmed by the inclusion of libraries that are incompatible with GPLv2
- This is also confirmed by KLS and the agreement of KLS's predecessors
- Added GPLv3 license headers to the compilable source files
- Removed Folly licensing in strings.h since the string functions do not match the Folly functions and are standard functions - this must have been left over from previous implementations
- Removed individual contributor license headers since the project has been under the "developer" mantle for many years
- Removed comments on files that were previously automatically generated since they've been manually modified multiple times and there are no automatic scripts referencing them (removed in 2023)
2026-04-01 17:09:57 -07:00

115 lines
2.7 KiB
C++

/* EQEmu: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "oriented_bounding_box.h"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtx/transform.hpp"
glm::mat4 CreateRotateMatrix(float rx, float ry, float rz) {
glm::mat4 rot_x(1.0f);
rot_x[1][1] = cos(rx);
rot_x[2][1] = -sin(rx);
rot_x[1][2] = sin(rx);
rot_x[2][2] = cos(rx);
glm::mat4 rot_y(1.0f);
rot_y[0][0] = cos(ry);
rot_y[2][0] = sin(ry);
rot_y[0][2] = -sin(ry);
rot_y[2][2] = cos(ry);
glm::mat4 rot_z(1.0f);
rot_z[0][0] = cos(rz);
rot_z[1][0] = -sin(rz);
rot_z[0][1] = sin(rz);
rot_z[1][1] = cos(rz);
return rot_z * rot_y * rot_x;
}
glm::mat4 CreateTranslateMatrix(float tx, float ty, float tz) {
glm::mat4 trans(1.0f);
trans[3][0] = tx;
trans[3][1] = ty;
trans[3][2] = tz;
return trans;
}
glm::mat4 CreateScaleMatrix(float sx, float sy, float sz) {
glm::mat4 scale(1.0f);
scale[0][0] = sx;
scale[1][1] = sy;
scale[2][2] = sz;
return scale;
}
OrientedBoundingBox::OrientedBoundingBox(const glm::vec3 &pos, const glm::vec3 &rot, const glm::vec3 &scale, const glm::vec3 &extents) {
min_x = -extents.x;
max_x = extents.x;
if (min_x > max_x)
{
float t = min_x;
min_x = max_x;
max_x = t;
}
min_y = -extents.y;
max_y = extents.y;
if (min_y > max_y)
{
float t = min_y;
min_y = max_y;
max_y = t;
}
min_z = -extents.z;
max_z = extents.z;
if (min_z > max_z)
{
float t = min_z;
min_z = max_z;
max_z = t;
}
//rotate
transformation = CreateRotateMatrix(rot.x * 3.14159f / 180.0f, rot.y * 3.14159f / 180.0f, rot.z * 3.14159f / 180.0f);
//scale
transformation = CreateScaleMatrix(scale.x, scale.y, scale.z) * transformation;
//translate
transformation = CreateTranslateMatrix(pos.x, pos.y, pos.z) * transformation;
inverted_transformation = glm::inverse(transformation);
}
bool OrientedBoundingBox::ContainsPoint(const glm::vec3 &p) const {
glm::vec4 pt(p.x, p.y, p.z, 1);
glm::vec4 box_space_p = inverted_transformation * pt;
if (box_space_p.x >= min_x && box_space_p.x <= max_x &&
box_space_p.y >= min_y && box_space_p.y <= max_y &&
box_space_p.z >= min_z && box_space_p.z <= max_z) {
return true;
}
return false;
}