From d78d3024cc0b6e92b31d9f60c46f5cbcf44c8898 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Thu, 14 Dec 2017 00:28:35 +0100 Subject: [PATCH] util-math: Add commonly used mathematical functions --- CMakeLists.txt | 2 ++ source/util-math.cpp | 21 +++++++++++++++++++++ source/util-math.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 source/util-math.cpp create mode 100644 source/util-math.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b8f14e7..ac44b589 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ SET(obs-stream-effects_HEADERS "${PROJECT_SOURCE_DIR}/source/gs-mipmapper.h" "${PROJECT_BINARY_DIR}/source/version.h" "${PROJECT_SOURCE_DIR}/source/strings.h" + "${PROJECT_SOURCE_DIR}/source/util-math.h" ) SET(obs-stream-effects_SOURCES "${PROJECT_SOURCE_DIR}/source/plugin.cpp" @@ -63,6 +64,7 @@ SET(obs-stream-effects_SOURCES "${PROJECT_SOURCE_DIR}/source/gs-vertex.cpp" "${PROJECT_SOURCE_DIR}/source/gs-vertexbuffer.cpp" "${PROJECT_SOURCE_DIR}/source/gs-mipmapper.cpp" + "${PROJECT_SOURCE_DIR}/source/util-math.cpp" ) SET(obs-stream-effects_LOCALE "${PROJECT_SOURCE_DIR}/data/locale/en-US.ini" diff --git a/source/util-math.cpp b/source/util-math.cpp new file mode 100644 index 00000000..4e5d3c92 --- /dev/null +++ b/source/util-math.cpp @@ -0,0 +1,21 @@ +/* +* Modern effects for a modern Streamer +* Copyright (C) 2017 Michael Fabian Dirks +* +* 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 2 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, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + +#include "util-math.h" + diff --git a/source/util-math.h b/source/util-math.h new file mode 100644 index 00000000..c48d98dc --- /dev/null +++ b/source/util-math.h @@ -0,0 +1,33 @@ +/* +* Modern effects for a modern Streamer +* Copyright (C) 2017 Michael Fabian Dirks +* +* 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 2 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, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + +#pragma once +#include +#include + +#define PI 3.1415926535897932384626433832795 +#define PI2 6.283185307179586476925286766559 +#define PI2_SQROOT 2.506628274631000502415765284811 + +inline double_t Gaussian1D(double_t x, double_t o) { + double_t c = (x / o); + double_t b = exp(-0.5 * c * c); + double_t a = (1.0 / (o * PI2_SQROOT)); + return a * b; +}