2015-08-22 14:40:02 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
2021-09-11 13:52:34 +00:00
|
|
|
* Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam
|
2015-08-22 14:40:02 +00:00
|
|
|
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
|
|
|
*
|
|
|
|
* 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://gnu.org/licenses
|
|
|
|
*/
|
2015-08-22 15:51:39 +00:00
|
|
|
|
2015-07-10 07:26:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-01-04 19:43:36 +00:00
|
|
|
#include <glm/glm.hpp>
|
2015-07-10 07:26:38 +00:00
|
|
|
|
2015-08-02 09:40:47 +00:00
|
|
|
namespace Math
|
|
|
|
{
|
2015-07-10 07:26:38 +00:00
|
|
|
|
|
|
|
struct Sphere
|
|
|
|
{
|
2022-01-04 19:43:36 +00:00
|
|
|
Sphere(const glm::vec3& pos = glm::vec3(0, 0, 0), float radius = 0.0f)
|
2015-07-10 07:26:38 +00:00
|
|
|
: pos(pos), radius(radius) {}
|
|
|
|
|
2022-01-04 00:39:55 +00:00
|
|
|
glm::vec3 pos;
|
2015-07-10 07:26:38 +00:00
|
|
|
float radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Compute distance between given \a point and \a sphere
|
2022-01-04 00:39:55 +00:00
|
|
|
inline float DistanceToSphere(const glm::vec3& point, const Sphere& sphere)
|
2015-07-10 07:26:38 +00:00
|
|
|
{
|
2022-01-04 19:43:36 +00:00
|
|
|
return glm::distance(point, sphere.pos) - sphere.radius;
|
2015-07-10 07:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline float DistanceBetweenSpheres(const Sphere& sphere1, const Sphere& sphere2)
|
|
|
|
{
|
2022-01-04 19:43:36 +00:00
|
|
|
return glm::distance(sphere1.pos, sphere2.pos) - sphere1.radius - sphere2.radius;
|
2015-07-10 07:26:38 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 00:39:55 +00:00
|
|
|
inline Sphere BoundingSphereForBox(glm::vec3 mins, glm::vec3 maxs)
|
2018-04-29 17:05:19 +00:00
|
|
|
{
|
|
|
|
auto centroid = (maxs + mins) / 2.0f;
|
|
|
|
auto halfExtent = (maxs - centroid);
|
2021-12-28 22:01:30 +00:00
|
|
|
return Sphere{centroid, glm::length(halfExtent)};
|
2018-04-29 17:05:19 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 07:26:38 +00:00
|
|
|
} // namespace Math
|