Procházet zdrojové kódy

Make the vector, matrix and transform-related classes header-only.

wip/core-clipp
Sam Hocevar před 4 roky
rodič
revize
ca3fb5a4ba
10 změnil soubory, kde provedl 225 přidání a 189 odebrání
  1. +7
    -8
      include/lol/math/private/matrix.h
  2. +99
    -46
      include/lol/math/private/matrix.ipp
  3. +9
    -7
      include/lol/math/private/ops.h
  4. +2
    -0
      include/lol/math/private/real.ipp
  5. +30
    -13
      include/lol/math/private/transform.ipp
  6. +55
    -0
      include/lol/math/private/vector.ipp
  7. +1
    -1
      include/lol/math/real.h
  8. +8
    -2
      include/lol/math/transform.h
  9. +14
    -16
      include/lol/math/vector.h
  10. +0
    -96
      legacy/math/vector.cpp

legacy/lol/math/matrix.h → include/lol/math/private/matrix.h Zobrazit soubor

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -14,13 +14,13 @@

//
// The matrix classes
// ------------------
// ——————————————————
//

#include <ostream>

#include <lol/math/private/ops.h>
#include <lol/math/vector.h>
#include <lol/math/transform.h>

#if _WIN32
# pragma push_macro("near")
@@ -29,6 +29,8 @@
# undef far
#endif

#define have_lol_matrix_h

namespace lol
{

@@ -109,7 +111,6 @@ struct lol_attr_nodiscard mat_t<T, 2, 2>
return rotate(radians) * m;
}

void printf() const;
std::string tostring() const;

static const mat_t<T,2,2> identity;
@@ -158,7 +159,7 @@ struct lol_attr_nodiscard mat_t<T, 3, 3>
explicit inline mat_t(mat_t<U,3,3> const &m)
: m_data{ (element)m[0], (element)m[1], (element)m[2] } {}

explicit mat_t(quat_t<T> const &q);
explicit mat_t(class quat_t<T> const &q);

inline vec_t<T,3>& operator[](size_t n) { return m_data[n]; }
inline vec_t<T,3> const& operator[](size_t n) const { return m_data[n]; }
@@ -201,7 +202,6 @@ struct lol_attr_nodiscard mat_t<T, 3, 3>
return rotate(radians, v) * m;
}

void printf() const;
std::string tostring() const;

static const mat_t<T,3,3> identity;
@@ -256,7 +256,7 @@ struct lol_attr_nodiscard mat_t<T, 4, 4>
: m_data{ (element)m[0], (element)m[1],
(element)m[2], (element)m[3] } {}

explicit mat_t(quat_t<T> const &q);
explicit mat_t(class quat_t<T> const &q);

inline vec_t<T,4>& operator[](size_t n) { return m_data[n]; }
inline vec_t<T,4> const& operator[](size_t n) const { return m_data[n]; }
@@ -336,7 +336,6 @@ struct lol_attr_nodiscard mat_t<T, 4, 4>
static mat_t<T,4,4> perspective(T fov_y, T width, T height, T near, T far);
static mat_t<T,4,4> shifted_perspective(T fov_y, T screen_size, T screen_ratio_yx, T near, T far);

void printf() const;
std::string tostring() const;

static const mat_t<T,4,4> identity;

legacy/math/matrix.cpp → include/lol/math/private/matrix.ipp Zobrazit soubor

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -10,52 +10,93 @@
// See http://www.wtfpl.net/ for more details.
//

#include <lol/engine-internal.h>
#pragma once

#include <cassert>
#include <cmath>

