Changeset View
Changeset View
Standalone View
Standalone View
extern/audaspace/include/util/Math3D.h
- This file was moved from intern/audaspace/intern/AUD_3DMath.h.
| /* | /******************************************************************************* | ||||
| * ***** BEGIN GPL LICENSE BLOCK ***** | * Copyright 2009-2016 Jörg Müller | ||||
| * | * | ||||
| * Copyright 2009-2011 Jörg Hermann Müller | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | * | ||||
| * This file is part of AudaSpace. | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
| * | * | ||||
| * Audaspace is free software; you can redistribute it and/or modify | * Unless required by applicable law or agreed to in writing, software | ||||
| * it under the terms of the GNU General Public License as published by | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| * the Free Software Foundation; either version 2 of the License, or | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * (at your option) any later version. | * See the License for the specific language governing permissions and | ||||
| * | * limitations under the License. | ||||
| * AudaSpace 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 Audaspace; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * ***** END GPL LICENSE BLOCK ***** | |||||
| */ | |||||
| /** \file audaspace/intern/AUD_3DMath.h | #pragma once | ||||
| * \ingroup audaspaceintern | |||||
| */ | |||||
| /** | |||||
| * @file Math3D.h | |||||
| * @ingroup util | |||||
| * Defines the Vector3 and Quaternion classes. | |||||
| */ | |||||
| #ifndef __AUD_3DMATH_H__ | #include "Audaspace.h" | ||||
| #define __AUD_3DMATH_H__ | |||||
| #include <cmath> | #include <cmath> | ||||
| #include <cstring> | #include <cstring> | ||||
| AUD_NAMESPACE_BEGIN | |||||
| /** | /** | ||||
| * This class represents a 3 dimensional vector. | * This class represents a 3 dimensional vector. | ||||
| */ | */ | ||||
| class AUD_Vector3 | class AUD_API Vector3 | ||||
| { | { | ||||
| private: | private: | ||||
| /** | /** | ||||
| Context not available. | |||||
| * \param y The y component. | * \param y The y component. | ||||
| * \param z The z component. | * \param z The z component. | ||||
| */ | */ | ||||
| inline AUD_Vector3(float x = 0, float y = 0, float z = 0) : | inline Vector3(float x = 0, float y = 0, float z = 0) : | ||||
| m_x(x), m_y(y), m_z(z) | m_x(x), m_y(y), m_z(z) | ||||
| { | { | ||||
| } | } | ||||
| Context not available. | |||||
| */ | */ | ||||
| inline void get(float* destination) const | inline void get(float* destination) const | ||||
| { | { | ||||
| memcpy(destination, m_v, sizeof(m_v)); | std::memcpy(destination, m_v, sizeof(m_v)); | ||||
| } | } | ||||
| /** | /** | ||||
| Context not available. | |||||
| */ | */ | ||||
| inline float length() const | inline float length() const | ||||
| { | { | ||||
| return sqrt(m_x*m_x + m_y*m_y + m_z*m_z); | return std::sqrt(m_x*m_x + m_y*m_y + m_z*m_z); | ||||
| } | } | ||||
| /** | /** | ||||
| Context not available. | |||||
| * \param op The second operand. | * \param op The second operand. | ||||
| * \return The cross product of the two vectors. | * \return The cross product of the two vectors. | ||||
| */ | */ | ||||
| inline AUD_Vector3 cross(const AUD_Vector3& op) const | inline Vector3 cross(const Vector3& op) const | ||||
| { | { | ||||
| return AUD_Vector3(m_y * op.m_z - m_z * op.m_y, | return Vector3(m_y * op.m_z - m_z * op.m_y, | ||||
| m_z * op.m_x - m_x * op.m_z, | m_z * op.m_x - m_x * op.m_z, | ||||
| m_x * op.m_y - m_y * op.m_x); | m_x * op.m_y - m_y * op.m_x); | ||||
| } | } | ||||
| /** | /** | ||||
| Context not available. | |||||
| * \param op The second operand. | * \param op The second operand. | ||||
| * \return The dot product of the two vectors. | * \return The dot product of the two vectors. | ||||
| */ | */ | ||||
| inline float operator*(const AUD_Vector3& op) const | inline float operator*(const Vector3& op) const | ||||
| { | { | ||||
| return m_x * op.m_x + m_y * op.m_y + m_z * op.m_z; | return m_x * op.m_x + m_y * op.m_y + m_z * op.m_z; | ||||
| } | } | ||||
| Context not available. | |||||
| * \param op The second operand. | * \param op The second operand. | ||||
| * \return The scaled vector. | * \return The scaled vector. | ||||
| */ | */ | ||||
| inline AUD_Vector3 operator*(const float& op) const | inline Vector3 operator*(const float& op) const | ||||
| { | { | ||||
| return AUD_Vector3(m_x * op, m_y * op, m_z * op); | return Vector3(m_x * op, m_y * op, m_z * op); | ||||
| } | } | ||||
| /** | /** | ||||
| Context not available. | |||||
| * \param op The second operand. | * \param op The second operand. | ||||
| * \return The sum vector. | * \return The sum vector. | ||||
| */ | */ | ||||
| inline AUD_Vector3 operator+(const AUD_Vector3& op) const | inline Vector3 operator+(const Vector3& op) const | ||||
| { | { | ||||
| return AUD_Vector3(m_x + op.m_x, m_y + op.m_y, m_z + op.m_z); | return Vector3(m_x + op.m_x, m_y + op.m_y, m_z + op.m_z); | ||||
| } | } | ||||
| /** | /** | ||||
| Context not available. | |||||
| * \param op The second operand. | * \param op The second operand. | ||||
| * \return The difference vector. | * \return The difference vector. | ||||
| */ | */ | ||||
| inline AUD_Vector3 operator-(const AUD_Vector3& op) const | inline Vector3 operator-(const Vector3& op) const | ||||
| { | { | ||||
| return AUD_Vector3(m_x - op.m_x, m_y - op.m_y, m_z - op.m_z); | return Vector3(m_x - op.m_x, m_y - op.m_y, m_z - op.m_z); | ||||
| } | } | ||||
| /** | /** | ||||
| * Negates the vector. | * Negates the vector. | ||||
| * \return The vector facing in the opposite direction. | * \return The vector facing in the opposite direction. | ||||
| */ | */ | ||||
| inline AUD_Vector3 operator-() const | inline Vector3 operator-() const | ||||
| { | { | ||||
| return AUD_Vector3(-m_x, -m_y, -m_z); | return Vector3(-m_x, -m_y, -m_z); | ||||
| } | } | ||||
| /** | /** | ||||
| Context not available. | |||||
| * \param op The second operand. | * \param op The second operand. | ||||
| * \return The difference vector. | * \return The difference vector. | ||||
| */ | */ | ||||
| inline AUD_Vector3& operator-=(const AUD_Vector3& op) | inline Vector3& operator-=(const Vector3& op) | ||||
| { | { | ||||
| m_x -= op.m_x; | m_x -= op.m_x; | ||||
| m_y -= op.m_y; | m_y -= op.m_y; | ||||
| Context not available. | |||||
| /** | /** | ||||
| * This class represents a quaternion used for 3D rotations. | * This class represents a quaternion used for 3D rotations. | ||||
| */ | */ | ||||
| class AUD_Quaternion | class AUD_API Quaternion | ||||
| { | { | ||||
| private: | private: | ||||
| /** | /** | ||||
| Context not available. | |||||
| * \param y The y component. | * \param y The y component. | ||||
| * \param z The z component. | * \param z The z component. | ||||
| */ | */ | ||||
| inline AUD_Quaternion(float w = 1, float x = 0, float y = 0, float z = 0) : | inline Quaternion(float w = 1, float x = 0, float y = 0, float z = 0) : | ||||
| m_w(w), m_x(x), m_y(y), m_z(z) | m_w(w), m_x(x), m_y(y), m_z(z) | ||||
| { | { | ||||
| } | } | ||||
| Context not available. | |||||
| */ | */ | ||||
| inline void get(float* destination) const | inline void get(float* destination) const | ||||
| { | { | ||||
| memcpy(destination, m_v, sizeof(m_v)); | std::memcpy(destination, m_v, sizeof(m_v)); | ||||
| } | } | ||||
| /** | /** | ||||
| Context not available. | |||||
| * z axis vector. | * z axis vector. | ||||
| * \return The negative z axis vector. | * \return The negative z axis vector. | ||||
| */ | */ | ||||
| inline AUD_Vector3 getLookAt() const | inline Vector3 getLookAt() const | ||||
| { | { | ||||
| return AUD_Vector3(-2 * (m_w * m_y + m_x * m_z), | return Vector3(-2 * (m_w * m_y + m_x * m_z), | ||||
| 2 * (m_x * m_w - m_z * m_y), | 2 * (m_x * m_w - m_z * m_y), | ||||
| 2 * (m_x * m_x + m_y * m_y) - 1); | 2 * (m_x * m_x + m_y * m_y) - 1); | ||||
| } | } | ||||
| /** | /** | ||||
| Context not available. | |||||
| * vector. | * vector. | ||||
| * \return The y axis vector. | * \return The y axis vector. | ||||
| */ | */ | ||||
| inline AUD_Vector3 getUp() const | inline Vector3 getUp() const | ||||
| { | { | ||||
| return AUD_Vector3(2 * (m_x * m_y - m_w * m_z), | return Vector3(2 * (m_x * m_y - m_w * m_z), | ||||
| 1 - 2 * (m_x * m_x + m_z * m_z), | 1 - 2 * (m_x * m_x + m_z * m_z), | ||||
| 2 * (m_w * m_x + m_y * m_z)); | 2 * (m_w * m_x + m_y * m_z)); | ||||
| } | } | ||||
| }; | }; | ||||
| #endif //__AUD_3DMATH_H__ | AUD_NAMESPACE_END | ||||
| Context not available. | |||||