Completed documentation, cleanup code
This commit is contained in:
parent
7c8a708a00
commit
8d55d62d98
0
DoxyGen/DoxyWarnLogfile.txt
Normal file
0
DoxyGen/DoxyWarnLogfile.txt
Normal file
@ -51,7 +51,7 @@ PROJECT_BRIEF =
|
|||||||
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
|
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
|
||||||
# the logo to the output directory.
|
# the logo to the output directory.
|
||||||
|
|
||||||
PROJECT_LOGO =
|
PROJECT_LOGO = //intranet/home/Afbeeldingen/PasserVR/Logos/Logo3NameRight100.png
|
||||||
|
|
||||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
|
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
|
||||||
# into which the generated documentation will be written. If a relative path is
|
# into which the generated documentation will be written. If a relative path is
|
||||||
@ -143,7 +143,7 @@ ALWAYS_DETAILED_SEC = NO
|
|||||||
# operators of the base classes will not be shown.
|
# operators of the base classes will not be shown.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
INLINE_INHERITED_MEMB = NO
|
INLINE_INHERITED_MEMB = YES
|
||||||
|
|
||||||
# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
|
# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
|
||||||
# before files name in the file list and in the header files. If set to NO the
|
# before files name in the file list and in the header files. If set to NO the
|
||||||
@ -339,7 +339,7 @@ MARKDOWN_SUPPORT = YES
|
|||||||
# Minimum value: 0, maximum value: 99, default value: 5.
|
# Minimum value: 0, maximum value: 99, default value: 5.
|
||||||
# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.
|
# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.
|
||||||
|
|
||||||
TOC_INCLUDE_HEADINGS = 5
|
TOC_INCLUDE_HEADINGS = 0
|
||||||
|
|
||||||
# When enabled doxygen tries to link words that correspond to documented
|
# When enabled doxygen tries to link words that correspond to documented
|
||||||
# classes, or namespaces to their corresponding documentation. Such a link can
|
# classes, or namespaces to their corresponding documentation. Such a link can
|
||||||
@ -501,7 +501,7 @@ EXTRACT_PACKAGE = NO
|
|||||||
# included in the documentation.
|
# included in the documentation.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
EXTRACT_STATIC = NO
|
EXTRACT_STATIC = YES
|
||||||
|
|
||||||
# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
|
# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
|
||||||
# locally in source files will be included in the documentation. If set to NO,
|
# locally in source files will be included in the documentation. If set to NO,
|
||||||
@ -549,7 +549,7 @@ HIDE_UNDOC_MEMBERS = NO
|
|||||||
# has no effect if EXTRACT_ALL is enabled.
|
# has no effect if EXTRACT_ALL is enabled.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
HIDE_UNDOC_CLASSES = NO
|
HIDE_UNDOC_CLASSES = YES
|
||||||
|
|
||||||
# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
|
# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
|
||||||
# declarations. If set to NO, these declarations will be included in the
|
# declarations. If set to NO, these declarations will be included in the
|
||||||
@ -563,7 +563,7 @@ HIDE_FRIEND_COMPOUNDS = NO
|
|||||||
# blocks will be appended to the function's detailed documentation block.
|
# blocks will be appended to the function's detailed documentation block.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
HIDE_IN_BODY_DOCS = NO
|
HIDE_IN_BODY_DOCS = YES
|
||||||
|
|
||||||
# The INTERNAL_DOCS tag determines if documentation that is typed after a
|
# The INTERNAL_DOCS tag determines if documentation that is typed after a
|
||||||
# \internal command is included. If the tag is set to NO then the documentation
|
# \internal command is included. If the tag is set to NO then the documentation
|
||||||
@ -638,7 +638,7 @@ INLINE_INFO = YES
|
|||||||
# name. If set to NO, the members will appear in declaration order.
|
# name. If set to NO, the members will appear in declaration order.
|
||||||
# The default value is: YES.
|
# The default value is: YES.
|
||||||
|
|
||||||
SORT_MEMBER_DOCS = YES
|
SORT_MEMBER_DOCS = NO
|
||||||
|
|
||||||
# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
|
# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
|
||||||
# descriptions of file, namespace and class members alphabetically by member
|
# descriptions of file, namespace and class members alphabetically by member
|
||||||
@ -741,14 +741,14 @@ SHOW_USED_FILES = YES
|
|||||||
# (if specified).
|
# (if specified).
|
||||||
# The default value is: YES.
|
# The default value is: YES.
|
||||||
|
|
||||||
SHOW_FILES = YES
|
SHOW_FILES = NO
|
||||||
|
|
||||||
# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
|
# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
|
||||||
# page. This will remove the Namespaces entry from the Quick Index and from the
|
# page. This will remove the Namespaces entry from the Quick Index and from the
|
||||||
# Folder Tree View (if specified).
|
# Folder Tree View (if specified).
|
||||||
# The default value is: YES.
|
# The default value is: YES.
|
||||||
|
|
||||||
SHOW_NAMESPACES = YES
|
SHOW_NAMESPACES = NO
|
||||||
|
|
||||||
# The FILE_VERSION_FILTER tag can be used to specify a program or script that
|
# The FILE_VERSION_FILTER tag can be used to specify a program or script that
|
||||||
# doxygen should invoke to get the current version for each file (typically from
|
# doxygen should invoke to get the current version for each file (typically from
|
||||||
@ -859,7 +859,7 @@ WARN_FORMAT = "$file:$line: $text"
|
|||||||
# messages should be written. If left blank the output is written to standard
|
# messages should be written. If left blank the output is written to standard
|
||||||
# error (stderr).
|
# error (stderr).
|
||||||
|
|
||||||
WARN_LOGFILE =
|
WARN_LOGFILE = DoxyWarnLogfile.txt
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# Configuration options related to the input files
|
# Configuration options related to the input files
|
||||||
@ -871,7 +871,7 @@ WARN_LOGFILE =
|
|||||||
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
|
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
|
||||||
# Note: If this tag is empty the current directory is searched.
|
# Note: If this tag is empty the current directory is searched.
|
||||||
|
|
||||||
INPUT =
|
INPUT = ..
|
||||||
|
|
||||||
# This tag can be used to specify the character encoding of the source files
|
# This tag can be used to specify the character encoding of the source files
|
||||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||||
@ -951,7 +951,7 @@ FILE_PATTERNS = *.c \
|
|||||||
# be searched for input files as well.
|
# be searched for input files as well.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
RECURSIVE = NO
|
RECURSIVE = YES
|
||||||
|
|
||||||
# The EXCLUDE tag can be used to specify files and/or directories that should be
|
# The EXCLUDE tag can be used to specify files and/or directories that should be
|
||||||
# excluded from the INPUT source files. This way you can easily exclude a
|
# excluded from the INPUT source files. This way you can easily exclude a
|
||||||
@ -1013,7 +1013,8 @@ EXAMPLE_RECURSIVE = NO
|
|||||||
# that contain images that are to be included in the documentation (see the
|
# that contain images that are to be included in the documentation (see the
|
||||||
# \image command).
|
# \image command).
|
||||||
|
|
||||||
IMAGE_PATH =
|
IMAGE_PATH = images \
|
||||||
|
.
|
||||||
|
|
||||||
# The INPUT_FILTER tag can be used to specify a program that doxygen should
|
# The INPUT_FILTER tag can be used to specify a program that doxygen should
|
||||||
# invoke to filter for each input file. Doxygen will invoke the filter program
|
# invoke to filter for each input file. Doxygen will invoke the filter program
|
||||||
@ -1293,7 +1294,7 @@ HTML_STYLESHEET =
|
|||||||
# list). For an example see the documentation.
|
# list). For an example see the documentation.
|
||||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||||
|
|
||||||
HTML_EXTRA_STYLESHEET =
|
HTML_EXTRA_STYLESHEET = custom_doxygen.css
|
||||||
|
|
||||||
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
|
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
|
||||||
# other source files which should be copied to the HTML output directory. Note
|
# other source files which should be copied to the HTML output directory. Note
|
||||||
@ -1314,7 +1315,7 @@ HTML_EXTRA_FILES =
|
|||||||
# Minimum value: 0, maximum value: 359, default value: 220.
|
# Minimum value: 0, maximum value: 359, default value: 220.
|
||||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||||
|
|
||||||
HTML_COLORSTYLE_HUE = 220
|
HTML_COLORSTYLE_HUE = 35
|
||||||
|
|
||||||
# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors
|
# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors
|
||||||
# in the HTML output. For a value of 0 the output will use gray-scales only. A
|
# in the HTML output. For a value of 0 the output will use gray-scales only. A
|
||||||
@ -1322,7 +1323,7 @@ HTML_COLORSTYLE_HUE = 220
|
|||||||
# Minimum value: 0, maximum value: 255, default value: 100.
|
# Minimum value: 0, maximum value: 255, default value: 100.
|
||||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||||
|
|
||||||
HTML_COLORSTYLE_SAT = 100
|
HTML_COLORSTYLE_SAT = 0
|
||||||
|
|
||||||
# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the
|
# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the
|
||||||
# luminance component of the colors in the HTML output. Values below 100
|
# luminance component of the colors in the HTML output. Values below 100
|
||||||
@ -1333,7 +1334,7 @@ HTML_COLORSTYLE_SAT = 100
|
|||||||
# Minimum value: 40, maximum value: 240, default value: 80.
|
# Minimum value: 40, maximum value: 240, default value: 80.
|
||||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||||
|
|
||||||
HTML_COLORSTYLE_GAMMA = 80
|
HTML_COLORSTYLE_GAMMA = 103
|
||||||
|
|
||||||
# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
|
# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
|
||||||
# page will contain the date and time when the page was generated. Setting this
|
# page will contain the date and time when the page was generated. Setting this
|
||||||
@ -2231,7 +2232,7 @@ PERLMOD_MAKEVAR_PREFIX =
|
|||||||
# C-preprocessor directives found in the sources and include files.
|
# C-preprocessor directives found in the sources and include files.
|
||||||
# The default value is: YES.
|
# The default value is: YES.
|
||||||
|
|
||||||
ENABLE_PREPROCESSING = YES
|
ENABLE_PREPROCESSING = NO
|
||||||
|
|
||||||
# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
|
# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
|
||||||
# in the source code. If set to NO, only conditional compilation will be
|
# in the source code. If set to NO, only conditional compilation will be
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
<!-- Layout definition for a class page -->
|
<!-- Layout definition for a class page -->
|
||||||
<class>
|
<class>
|
||||||
<briefdescription visible="no"/>
|
<briefdescription visible="no"/>
|
||||||
<detaileddescription title="Unity Inspector"/>
|
<detaileddescription title=""/>
|
||||||
<includes visible="$SHOW_INCLUDE_FILES"/>
|
<includes visible="$SHOW_INCLUDE_FILES"/>
|
||||||
<inheritancegraph visible="$CLASS_GRAPH"/>
|
<inheritancegraph visible="$CLASS_GRAPH"/>
|
||||||
<collaborationgraph visible="$COLLABORATION_GRAPH"/>
|
<collaborationgraph visible="$COLLABORATION_GRAPH"/>
|
||||||
|
@ -68,13 +68,9 @@ void Quaternion::Normalize() {
|
|||||||
|
|
||||||
Quaternion Quaternion::Normalize(const Quaternion& q) {
|
Quaternion Quaternion::Normalize(const Quaternion& q) {
|
||||||
Quaternion result;
|
Quaternion result;
|
||||||
Normalize(q, result);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
void Quaternion::Normalize(const Quaternion& q, Quaternion& result) {
|
|
||||||
float scale = 1.0f / q.GetLength();
|
float scale = 1.0f / q.GetLength();
|
||||||
result = Quaternion(q.x * scale, q.y * scale, q.z * scale, q.w * scale);
|
result = Quaternion(q.x * scale, q.y * scale, q.z * scale, q.w * scale);
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
float Quaternion::Dot(Quaternion a, Quaternion b) {
|
float Quaternion::Dot(Quaternion a, Quaternion b) {
|
||||||
@ -148,13 +144,6 @@ Quaternion Quaternion::Inverse(Quaternion r) {
|
|||||||
return Quaternion(-r.x / n, -r.y / n, -r.z / n, r.w / n);
|
return Quaternion(-r.x / n, -r.y / n, -r.z / n, r.w / n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a quaternion with the given forward direction
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="forward">The diraction to look in</param>
|
|
||||||
/// <returns>The rotation for this direction</returns>
|
|
||||||
/// For the rotation, Vector::up is used for the up direction.
|
|
||||||
/// Note: if the forward direction == Vector3::up, the result is Quaternion::identity
|
|
||||||
Quaternion Quaternion::LookRotation(const Vector3& forward) {
|
Quaternion Quaternion::LookRotation(const Vector3& forward) {
|
||||||
Vector3 up = Vector3(0, 1, 0);
|
Vector3 up = Vector3(0, 1, 0);
|
||||||
return LookRotation(forward, up);
|
return LookRotation(forward, up);
|
||||||
|
204
Quaternion.h
204
Quaternion.h
@ -2,20 +2,32 @@
|
|||||||
// License, v. 2.0.If a copy of the MPL was not distributed with this
|
// License, v. 2.0.If a copy of the MPL was not distributed with this
|
||||||
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#ifndef QUATERNION_H
|
|
||||||
#define QUATERNION_H
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
struct Vector3;
|
struct Vector3;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
/// <summary>
|
||||||
|
/// A quaternion
|
||||||
|
/// </summary>
|
||||||
|
/// This is a C-style implementation
|
||||||
typedef struct Quat {
|
typedef struct Quat {
|
||||||
|
/// <summary>
|
||||||
|
/// The x component
|
||||||
|
/// </summary>
|
||||||
float x;
|
float x;
|
||||||
|
/// <summary>
|
||||||
|
/// The y component
|
||||||
|
/// </summary>
|
||||||
float y;
|
float y;
|
||||||
|
/// <summary>
|
||||||
|
/// The z component
|
||||||
|
/// </summary>
|
||||||
float z;
|
float z;
|
||||||
|
/// <summary>
|
||||||
|
/// The w component
|
||||||
|
/// </summary>
|
||||||
float w;
|
float w;
|
||||||
} Quat;
|
} Quat;
|
||||||
void CopyQuat(const Quat& q1, Quat& q2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -31,10 +43,10 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// create a new quaternion with the given values
|
/// create a new quaternion with the given values
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="_x">x axis value</param>
|
/// <param name="_x">x component</param>
|
||||||
/// <param name="_y">y axis value</param>
|
/// <param name="_y">y component</param>
|
||||||
/// <param name="_z">z axis value</param>
|
/// <param name="_z">z component</param>
|
||||||
/// <param name="_w">w axis value</param>
|
/// <param name="_w">w component</param>
|
||||||
Quaternion(float _x, float _y, float _z, float _w);
|
Quaternion(float _x, float _y, float _z, float _w);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a quaternion from C-style Quat
|
/// Create a quaternion from C-style Quat
|
||||||
@ -48,51 +60,185 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
const static Quaternion identity;
|
const static Quaternion identity;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert to unit quaternion
|
||||||
|
/// </summary>
|
||||||
|
/// This will preserve the orientation,
|
||||||
|
/// but ensures that it is a unit quaternion.
|
||||||
void Normalize();
|
void Normalize();
|
||||||
|
/// <summary>
|
||||||
|
/// Convert to unity quaternion
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="q">The quaternion to convert</param>
|
||||||
|
/// <returns>A unit quaternion</returns>
|
||||||
|
/// This will preserve the orientation,
|
||||||
|
/// but ensures that it is a unit quaternion.
|
||||||
static Quaternion Normalize(const Quaternion& q);
|
static Quaternion Normalize(const Quaternion& q);
|
||||||
static void Normalize(const Quaternion& q, Quaternion& result);
|
|
||||||
|
|
||||||
static Vector3 ToAngles(const Quaternion& q1);
|
/// <summary>
|
||||||
|
/// Convert to euler angles
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="q">The quaternion to convert</param>
|
||||||
|
/// <returns>A vector containing euler angles</returns>
|
||||||
|
/// The euler angles performed in the order: Z, X, Y
|
||||||
|
static Vector3 ToAngles(const Quaternion& q);
|
||||||
|
|
||||||
Vector3 operator *(const Vector3& p) const;
|
/// <summary>
|
||||||
Quaternion operator *(const Quaternion& r2) const;
|
/// Rotate a vector using this quaterion
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The vector to rotate</param>
|
||||||
|
/// <returns>The rotated vector</returns>
|
||||||
|
Vector3 operator *(const Vector3& vector) const;
|
||||||
|
/// <summary>
|
||||||
|
/// Multiply this quaternion with another quaternion
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rotation">The quaternion to multiply with</param>
|
||||||
|
/// <returns>The resulting rotation</returns>
|
||||||
|
/// The result will be this quaternion rotated according to
|
||||||
|
/// the give rotation.
|
||||||
|
Quaternion operator *(const Quaternion& rotation) const;
|
||||||
|
|
||||||
bool operator ==(const Quaternion& q);
|
/// <summary>
|
||||||
|
/// Check the equality of two quaternions
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="quaternion">The quaternion to compare to</param>
|
||||||
|
/// <returns>True when the components of the quaternions are identical</returns>
|
||||||
|
/// Note that this does not compare the rotations themselves.
|
||||||
|
/// Two quaternions with the same rotational effect may have different
|
||||||
|
/// components. Use Quaternion::Angle to check if the rotations are the same.
|
||||||
|
bool operator ==(const Quaternion& quaternion);
|
||||||
|
|
||||||
static Quaternion Inverse(Quaternion r);
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The inverse of quaterion
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="quaternion">The quaternion for which the inverse is needed</param>
|
||||||
|
/// <returns>The inverted quaternion</returns>
|
||||||
|
static Quaternion Inverse(Quaternion quaternion);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A rotation which looks in the given direction
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="forward">The look direction</param>
|
||||||
|
/// <param name="upwards">The up direction</param>
|
||||||
|
/// <returns>The look rotation</returns>
|
||||||
static Quaternion LookRotation(const Vector3& forward, const Vector3& upwards);
|
static Quaternion LookRotation(const Vector3& forward, const Vector3& upwards);
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a quaternion with the given forward direction with up = Vector3::up
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="forward">The look direction</param>
|
||||||
|
/// <returns>The rotation for this direction</returns>
|
||||||
|
/// For the rotation, Vector::up is used for the up direction.
|
||||||
|
/// Note: if the forward direction == Vector3::up, the result is Quaternion::identity
|
||||||
static Quaternion LookRotation(const Vector3& forward);
|
static Quaternion LookRotation(const Vector3& forward);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculat the rotation from on vector to another
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fromDirection">The from direction</param>
|
||||||
|
/// <param name="toDirection">The to direction</param>
|
||||||
|
/// <returns>The rotation from the first to the second vector</returns>
|
||||||
static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection);
|
static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rotate form one orientation to anther with a maximum amount of degrees
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="from">The from rotation</param>
|
||||||
|
/// <param name="to">The destination rotation</param>
|
||||||
|
/// <param name="maxDegreesDelta">The maximum amount of degrees to rotate</param>
|
||||||
|
/// <returns>The possibly limited rotation</returns>
|
||||||
static Quaternion RotateTowards(const Quaternion& from, const Quaternion& to, float maxDegreesDelta);
|
static Quaternion RotateTowards(const Quaternion& from, const Quaternion& to, float maxDegreesDelta);
|
||||||
static Quaternion AngleAxis(float angle, const Vector3& axis);
|
|
||||||
void ToAngleAxis(float* angle, Vector3* axis);
|
|
||||||
static void ToAxisAngleRad(const Quaternion& q, Vector3* const axis, float* angle);
|
|
||||||
static float Angle(Quaternion a, Quaternion b);
|
|
||||||
static Quaternion Slerp(const Quaternion& a, const Quaternion& b, float t);
|
|
||||||
static Quaternion SlerpUnclamped(const Quaternion& a, const Quaternion& b, float t);
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert an angle/axis representation to a quaternion
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="angle">The angle</param>
|
||||||
|
/// <param name="axis">The axis</param>
|
||||||
|
/// <returns>The resulting quaternion</returns>
|
||||||
|
static Quaternion AngleAxis(float angle, const Vector3& axis);
|
||||||
|
/// <summary>
|
||||||
|
/// Convert this quaternion to angle/axis representation
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="angle">A pointer to the angle for the result</param>
|
||||||
|
/// <param name="axis">A pointer to the axis for the result</param>
|
||||||
|
void ToAngleAxis(float* angle, Vector3* axis);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the angle between two orientations
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="orientation1">The first orientation</param>
|
||||||
|
/// <param name="orientation2">The second orientation</param>
|
||||||
|
/// <returns>The smallest angle in degrees between the two orientations</returns>
|
||||||
|
static float Angle(Quaternion orientation1, Quaternion orientation2);
|
||||||
|
/// <summary>
|
||||||
|
/// Sherical lerp between two rotations
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rotation1">The first rotation</param>
|
||||||
|
/// <param name="rotation2">The second rotation</param>
|
||||||
|
/// <param name="factor">The factor between 0 and 1.</param>
|
||||||
|
/// <returns>The resulting rotation</returns>
|
||||||
|
/// A factor 0 returns rotation1, factor1 returns rotation2.
|
||||||
|
static Quaternion Slerp(const Quaternion& rotation1, const Quaternion& rotation2, float factor);
|
||||||
|
/// <summary>
|
||||||
|
/// Unclamped sherical lerp between two rotations
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rotation1">The first rotation</param>
|
||||||
|
/// <param name="rotation2">The second rotation</param>
|
||||||
|
/// <param name="factor">The factor</param>
|
||||||
|
/// <returns>The resulting rotation</returns>
|
||||||
|
/// A factor 0 returns rotation1, factor1 returns rotation2.
|
||||||
|
/// Values outside the 0..1 range will result in extrapolated rotations
|
||||||
|
static Quaternion SlerpUnclamped(const Quaternion& rotation1, const Quaternion& rotation2, float factor);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a rotation from euler angles
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">The angle around the right axis</param>
|
||||||
|
/// <param name="y">The angle around the upward axis</param>
|
||||||
|
/// <param name="z">The angle around the forward axis</param>
|
||||||
|
/// <returns>The resulting quaternion</returns>
|
||||||
|
/// Rotation are appied in the order z, X, Y.
|
||||||
static Quaternion Euler(float x, float y, float z);
|
static Quaternion Euler(float x, float y, float z);
|
||||||
static Quaternion Euler(Vector3 euler);
|
/// <summary>
|
||||||
static Quaternion FromEulerRad(Vector3 euler);
|
/// Create a rotation from a vector containing euler angles
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="eulerAngles">Vector with the euler angles</param>
|
||||||
|
/// <returns>The resulting quaternion</returns>
|
||||||
|
/// Rotation are appied in the order z, X, Y.
|
||||||
|
static Quaternion Euler(Vector3 eulerAngles);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the angle of around the give axis for a rotation
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="axis">The axis around which the angle should be computed</param>
|
||||||
|
/// <param name="rotation">The source rotation</param>
|
||||||
|
/// <returns>The signed angle around the axis</returns>
|
||||||
static float GetAngleAround(Vector3 axis, Quaternion rotation);
|
static float GetAngleAround(Vector3 axis, Quaternion rotation);
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the rotation limited around the given axis
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="axis">The axis which which the rotation should be limited</param>
|
||||||
|
/// <param name="rotation">The source rotation</param>
|
||||||
|
/// <returns>The rotation around the given axis</returns>
|
||||||
static Quaternion GetRotationAround(Vector3 axis, Quaternion rotation);
|
static Quaternion GetRotationAround(Vector3 axis, Quaternion rotation);
|
||||||
|
/// <summary>
|
||||||
|
/// Swing-twist decomposition of a rotation
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="axis">The base direction for the decomposition</param>
|
||||||
|
/// <param name="rotation">The source rotation</param>
|
||||||
|
/// <param name="swing">A pointer to the quaternion for the swing result</param>
|
||||||
|
/// <param name="twist">A pointer to the quaternion for the twist result</param>
|
||||||
static void GetSwingTwist(Vector3 axis, Quaternion rotation, Quaternion* swing, Quaternion* twist);
|
static void GetSwingTwist(Vector3 axis, Quaternion rotation, Quaternion* swing, Quaternion* twist);
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
float GetLength() const;
|
float GetLength() const;
|
||||||
float GetLengthSquared() const;
|
float GetLengthSquared() const;
|
||||||
static float GetLengthSquared(const Quaternion& q);
|
static float GetLengthSquared(const Quaternion& q);
|
||||||
|
|
||||||
|
void ToAxisAngleRad(const Quaternion& q, Vector3* const axis, float* angle);
|
||||||
|
static Quaternion FromEulerRad(Vector3 euler);
|
||||||
|
|
||||||
static float Dot(Quaternion a, Quaternion b);
|
static float Dot(Quaternion a, Quaternion b);
|
||||||
|
|
||||||
public:
|
|
||||||
Vector3 xyz() const;
|
Vector3 xyz() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
//#include "Vector3.h"
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
44
Vector3.cpp
44
Vector3.cpp
@ -5,7 +5,6 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
#include "Quaternion.h"
|
|
||||||
|
|
||||||
const float Deg2Rad = 0.0174532924F;
|
const float Deg2Rad = 0.0174532924F;
|
||||||
const float Rad2Deg = 57.29578F;
|
const float Rad2Deg = 57.29578F;
|
||||||
@ -92,26 +91,6 @@ Vector3 Vector3::operator *(float f) const {
|
|||||||
return Vector3(this->x * f, this->y * f, this->z * f);
|
return Vector3(this->x * f, this->y * f, this->z * f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 operator *(const Quaternion& o, const Vector3& p) {
|
|
||||||
float num = o.x * 2;
|
|
||||||
float num2 = o.y * 2;
|
|
||||||
float num3 = o.z * 2;
|
|
||||||
float num4 = o.x * num;
|
|
||||||
float num5 = o.y * num2;
|
|
||||||
float num6 = o.z * num3;
|
|
||||||
float num7 = o.x * num2;
|
|
||||||
float num8 = o.x * num3;
|
|
||||||
float num9 = o.y * num3;
|
|
||||||
float num10 = o.w * num;
|
|
||||||
float num11 = o.w * num2;
|
|
||||||
float num12 = o.w * num3;
|
|
||||||
Vector3 result = Vector3::zero;
|
|
||||||
result.x = (1 - (num5 + num6)) * p.x + (num7 - num12) * p.y + (num8 + num11) * p.z;
|
|
||||||
result.y = (num7 + num12) * p.x + (1 - (num4 + num6)) * p.y + (num9 - num10) * p.z;
|
|
||||||
result.z = (num8 - num11) * p.x + (num9 + num10) * p.y + (1 - (num4 + num5)) * p.z;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 Vector3::operator/(const float& d) {
|
Vector3 Vector3::operator/(const float& d) {
|
||||||
return Vector3(this->x / d, this->y / d, this->z / d);
|
return Vector3(this->x / d, this->y / d, this->z / d);
|
||||||
}
|
}
|
||||||
@ -156,7 +135,6 @@ float clamp(float x, float lower, float upper) {
|
|||||||
return upperClamp;
|
return upperClamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is buggy (0-1-0, 0-1-0) gives 180 degrees in return!!!
|
|
||||||
float Vector3::Angle(Vector3 from, Vector3 to) {
|
float Vector3::Angle(Vector3 from, Vector3 to) {
|
||||||
float denominator = sqrtf(from.sqrMagnitude() * to.sqrMagnitude());
|
float denominator = sqrtf(from.sqrMagnitude() * to.sqrMagnitude());
|
||||||
if (denominator < epsilon)
|
if (denominator < epsilon)
|
||||||
@ -185,14 +163,14 @@ float Vector3::SignedAngle(Vector3 from, Vector3 to, Vector3 axis) {
|
|||||||
return signed_angle;
|
return signed_angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CopyVec3(const Vec3& v1, Vec3& v2) {
|
//void CopyVec3(const Vec3& v1, Vec3& v2) {
|
||||||
v2.x = v1.x;
|
// v2.x = v1.x;
|
||||||
v2.y = v1.y;
|
// v2.y = v1.y;
|
||||||
v2.z = v1.z;
|
// v2.z = v1.z;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void Vec3_Constructor(Vec3* v, float _x, float _y, float _z) {
|
//void Vec3_Constructor(Vec3* v, float _x, float _y, float _z) {
|
||||||
v->x = _x;
|
// v->x = _x;
|
||||||
v->y = _y;
|
// v->y = _y;
|
||||||
v->z = _z;
|
// v->z = _z;
|
||||||
}
|
//}
|
||||||
|
177
Vector3.h
177
Vector3.h
@ -2,26 +2,35 @@
|
|||||||
// License, v. 2.0.If a copy of the MPL was not distributed with this
|
// License, v. 2.0.If a copy of the MPL was not distributed with this
|
||||||
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#ifndef VECTOR_H
|
|
||||||
#define VECTOR_H
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
struct Quaternion;
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
/// <summary>
|
||||||
|
/// 3-dimensional Vector representation
|
||||||
|
/// </summary>
|
||||||
|
/// This is a C-style implementation
|
||||||
|
/// This uses the right-handed coordinate system.
|
||||||
typedef struct Vec3 {
|
typedef struct Vec3 {
|
||||||
|
/// <summary>
|
||||||
|
/// The right axis of the vector
|
||||||
|
/// </summary>
|
||||||
float x;
|
float x;
|
||||||
|
/// <summary>
|
||||||
|
/// The upward axis of the vector
|
||||||
|
/// </summary>
|
||||||
float y;
|
float y;
|
||||||
|
/// <summary>
|
||||||
|
/// The forward axis of the vector
|
||||||
|
/// </summary>
|
||||||
float z;
|
float z;
|
||||||
|
|
||||||
} Vec3;
|
} Vec3;
|
||||||
|
|
||||||
void CopyVec3(const Vec3& v1, Vec3& v2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A 3-dimensional vector
|
/// A 3-dimensional vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// This uses the right-handed coordinate system.
|
||||||
struct Vector3 : Vec3 {
|
struct Vector3 : Vec3 {
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -71,39 +80,157 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
const static Vector3 back;
|
const static Vector3 back;
|
||||||
|
|
||||||
static float Magnitude(const Vector3& a);
|
/// <summary>
|
||||||
|
/// The length of a vector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The vector for which you need the length</param>
|
||||||
|
/// <returns>The length of the given vector</returns>
|
||||||
|
static float Magnitude(const Vector3& vector);
|
||||||
|
/// <summary>
|
||||||
|
/// The length of this vector
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The length of this vector</returns>
|
||||||
float magnitude() const;
|
float magnitude() const;
|
||||||
static float SqrMagnitude(const Vector3& a);
|
/// <summary>
|
||||||
|
/// The squared length of a vector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The vector for which you need the squared length</param>
|
||||||
|
/// <returns>The squatred length</returns>
|
||||||
|
/// The squared length is computationally simpler than the real length.
|
||||||
|
/// Think of Pythagoras A^2 + B^2 = C^2.
|
||||||
|
/// This leaves out the calculation of the squared root of C.
|
||||||
|
static float SqrMagnitude(const Vector3& vector);
|
||||||
|
/// <summary>
|
||||||
|
/// The squared length of this vector
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The squared length</returns>
|
||||||
|
/// The squared length is computationally simpler than the real length.
|
||||||
|
/// Think of Pythagoras A^2 + B^2 = C^2.
|
||||||
|
/// This leaves out the calculation of the squared root of C.
|
||||||
float sqrMagnitude() const;
|
float sqrMagnitude() const;
|
||||||
static Vector3 Normalize(Vector3 v);
|
/// <summary>
|
||||||
|
/// Connvert a vector to a length of 1
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The vector to convert</param>
|
||||||
|
/// <returns>The vector with length 1</returns>
|
||||||
|
static Vector3 Normalize(Vector3 vector);
|
||||||
|
/// <summary>
|
||||||
|
/// Convert the vector to a length of a
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The vector with length 1</returns>
|
||||||
Vector3 normalized() const;
|
Vector3 normalized() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Negate the vector
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The negated vector</returns>
|
||||||
|
/// This will result in a vector pointing in the opposite direction
|
||||||
Vector3 operator -();
|
Vector3 operator -();
|
||||||
Vector3 operator -(const Vector3& p2) const;
|
/// <summary>
|
||||||
|
/// Subtract a vector from this vector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The vector to subtract from this vector</param>
|
||||||
|
/// <returns>The result of the subtraction</returns>
|
||||||
|
Vector3 operator -(const Vector3& vector) const;
|
||||||
|
|
||||||
Vector3 operator +(const Vector3& t1) const;
|
/// <summary>
|
||||||
static Vector3 Scale(const Vector3& p1, const Vector3& p2);
|
/// Add another vector to this vector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector2">The vector to add</param>
|
||||||
|
/// <returns>The result of adding the vector</returns>
|
||||||
|
Vector3 operator +(const Vector3& vector2) const;
|
||||||
|
|
||||||
Vector3 operator *(float f) const;
|
/// <summary>
|
||||||
|
/// Scale a vector using another vector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector1">The vector to scale</param>
|
||||||
|
/// <param name="vector2">A vector with scaling factors</param>
|
||||||
|
/// <returns>The scaled vector</returns>
|
||||||
|
/// Each component of the vector v1 will be multiplied with the
|
||||||
|
/// component from the scaling vector v2.
|
||||||
|
static Vector3 Scale(const Vector3& vector1, const Vector3& vector2);
|
||||||
|
/// <summary>
|
||||||
|
/// Scale a vector uniformly up
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="factor">The scaling factor</param>
|
||||||
|
/// <returns>The scaled vector</returns>
|
||||||
|
/// Each component of the vector will be multipled with the same factor.
|
||||||
|
Vector3 operator *(float factor) const;
|
||||||
|
/// <summary>
|
||||||
|
/// Scale a vector uniformy down
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="factor">The scaling factor</param>
|
||||||
|
/// <returns>The scaled vector</returns>
|
||||||
|
/// Each componet of the vector will be divided by the same factor.
|
||||||
|
Vector3 operator /(const float& factor);
|
||||||
|
|
||||||
Vector3 operator /(const float& d);
|
/// <summary>
|
||||||
static float Dot(const Vector3& v1, const Vector3& v2);
|
/// The dot product of two vectors
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector1">The first vector</param>
|
||||||
|
/// <param name="vector2">The second vector</param>
|
||||||
|
/// <returns>The dot product of the two vectors</returns>
|
||||||
|
static float Dot(const Vector3& vector1, const Vector3& vector2);
|
||||||
|
|
||||||
bool operator ==(const Vector3& v);
|
/// <summary>
|
||||||
|
/// Check is this vector is equal to the given vector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The vector to check against</param>
|
||||||
|
/// <returns>True if it is identical to the given vector</returns>
|
||||||
|
/// Note this uses float comparison to check equality which
|
||||||
|
/// may have strange effects. Equality on float should be avoided.
|
||||||
|
bool operator ==(const Vector3& vector);
|
||||||
|
|
||||||
static float Distance(const Vector3& p1, const Vector3& p2);
|
/// <summary>
|
||||||
static Vector3 Cross(const Vector3& v1, const Vector3& v2);
|
/// The distance between two vectors
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector1">The first vector</param>
|
||||||
|
/// <param name="vector2">The second vectors</param>
|
||||||
|
/// <returns>The distance between the two vectors</returns>
|
||||||
|
static float Distance(const Vector3& vector1, const Vector3& vector2);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The cross product of two vectors
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector1">The first vector</param>
|
||||||
|
/// <param name="vector2">The second vector</param>
|
||||||
|
/// <returns>The cross product of the two vectors</returns>
|
||||||
|
static Vector3 Cross(const Vector3& vector1, const Vector3& vector2);
|
||||||
|
|
||||||
// Projects a vector onto another vector.
|
// Projects a vector onto another vector.
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Project a vector on another vector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The vector to project</param>
|
||||||
|
/// <param name="onNormal">The normal vector to project on</param>
|
||||||
|
/// <returns>The projected vector</returns>
|
||||||
static Vector3 Project(Vector3 vector, Vector3 onNormal);
|
static Vector3 Project(Vector3 vector, Vector3 onNormal);
|
||||||
// Projects a vector onto a plane defined by a normal orthogonal to the plane.
|
/// <summary>
|
||||||
|
/// Projects a vector onto a plane defined by a normal orthogonal to the plane.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The vector to project</param>
|
||||||
|
/// <param name="planeNormal">The normal of the plane to project on</param>
|
||||||
|
/// <returns></returns>
|
||||||
static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal);
|
static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal);
|
||||||
|
|
||||||
static float Angle(Vector3 from, Vector3 to);
|
/// <summary>
|
||||||
|
/// Calculate the angle between two vectors
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector1">The first vector</param>
|
||||||
|
/// <param name="vector2">The second vector</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// This reterns an unsigned angle which is the shortest distance
|
||||||
|
/// between the two vectors. Use Vector3::SignedAngle if a
|
||||||
|
/// signed angle is needed.
|
||||||
|
static float Angle(Vector3 vector1, Vector3 vector2);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculate the angle between two vectors rotation around an axis.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="from">The starting vector</param>
|
||||||
|
/// <param name="to">The ending vector</param>
|
||||||
|
/// <param name="axis">The axis to rotate around</param>
|
||||||
|
/// <returns>The signed angle</returns>
|
||||||
static float SignedAngle(Vector3 from, Vector3 to, Vector3 axis);
|
static float SignedAngle(Vector3 from, Vector3 to, Vector3 axis);
|
||||||
};
|
};
|
||||||
|
|
||||||
void Vec3_Constructor(Vec3* v, float _x, float _y, float _z);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user