namespace lol
{

template<> mat3 mat3::scale(float x, float y, float z)
template<>
inline std::string mat2::tostring() const
{
mat2 const &p = *this;

return format("[ %6.6f %6.6f\n", p[0][0], p[1][0]) +
format(" %6.6f %6.6f ]\n", p[0][1], p[1][1]);
}

template<>
inline std::string mat3::tostring() const
{
mat3 const &p = *this;

return format("[ %6.6f %6.6f %6.6f\n", p[0][0], p[1][0], p[2][0]) +
format(" %6.6f %6.6f %6.6f\n", p[0][1], p[1][1], p[2][1]) +
format(" %6.6f %6.6f %6.6f ]\n", p[0][2], p[1][2], p[2][2]);
}

template<>
inline std::string mat4::tostring() const
{
mat3 ret(1.0f);
mat4 const &p = *this;

return format("[ %6.6f %6.6f %6.6f %6.6f\n",
p[0][0], p[1][0], p[2][0], p[3][0]) +
format(" %6.6f %6.6f %6.6f %6.6f\n",
p[0][1], p[1][1], p[2][1], p[3][1]) +
format(" %6.6f %6.6f %6.6f %6.6f\n",
p[0][2], p[1][2], p[2][2], p[3][2]) +
format(" %6.6f %6.6f %6.6f %6.6f ]\n",
p[0][3], p[1][3], p[2][3], p[3][3]);
}

template<typename T>
mat_t<T,3,3> mat_t<T,3,3>::scale(T x, T y, T z)
{
mat_t<T,3,3> ret(T(1));
ret[0][0] = x;
ret[1][1] = y;
ret[2][2] = z;

return ret;
}

template<> mat3 mat3::scale(float x)
template<typename T>
mat_t<T,3,3> mat_t<T,3,3>::scale(T x)
{
return scale(x, x, x);
}

template<> mat3 mat3::scale(vec3 v)
template<typename T>
mat_t<T,3,3> mat_t<T,3,3>::scale(vec_t<T,3> v)
{
return scale(v.x, v.y, v.z);
}

template<> mat4 mat4::translate(float x, float y, float z)
template<typename T>
mat_t<T,4,4> mat_t<T,4,4>::translate(T x, T y, T z)
{
mat4 ret(1.0f);
mat_t<T,4,4> ret(T(1));
ret[3][0] = x;
ret[3][1] = y;
ret[3][2] = z;
return ret;
}

template<> mat4 mat4::translate(vec3 v)
template<typename T>
mat_t<T,4,4> mat_t<T,4,4>::translate(vec_t<T,3> v)
{
return translate(v.x, v.y, v.z);
}

template<> mat2 mat2::rotate(float radians)
template<typename T>
mat_t<T,2,2> mat_t<T,2,2>::rotate(T radians)
{
float st = sin(radians);
float ct = cos(radians);
T st = sin(radians);
T ct = cos(radians);

mat2 ret;
mat_t<T,2,2> ret;

ret[0][0] = ct;
ret[0][1] = st;
@@ -66,22 +107,23 @@ template<> mat2 mat2::rotate(float radians)
return ret;
}

template<> mat3 mat3::rotate(float radians, float x, float y, float z)
template<typename T>
mat_t<T,3,3> mat_t<T,3,3>::rotate(T radians, T x, T y, T z)
{
float st = sin(radians);
float ct = cos(radians);
T st = sin(radians);
T ct = cos(radians);

float len = std::sqrt(x * x + y * y + z * z);
float invlen = len ? 1.0f / len : 0.0f;
T len = std::sqrt(x * x + y * y + z * z);
T invlen = len ? T(1) / len : T(0);
x *= invlen;
y *= invlen;
z *= invlen;

float mtx = (1.0f - ct) * x;
float mty = (1.0f - ct) * y;
float mtz = (1.0f - ct) * z;
T mtx = (T(1) - ct) * x;
T mty = (T(1) - ct) * y;
T mtz = (T(1) - ct) * z;

mat3 ret;
mat_t<T,3,3> ret;

ret[0][0] = x * mtx + ct;
ret[0][1] = x * mty + st * z;
@@ -98,44 +140,50 @@ template<> mat3 mat3::rotate(float radians, float x, float y, float z)
return ret;
}

template<> mat3 mat3::rotate(float radians, vec3 v)
template<typename T>
mat_t<T,3,3> mat_t<T,3,3>::rotate(T radians, vec_t<T,3> v)
{
return rotate(radians, v.x, v.y, v.z);
}

template<> mat3::mat_t(quat const &q)
template<typename T>
mat_t<T,3,3>::mat_t(quat_t<T> const &q)
{
float n = norm(q);
T n = norm(q);

if (!n)
{
for (int j = 0; j < 3; j++)
for (int i = 0; i < 3; i++)
(*this)[i][j] = (i == j) ? 1.f : 0.f;
(*this)[i][j] = (i == j) ? T(1) : T(0);
return;
}

float s = 2.0f / n;
T s = T(2) / n;

(*this)[0][0] = 1.0f - s * (q.y * q.y + q.z * q.z);
(*this)[0][0] = T(1) - s * (q.y * q.y + q.z * q.z);
(*this)[0][1] = s * (q.x * q.y + q.z * q.w);
(*this)[0][2] = s * (q.x * q.z - q.y * q.w);

(*this)[1][0] = s * (q.x * q.y - q.z * q.w);
(*this)[1][1] = 1.0f - s * (q.z * q.z + q.x * q.x);
(*this)[1][1] = T(1) - s * (q.z * q.z + q.x * q.x);
(*this)[1][2] = s * (q.y * q.z + q.x * q.w);

(*this)[2][0] = s * (q.x * q.z + q.y * q.w);
(*this)[2][1] = s * (q.y * q.z - q.x * q.w);
(*this)[2][2] = 1.0f - s * (q.x * q.x + q.y * q.y);
(*this)[2][2] = T(1) - s * (q.x * q.x + q.y * q.y);
}

template<> mat4::mat_t(quat const &q)
template<typename T>
mat_t<T,4,4>::mat_t(quat_t<T> const &q)
{
*this = mat4(mat3(q), 1.f);
*this = mat_t<T,4,4>(mat_t<T,3,3>(q), T(1));
}

template<> mat4 mat4::lookat(vec3 eye, vec3 center, vec3 up)
// These are only specialised for float type, but could be extended
// to anything else. I’m just not sure it’s worth it.
template<>
inline mat4 mat4::lookat(vec3 eye, vec3 center, vec3 up)
{
vec3 v3 = normalize(eye - center);
vec3 v1 = normalize(cross(up, v3));
@@ -147,8 +195,9 @@ template<> mat4 mat4::lookat(vec3 eye, vec3 center, vec3 up)
vec4(-dot(eye, v1), -dot(eye, v2), -dot(eye, v3), 1.f));
}

