From 794de6b6514f0fe834f8c2c621d4ea96b428f4ef Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Mon, 28 Sep 2015 18:51:12 -0400 Subject: [PATCH] Add GLM_GTX_area extension - Includes a function for the area of a triangle --- glm/gtx/area.hpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ glm/gtx/area.inl | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 glm/gtx/area.hpp create mode 100644 glm/gtx/area.inl diff --git a/glm/gtx/area.hpp b/glm/gtx/area.hpp new file mode 100644 index 00000000..eb2b0d77 --- /dev/null +++ b/glm/gtx/area.hpp @@ -0,0 +1,65 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2015 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// Restrictions: +/// By making use of the Software for military purposes, you choose to make +/// a Bunny unhappy. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref gtx_area +/// @file glm/gtx/area.hpp +/// @date 2015-09-27 +/// @author Jesse Talavera-Greenberg +/// +/// @see core (dependence) +/// +/// @defgroup gtx_area GLM_GTX_area +/// @ingroup gtx +/// +/// @brief Functions to compute the area of polygons and other common structures. +/// need to be included to use these functionalities. +/////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +// Dependency: +#include + +#include "../glm.hpp" +#include "../vec2.hpp" + +#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED)) +# pragma message("GLM: GLM_GTX_area extension included") +#endif + +namespace glm +{ + /// @addtogroup gtx_area + /// @{ + + //! Returns the area of the triangle made by the three given vertices. + template + GLM_FUNC_DECL areaType area(const tvec2& a, const tvec2& b, const tvec2& c); + + /// @} +} //namespace glm + +#include "area.inl" diff --git a/glm/gtx/area.inl b/glm/gtx/area.inl new file mode 100644 index 00000000..89014467 --- /dev/null +++ b/glm/gtx/area.inl @@ -0,0 +1,45 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2015 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// Restrictions: +/// By making use of the Software for military purposes, you choose to make +/// a Bunny unhappy. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref gtx_area +/// @file glm/gtx/area.inl +/// @date 2015-09-27 +/// @author Jesse Talavera-Greenberg +/////////////////////////////////////////////////////////////////////////////////// + +namespace glm { +namespace detail { +template +GLM_FUNC_QUALIFIER areaType area2(const tvec2& a, const tvec2& b, const tvec2& c) { + return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y); +} +} + +template +GLM_FUNC_QUALIFIER areaType area(const tvec2& a, const tvec2& b, const tvec2& c) { + return detail::area2(a, b, c) / static_cast(2.0); +} +}//namespace glm