Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Merge internal branch into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelsey Mayfield committed Apr 29, 2016
2 parents 56b7da7 + eda5601 commit 85c795d
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 39 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ endfunction()
function(mathfu_enable_warnings target)
get_target_property(target_compile_flags ${target} COMPILE_FLAGS)
if(MSVC)
target_compile_options(${target} PRIVATE /W4 /WX)
# C4127: conditional expression is constant
# C4577: 'noexcept' used with no exception handling mode specified.
target_compile_options(${target} PRIVATE /W4 /WX /wd4127 /wd4577)
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR
CMAKE_COMPILER_IS_CLANGXX)
# Set the maximum warning level for gcc.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ PERL_PATH = /usr/bin/perl
# powerful graphs.
# The default value is: YES.

CLASS_DIAGRAMS = YES
CLASS_DIAGRAMS = NO

# You can define message sequence charts within doxygen comments using the \msc
# command. Doxygen will then run the mscgen tool (see:
Expand All @@ -2108,7 +2108,7 @@ CLASS_DIAGRAMS = YES
# the mscgen tool resides. If left empty the tool is assumed to be found in the
# default search path.

MSCGEN_PATH =
MSCGEN_PATH =

# If set to YES, the inheritance and collaboration graphs will hide inheritance
# and usage relations if the target is undocumented or is not a class.
Expand Down
1 change: 1 addition & 0 deletions include/mathfu/glsl_mappings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
/// MathFu provides a set of data types that are similar in style to
/// GLSL Vector and Matrix data types.

/// @brief Namespace for MathFu library.
namespace mathfu {

/// @addtogroup mathfu_glsl
Expand Down
46 changes: 30 additions & 16 deletions include/mathfu/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ inline Matrix<T, 4, 4> PerspectiveHelper(T fovy, T aspect, T znear, T zfar,
T handedness);
template <class T>
static inline Matrix<T, 4, 4> OrthoHelper(T left, T right, T bottom, T top,
T znear, T zfar);
T znear, T zfar, T handedness);
template <class T>
static inline Matrix<T, 4, 4> LookAtHelper(const Vector<T, 3>& at,
const Vector<T, 3>& eye,
const Vector<T, 3>& up);
const Vector<T, 3>& up,
T handedness);
/// @endcond