template<> mat4 mat4::ortho(float left, float right, float bottom,
float top, float near, float far)
template<>
inline mat4 mat4::ortho(float left, float right, float bottom,
float top, float near, float far)
{
float invrl = (right != left) ? 1.0f / (right - left) : 0.0f;
float invtb = (top != bottom) ? 1.0f / (top - bottom) : 0.0f;
@@ -165,15 +214,17 @@ template<> mat4 mat4::ortho(float left, float right, float bottom,
return ret;
}

template<> mat4 mat4::ortho(float width, float height,
float near, float far)
template<>
inline mat4 mat4::ortho(float width, float height,
float near, float far)
{
return mat4::ortho(-0.5f * width, 0.5f * width,
-0.5f * height, 0.5f * height, near, far);
}

template<> mat4 mat4::frustum(float left, float right, float bottom,
float top, float near, float far)
template<>
inline mat4 mat4::frustum(float left, float right, float bottom,
float top, float near, float far)
{
float invrl = (right != left) ? 1.0f / (right - left) : 0.0f;
float invtb = (top != bottom) ? 1.0f / (top - bottom) : 0.0f;
@@ -194,8 +245,9 @@ template<> mat4 mat4::frustum(float left, float right, float bottom,
* Return a standard perspective matrix
*/

template<> mat4 mat4::perspective(float fov_y, float width,
float height, float near, float far)
template<>
inline mat4 mat4::perspective(float fov_y, float width,
float height, float near, float far)
{
float t2 = lol::tan(fov_y * 0.5f);
float t1 = t2 * width / height;
@@ -208,12 +260,13 @@ template<> mat4 mat4::perspective(float fov_y, float width,
* the near plane
*/

template<> mat4 mat4::shifted_perspective(float fov_y, float screen_size,
float screen_ratio_yx,
float near, float far)
template<>
inline mat4 mat4::shifted_perspective(float fov_y, float screen_size,
float screen_ratio_yx,
float near, float far)
{
float tan_y = tanf(fov_y * .5f);
ASSERT(tan_y > 0.000001f);
assert(tan_y > 0.000001f);
float dist_scr = (screen_size * screen_ratio_yx * .5f) / tan_y;

return mat4::perspective(fov_y, screen_size, screen_size * screen_ratio_yx,

legacy/lol/math/ops.h → include/lol/math/private/ops.h Zobrazit soubor

@@ -1,18 +1,20 @@
//
// Lol Engine
// Lol Engine
//
// Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//

#pragma once

//
// Operations for vector classes
// -----------------------------
// —————————————————————————————
//

#include <ostream>

include/lol/math/real.ipp → include/lol/math/private/real.ipp Zobrazit soubor

@@ -10,6 +10,8 @@
// See http://www.wtfpl.net/ for more details.
//

#pragma once

#include <new>
#include <string>
#include <sstream>

legacy/math/transform.cpp → include/lol/math/private/transform.ipp Zobrazit soubor

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -10,12 +10,26 @@
// See http://www.wtfpl.net/ for more details.
//

#include <lol/engine-internal.h>
#pragma once

namespace lol
{

template<> quat quat::rotate(float radians, vec3 const &v)
template<>
inline std::string cmplx::tostring() const
{
return format("[ %6.6f %6.6f ]", x, y);
}

template<>
inline std::string quat::tostring() const
{
return format("[ %6.6f %6.6f %6.6f %6.6f ]", w, x, y, z);

}

template<>
inline quat quat::rotate(float radians, vec3 const &v)
{
float half_angle = radians * 0.5f;

@@ -24,12 +38,14 @@ template<> quat quat::rotate(float radians, vec3 const &v)
return quat(cos(half_angle), tmp.x, tmp.y, tmp.z);
}

template<> quat quat::rotate(float radians, float x, float y, float z)
template<>
inline quat quat::rotate(float radians, float x, float y, float z)
{
return quat::rotate(radians, vec3(x, y, z));
}

template<> quat quat::rotate(vec3 const &src, vec3 const &dst)
template<>
inline quat quat::rotate(vec3 const &src, vec3 const &dst)
{
/* Algorithm directly taken from Sam Hocevar's article "Quaternion from
* two vectors: the final version".
@@ -56,7 +72,8 @@ template<> quat quat::rotate(vec3 const &src, vec3 const &dst)
return normalize(quat(real_part, w.x, w.y, w.z));
}

template<> quat slerp(quat const &qa, quat const &qb, float f)
template<>
inline quat slerp(quat const &qa, quat const &qb, float f)
{
float const magnitude = lol::sqrt(sqlength(qa) * sqlength(qb));
float const product = lol::dot(qa, qb) / magnitude;
@@ -199,43 +216,43 @@ static inline quat quat_fromeuler_generic(vec3 const &v, int i, int j, int k)

#define DEFINE_GENERIC_EULER_CONVERSIONS_INNER(a1, a2, a3, name) \
/* Create quaternions from Euler angles */ \
template<> quat quat::fromeuler_##name(vec3 const &v) \
template<> inline quat quat::fromeuler_##name(vec3 const &v) \
{ \
int x = 0, y = 1, z = 2; UNUSED(x, y, z); \
return quat_fromeuler_generic(v, a1, a2, a3); \
} \
\
template<> quat quat::fromeuler_##name(float phi, float theta, float psi) \
template<> inline quat quat::fromeuler_##name(float phi, float theta, float psi) \
{ \
return quat::fromeuler_##name(vec3(phi, theta, psi)); \
} \
\
/* Create 3×3 matrices from Euler angles */ \
template<> mat3 mat3::fromeuler_##name(vec3 const &v) \
template<> inline mat3 mat3::fromeuler_##name(vec3 const &v) \
{ \
int x = 0, y = 1, z = 2; UNUSED(x, y, z); \
return mat3_fromeuler_generic(v, a1, a2, a3); \
} \
\
template<> mat3 mat3::fromeuler_##name(float phi, float theta, float psi) \
template<> inline mat3 mat3::fromeuler_##name(float phi, float theta, float psi) \
{ \
return mat3::fromeuler_##name(vec3(phi, theta, psi)); \
} \
\
/* Create 4×4 matrices from Euler angles */ \
template<> mat4 mat4::fromeuler_##name(vec3 const &v) \
template<> inline mat4 mat4::fromeuler_##name(vec3 const &v) \
{ \
int x = 0, y = 1, z = 2; UNUSED(x, y, z); \
return mat4(mat3_fromeuler_generic(v, a1, a2, a3), 1.f); \
} \
\
template<> mat4 mat4::fromeuler_##name(float phi, float theta, float psi) \
template<> inline mat4 mat4::fromeuler_##name(float phi, float theta, float psi) \
{ \
return mat4::fromeuler_##name(vec3(phi, theta, psi)); \
} \
\
/* Retrieve Euler angles from a quaternion */ \
template<> vec3 vec3::toeuler_##name(quat const &q) \
template<> inline vec3 vec3::toeuler_##name(quat const &q) \
{ \
int x = 0, y = 1, z = 2; UNUSED(x, y, z); \
return quat_toeuler_generic(q, a1, a2, a3); \

+ 55
- 0
include/lol/math/private/vector.ipp Zobrazit soubor

@@ -0,0 +1,55 @@
//
// Lol Engine
//
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//

#pragma once

namespace lol
{

template<>
inline std::string vec2::tostring() const
{
return format("[ %6.6f %6.6f ]", x, y);
}

template<>
inline std::string ivec2::tostring() const
{
return format("[ %i %i ]", x, y);
}

template<>
inline std::string vec3::tostring() const
{
return format("[ %6.6f %6.6f %6.6f ]", x, y, z);
}

template<>
inline std::string ivec3::tostring() const
{
return format("[ %i %i %i ]", x, y, z);
}

template<>
inline std::string vec4::tostring() const
{
return format("[ %6.6f %6.6f %6.6f %6.6f ]", x, y, z, w);
}

template<>
inline std::string ivec4::tostring() const
{
return format("[ %i %i %i %i ]", x, y, z, w);
}

} /* namespace lol */


+ 1
- 1
include/lol/math/real.h Zobrazit soubor

@@ -376,5 +376,5 @@ template<> std::string real::xstr() const;

} /* namespace lol */

#include "real.ipp"
#include "private/real.ipp"


legacy/lol/math/transform.h → include/lol/math/transform.h Zobrazit soubor

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -14,13 +14,16 @@

//
// The complex, quaternion and dual quaternion classes
// ---------------------------------------------------
// ———————————————————————————————————————————————————
//

#include <lol/math/private/ops.h>
#include <lol/math/vector.h>

#include <ostream>

#include "private/matrix.h"

namespace lol
{

@@ -497,3 +500,6 @@ static inline sqt_t<T> operator /(sqt_t<T> const &x, sqt_t<T> const &y)

} /* namespace lol */

#include "private/matrix.ipp"
#include "private/transform.ipp"


legacy/lol/math/vector.h → include/lol/math/vector.h Zobrazit soubor

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -14,15 +14,12 @@

//
// The vector classes
// ------------------
// ——————————————————
//

#include <lol/base/assert.h>
#include <lol/math/functions.h>
#include <lol/math/half.h>
#include <lol/math/real.h>
#include <lol/math/ops.h>
#include <lol/math/private/ops.h>

#include <cassert>
#include <ostream>
#include <type_traits>

@@ -112,7 +109,6 @@ private:
return *this; \
} \
\
void printf() const; \
std::string tostring() const;

/* The generic “vec_t” type, which is a fixed-size vector with no
@@ -166,8 +162,8 @@ struct lol_attr_nodiscard vec_t<T, N, FULL_SWIZZLE>
/* Factory for base axis vectors, e.g. [1,0,0,…,0] */
static inline vec_t<T, N> axis(int i)
{
ASSERT(i >= 0);
ASSERT(i < N);
assert(i >= 0);
assert(i < N);
vec_t<T, N> ret(T(0));
ret[i] = T(1);
return ret;
@@ -250,8 +246,8 @@ struct lol_attr_nodiscard vec_t<T,2>
/* Factory for base axis vectors, e.g. [1,0,0,…,0] */
static inline vec_t<T,2> axis(int i)
{
ASSERT(i >= 0);
ASSERT(i < 2);
assert(i >= 0);
assert(i < 2);
return vec_t<T,2>(T(i == 0), T(i == 1));
}

@@ -365,8 +361,8 @@ struct lol_attr_nodiscard vec_t<T,3>
/* Factory for base axis vectors, e.g. [1,0,0,…,0] */
static inline vec_t<T,3> axis(int i)
{
ASSERT(i >= 0);
ASSERT(i < 3);
assert(i >= 0);
assert(i < 3);
return vec_t<T,3>(T(i == 0), T(i == 1), T(i == 2));
}

@@ -614,8 +610,8 @@ struct lol_attr_nodiscard vec_t<T,4>
/* Factory for base axis vectors, e.g. [1,0,0,…,0] */
static inline vec_t<T,4> axis(int i)
{
ASSERT(i >= 0);
ASSERT(i < 4);
assert(i >= 0);
assert(i < 4);
return vec_t<T,4>(T(i == 0), T(i == 1), T(i == 2), T(i == 3));
}

@@ -1347,3 +1343,5 @@ vec_t<T,4> const vec_t<T,4>::axis_w = vec_t<T,4>(T(0), T(0), T(0), T(1));

} /* namespace lol */

#include "private/vector.ipp"


+ 0
- 96
legacy/math/vector.cpp Zobrazit soubor

@@ -1,96 +0,0 @@
//
// Lol Engine
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//

#include <lol/engine-internal.h>

#include <ostream> /* std::ostream */

namespace lol
{

#define LOL_PRINTF_TOSTRING(type, ...) \
template<> void type::printf() const { msg::debug(__VA_ARGS__); } \
template<> std::string type::tostring() const { return format(__VA_ARGS__); }

LOL_PRINTF_TOSTRING(vec2, "[ %6.6f %6.6f ]\n", x, y);
LOL_PRINTF_TOSTRING(ivec2, "[ %i %i ]\n", x, y);
LOL_PRINTF_TOSTRING(cmplx, "[ %6.6f %6.6f ]\n", x, y);
LOL_PRINTF_TOSTRING(vec3, "[ %6.6f %6.6f %6.6f ]\n", x, y, z);
LOL_PRINTF_TOSTRING(ivec3, "[ %i %i %i ]\n", x, y, z);
LOL_PRINTF_TOSTRING(vec4, "[ %6.6f %6.6f %6.6f %6.6f ]\n", x, y, z, w);
LOL_PRINTF_TOSTRING(ivec4, "[ %i %i %i %i ]\n", x, y, z, w);
LOL_PRINTF_TOSTRING(quat, "[ %6.6f %6.6f %6.6f %6.6f ]\n", w, x, y, z);

template<> void mat2::printf() const
{
mat2 const &p = *this;

msg::debug("[ %6.6f %6.6f\n", p[0][0], p[1][0]);
msg::debug(" %6.6f %6.6f ]\n", p[0][1], p[1][1]);
}

template<> std::string mat2::tostring() const
{
mat2 const &p = *this;

return format("[ %6.6f %6.6f\n", p[0][0], p[1][0]) +
format(" %6.6f %6.6f ]\n", p[0][1], p[1][1]);
}

template<> void mat3::printf() const
{
mat3 const &p = *this;

msg::debug("[ %6.6f %6.6f %6.6f\n", p[0][0], p[1][0], p[2][0]);
msg::debug(" %6.6f %6.6f %6.6f\n", p[0][1], p[1][1], p[2][1]);
msg::debug(" %6.6f %6.6f %6.6f ]\n", p[0][2], p[1][2], p[2][2]);
}

template<> std::string mat3::tostring() const
{
mat3 const &p = *this;

return format("[ %6.6f %6.6f %6.6f\n", p[0][0], p[1][0], p[2][0]) +
format(" %6.6f %6.6f %6.6f\n", p[0][1], p[1][1], p[2][1]) +
format(" %6.6f %6.6f %6.6f ]\n", p[0][2], p[1][2], p[2][2]);
}

template<> void mat4::printf() const
{
mat4 const &p = *this;

msg::debug("[ %6.6f %6.6f %6.6f %6.6f\n",
p[0][0], p[1][0], p[2][0], p[3][0]);
msg::debug(" %6.6f %6.6f %6.6f %6.6f\n",
p[0][1], p[1][1], p[2][1], p[3][1]);
msg::debug(" %6.6f %6.6f %6.6f %6.6f\n",
p[0][2], p[1][2], p[2][2], p[3][2]);
msg::debug(" %6.6f %6.6f %6.6f %6.6f ]\n",
p[0][3], p[1][3], p[2][3], p[3][3]);
}

template<> std::string mat4::tostring() const
{
mat4 const &p = *this;

return format("[ %6.6f %6.6f %6.6f %6.6f\n",
p[0][0], p[1][0], p[2][0], p[3][0]) +
format(" %6.6f %6.6f %6.6f %6.6f\n",
p[0][1], p[1][1], p[2][1], p[3][1]) +
format(" %6.6f %6.6f %6.6f %6.6f\n",
p[0][2], p[1][2], p[2][2], p[3][2]) +
format(" %6.6f %6.6f %6.6f %6.6f ]\n",
p[0][3], p[1][3], p[2][3], p[3][3]);
}

} /* namespace lol */


Načítá se…
Zrušit
Uložit