/// @addtogroup mathfu_matrix
Expand Down Expand Up @@ -727,10 +728,11 @@ class Matrix {
/// @param top Top extent.
/// @param znear Near plane location.
/// @param zfar Far plane location.
/// @param handedness 1.0f for RH, -1.0f for LH
/// @return 4x4 orthographic Matrix.
static inline Matrix<T, 4, 4> Ortho(T left, T right, T bottom, T top, T znear,
T zfar) {
return OrthoHelper(left, right, bottom, top, znear, zfar);
T zfar, T handedness = 1) {
return OrthoHelper(left, right, bottom, top, znear, zfar, handedness);
}

/// @brief Create a 3-dimensional camera Matrix.
Expand All @@ -739,11 +741,14 @@ class Matrix {
/// @param eye The position of the camera.
/// @param up The up vector in the world, for example (0, 1, 0) if the
/// y-axis is up.
/// @param handedness 1.0f for RH, -1.0f for LH.
/// @return 3-dimensional camera Matrix.
/// TODO: Change default handedness to +1 so that it matches Perspective().
static inline Matrix<T, 4, 4> LookAt(const Vector<T, 3>& at,
const Vector<T, 3>& eye,
const Vector<T, 3>& up) {
return LookAtHelper(at, eye, up);
const Vector<T, 3>& up,
T handedness = -1) {
return LookAtHelper(at, eye, up, handedness);
}

/// @brief Multiply a Vector by a Matrix.
Expand Down Expand Up @@ -1290,22 +1295,22 @@ inline Matrix<T, 4, 4> PerspectiveHelper(T fovy, T aspect, T znear, T zfar,
T handedness) {
const T y = 1 / tan(static_cast<T>(fovy) * static_cast<T>(.5));
const T x = y / aspect;
const T zdist = (znear - zfar) * handedness;
const T zdist = (znear - zfar);
const T zfar_per_zdist = zfar / zdist;
return Matrix<T, 4, 4>(x, 0, 0, 0, 0, y, 0, 0, 0, 0, zfar_per_zdist,
-1 * handedness, 0, 0,
2.0f * znear * zfar_per_zdist * handedness, 0);
return Matrix<T, 4, 4>(x, 0, 0, 0, 0, y, 0, 0, 0, 0,
zfar_per_zdist * handedness, -1 * handedness, 0, 0,
2.0f * znear * zfar_per_zdist, 0);
}
/// @endcond

/// @cond MATHFU_INTERNAL
/// Create a 4x4 orthographic matrix.
template <class T>
static inline Matrix<T, 4, 4> OrthoHelper(T left, T right, T bottom, T top,
T znear, T zfar) {
T znear, T zfar, T handedness) {
return Matrix<T, 4, 4>(static_cast<T>(2) / (right - left), 0, 0, 0, 0,
static_cast<T>(2) / (top - bottom), 0, 0, 0, 0,
static_cast<T>(-2) / (zfar - znear), 0,
-handedness * static_cast<T>(2) / (zfar - znear), 0,
-(right + left) / (right - left),
-(top + bottom) / (top - bottom),
-(zfar + znear) / (zfar - znear), static_cast<T>(1));
Expand All @@ -1320,13 +1325,21 @@ template <class T>
static void LookAtHelperCalculateAxes(const Vector<T, 3>& at,
const Vector<T, 3>& eye,
const Vector<T, 3>& up,
T handedness,
Vector<T, 3>* const axes) {
// Notice that y-axis is always the same regardless of handedness.
axes[2] = (at - eye).Normalized();
axes[0] = Vector<T, 3>::CrossProduct(up, axes[2]).Normalized();
axes[1] = Vector<T, 3>::CrossProduct(axes[2], axes[0]);
axes[3] = Vector<T, 3>(-Vector<T, 3>::DotProduct(axes[0], eye),
axes[3] = Vector<T, 3>(handedness * Vector<T, 3>::DotProduct(axes[0], eye),
-Vector<T, 3>::DotProduct(axes[1], eye),
-Vector<T, 3>::DotProduct(axes[2], eye));
handedness * Vector<T, 3>::DotProduct(axes[2], eye));

// Default calculation is left-handed (i.e. handedness=-1).
// Negate x and z axes for right-handed (i.e. handedness=+1) case.
const float neg = -handedness;
axes[0] *= neg;
axes[2] *= neg;
}
/// @endcond

Expand All @@ -1335,9 +1348,10 @@ static void LookAtHelperCalculateAxes(const Vector<T, 3>& at,
template <class T>
static inline Matrix<T, 4, 4> LookAtHelper(const Vector<T, 3>& at,
const Vector<T, 3>& eye,
const Vector<T, 3>& up) {
const Vector<T, 3>& up,
T handedness) {
Vector<T, 3> axes[4];
LookAtHelperCalculateAxes(at, eye, up, axes);
LookAtHelperCalculateAxes(at, eye, up, handedness, axes);
const Vector<T, 4> column0(axes[0][0], axes[1][0], axes[2][0], 0);
const Vector<T, 4> column1(axes[0][1], axes[1][1], axes[2][1], 0);
const Vector<T, 4> column2(axes[0][2], axes[1][2], axes[2][2], 0);
Expand Down
13 changes: 9 additions & 4 deletions include/mathfu/matrix_4x4.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,25 @@ class Matrix<float, 4> {
}

/// Create a 4x4 orthographic matrix.
/// @param handedness 1.0f for RH, -1.0f for LH
static inline Matrix<float, 4, 4> Ortho(float left, float right, float bottom,
float top, float znear, float zfar) {
return OrthoHelper(left, right, bottom, top, znear, zfar);
float top, float znear, float zfar,
float handedness = 1.0f) {
return OrthoHelper(left, right, bottom, top, znear, zfar, handedness);
}

/// Create a 3-dimensional camera matrix.
/// @param at The look-at target of the camera.
/// @param eye The position of the camera.
/// @param up The up vector in the world, for example (0, 1, 0) if the
/// @handedness: 1.0f for RH, -1.0f for LH
/// TODO: Change default handedness to 1.0f, to match Perspective().
/// y-axis is up.
static inline Matrix<float, 4, 4> LookAt(const Vector<float, 3>& at,
const Vector<float, 3>& eye,
const Vector<float, 3>& up) {
return LookAtHelper(at, eye, up);
const Vector<float, 3>& up,
float handedness = -1.0f) {
return LookAtHelper(at, eye, up, handedness);
}

// Dimensions of the matrix.
Expand Down
13 changes: 13 additions & 0 deletions include/mathfu/quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,19 @@ class Quaternion {
2 * (sy + xz), 2 * (yz - sx), 1 - 2 * (x2 + y2));
}

/// @brief Convert to a 4x4 Matrix.
///
/// @return 4x4 transform Matrix.
inline Matrix<T, 4> ToMatrix4() const {
const T x2 = v_[0] * v_[0], y2 = v_[1] * v_[1], z2 = v_[2] * v_[2];
const T sx = s_ * v_[0], sy = s_ * v_[1], sz = s_ * v_[2];
const T xz = v_[0] * v_[2], yz = v_[1] * v_[2], xy = v_[0] * v_[1];
return Matrix<T, 4>(1 - 2 * (y2 + z2), 2 * (xy + sz), 2 * (xz - sy), 0.0f,
2 * (xy - sz), 1 - 2 * (x2 + z2), 2 * (sx + yz), 0.0f,
2 * (sy + xz), 2 * (yz - sx), 1 - 2 * (x2 + y2), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
}

/// @brief Create a Quaternion from an angle and axis.
///
/// @param angle Angle in radians to rotate by.
Expand Down
4 changes: 2 additions & 2 deletions include/mathfu/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
/// @def MATHFU_VERSION_REVISION
/// @brief Revision number of the library.
/// @see kMathFuVersionString
#define MATHFU_VERSION_REVISION 1
#define MATHFU_VERSION_REVISION 2

/// @}

Expand Down Expand Up @@ -487,7 +487,7 @@ inline void *AllocateAligned(size_t n) {
/// @param p Pointer to memory to deallocate.
inline void FreeAligned(void *p) {
#if defined(_MSC_VER) && _MSC_VER >= 1900 // MSVC 2015
return _aligned_free(p);
_aligned_free(p);
#else
if (p == NULL) return;
free(*(reinterpret_cast<uint8_t **>(p) - 1));
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MathFu Version 1.0.1 {#mathfu_readme}
MathFu Version 1.0.2 {#mathfu_readme}
====================

MathFu is a C++ math library developed primarily for games focused on
Expand Down
Loading

0 comments on commit 85c795d

Please sign in to comment.