Commit af92e00d authored by Philip Trettner's avatar Philip Trettner

working on making glm optional

parent 513580fb
......@@ -196,8 +196,6 @@ if(TARGET glm)
target_link_libraries(glow PUBLIC glm)
target_compile_definitions(glow PUBLIC GLOW_USE_GLM)
target_compile_definitions(glow PUBLIC GLOW_HAS_GLM)
else()
message(FATAL_ERROR "no target 'glm' found. GLOW requires either glm or typed-geometry. Is a submodule/dependency missing?")
endif()
# typed geometry
......
......@@ -4,10 +4,12 @@ from Cheetah.Template import Template
#outCodeDir = "/home/ptrettner/projects/glow-tests/libs/glow/src/glow/objects/"
#outTestDir = "/home/ptrettner/projects/glow-tests/src/objects/tex-gen/"
outCodeDir = "/home/ptrettner/projects/glow-minimal/extern/glow/src/glow/objects/"
outTestDir = None
#outCodeDir = "/mnt/c/Users/Kunstwald/workspace/glow-samples/glow/src/glow/objects/"
#outTestDir = "/mnt/c/Users/Kunstwald/workspace/glow-tex-tests/"
outCodeDir = "/home/jkunstwald/workspace/glow-samples/extern/glow/src/glow/objects/"
outTestDir = "/home/jkunstwald/workspace/glow-tests/src/objects/tex-gen/"
#outCodeDir = "/home/jkunstwald/workspace/glow-samples/extern/glow/src/glow/objects/"
#outTestDir = "/home/jkunstwald/workspace/glow-tests/src/objects/tex-gen/"
texTypes = {
"GL_TEXTURE_1D": {
......@@ -166,7 +168,7 @@ def main():
context["dimCall"] = ", ".join(list(map(lambda x: "m" + x, context["sizeMember"])) + ["1", "1", "1"][0:3-len(context["sizeVars"])])
context["sizeMemberCall"] = ", ".join(list(map(lambda x: "m" + x, context["sizeMember"])))
context["sizeMemberCallBound"] = ", ".join(map(lambda x: "texture->m" + x, context["sizeMember"]))
context["sizeExpandCall"] = ", ".join(["size.x", "size.y", "size.z", "size.w"][0:len(context["sizeVars"])])
context["sizeExpandCall"] = ", ".join(["size.width", "size.height", "size.depth", "size.w"][0:len(context["sizeVars"])])
t = Template(file='texture.hh.tmpl', searchList=context)
writeIfDiff(outCodeDir + str(className) + ".hh", str(t))
......@@ -174,8 +176,9 @@ def main():
t = Template(file='texture.cc.tmpl', searchList=context)
writeIfDiff(outCodeDir + str(className) + ".cc", str(t))
t = Template(file='texture.test.cc.tmpl', searchList=context)
writeIfDiff(outTestDir + str(className) + ".cc", str(t))
if outTestDir is not None:
t = Template(file='texture.test.cc.tmpl', searchList=context)
writeIfDiff(outTestDir + str(className) + ".cc", str(t))
if __name__ == "__main__":
......
......@@ -2,9 +2,8 @@
\#include "${class}.hh"
\#include <typed-geometry/common/assert.hh>
\#include <glm/glm.hpp>
\#include <glm/ext.hpp>
\#include <typed-geometry/common/scalar_math.hh>
\#include <typed-geometry/functions/minmax.hh>
\#include <glow/data/SurfaceData.hh>
\#include <glow/data/TextureData.hh>
......@@ -177,11 +176,11 @@ void $class::Bound$class::makeStorageImmutable(${sizeParameter}, GLenum internal
#if $hasMipmaps
if (mipmapLevels <= 0)
#if $dims == 1
mipmapLevels = glm::floor(glm::log2((float)width)) + 1;
mipmapLevels = tg::floor(tg::log2((float)width)) + 1;
#elif $dims == 2
mipmapLevels = glm::floor(glm::log2(glm::max((float)width, (float)height))) + 1;
mipmapLevels = tg::floor(tg::log2(tg::max((float)width, (float)height))) + 1;
#elif $dims == 3
mipmapLevels = glm::floor(glm::log2(glm::max((float)width, glm::max((float)height, (float)depth)))) + 1;
mipmapLevels = tg::floor(tg::log2(tg::max((float)width, (float)height, (float)depth))) + 1;
#else
\#error "not implemented"
#end if
......@@ -265,18 +264,18 @@ void $class::Bound$class::setAnisotropicFiltering(GLfloat samples)
return;
checkValidGLOW();
samples = glm::clamp(samples, 1.f, limits::maxAnisotropy);
samples = tg::clamp(samples, 1.f, limits::maxAnisotropy);
glTexParameterf(texture->mTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, samples);
texture->mAnisotropicFiltering = samples;
}
void $class::Bound$class::setBorderColor(glm::vec4 const& color)
void $class::Bound$class::setBorderColor(tg::color4 const& color)
{
if (!isCurrent())
return;
checkValidGLOW();
glTexParameterfv(texture->mTarget, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(color));
glTexParameterfv(texture->mTarget, GL_TEXTURE_BORDER_COLOR, &color.r);
texture->mBorderColor = color;
}
......@@ -580,7 +579,7 @@ void $class::Bound$class::setData(GLenum internalFormat, const SharedTextureData
setMinFilter(data->getMinFilter());
if (data->getMagFilter() != GL_INVALID_ENUM)
setMagFilter(data->getMagFilter());
if (data->getBorderColor() != glm::vec4(-1))
if (data->getBorderColor() != tg::color4(-1))
setBorderColor(data->getBorderColor());
#if not $cubemap
#for $C in $texCoords
......@@ -629,8 +628,8 @@ void $class::clear(GLenum format, GLenum type, const GLvoid* data#if $hasMipmaps
int w = mWidth;
int h = mHeight;
#if $hasMipmaps
w = glm::max(1, w >> mipmapLevel);
h = glm::max(1, h >> mipmapLevel);
w = tg::max(1, w >> mipmapLevel);
h = tg::max(1, h >> mipmapLevel);
#end if
rawdata.resize(stride * w * h);
auto bdata = (uint8_t const *)data;
......
......@@ -11,9 +11,7 @@
\#include <vector>
\#include <glm/vec2.hpp>
\#include <glm/vec3.hpp>
\#include <glm/vec4.hpp>
\#include <typed-geometry/tg-lean.hh>
namespace glow
{
......@@ -29,7 +27,7 @@ public:
#if $storageDim == 1
using SizeT = int;
#else
using SizeT = glm::ivec$storageDim;
using SizeT = tg::isize$storageDim;
#end if
struct Shape
......@@ -58,7 +56,7 @@ private:
GLenum mMagFilter = GL_LINEAR;
/// Border color
glm::vec4 mBorderColor = {0.0f, 0.0f, 0.0f, 0.0f};
tg::color4 mBorderColor = {0.0f, 0.0f, 0.0f, 0.0f};
#for $C in $texCoords
/// Wrapping in $C
......@@ -124,7 +122,7 @@ public: // getter
#if $hasTexParams
GLenum getMinFilter() const { return mMinFilter; }
GLenum getMagFilter() const { return mMagFilter; }
glm::vec4 getBorderColor() const { return mBorderColor; }
tg::color4 getBorderColor() const { return mBorderColor; }
#for $C in $texCoords
GLenum getWrap${C}() const { return mWrap$C; }
#end for
......@@ -137,7 +135,7 @@ public: // getter
#for $S in $sizeMember
int get${S}() const { return m${S}; }
#end for
glm::ivec3 getDimensions() const override { return { $dimCall }; }
tg::isize3 getDimensions() const override { return { $dimCall }; }
#if $storageDim > 1
SizeT getSize() const { return { $sizeMemberCall }; }
#end if
......@@ -210,7 +208,7 @@ public:
void setAnisotropicFiltering(GLfloat samples);
/// Sets the border color
void setBorderColor(glm::vec4 const& color);
void setBorderColor(tg::color4 const& color);
#for $C in $texCoords
/// Sets texture wrapping in $C
......@@ -272,7 +270,7 @@ public:
/// Generic data uploads
/// Changes internal format, ${sizeParameterCall}, and data
void setData(GLenum internalFormat#if $cubemap #, GLenum target#end if #, ${sizeParameter}, GLenum format, GLenum type, const GLvoid* data#if $hasMipmaps #, int mipmapLevel = 0#end if #);
/// Data upload via glm or c++ type (see gltypeinfo)
/// Data upload via glm, tg, or c++ type (see gltypeinfo)
template <typename DataT>
void setData(GLenum internalFormat#if $cubemap #, GLenum target#end if #, ${sizeParameter}, std::vector<DataT> const& data#if $hasMipmaps #, int mipmapLevel = 0#end if #)
{
......@@ -286,7 +284,7 @@ public:
}
/// Same as above
/// Usage:
/// glm::vec3 texData[] = { ... }
/// tg::vec3 texData[] = { ... }
/// setData(iFormat, ${sizeParameterCall}, texData);
template <typename DataT, std::size_t N>
void setData(GLenum internalFormat#if $cubemap #, GLenum target#end if #, ${sizeParameter}, const DataT(&data)[N]#if $hasMipmaps #, int mipmapLevel = 0#end if #)
......@@ -301,7 +299,7 @@ public:
}
/// Same as above
/// Usage:
/// glm::vec3 texData[][] = { ... }
/// tg::vec3 texData[][] = { ... }
/// // it's #echo "".join(["[" + P + "]" for P in $sizeVarsReverse])#
/// setData(iFormat, texData);
template <typename DataT, $sizeParameter>
......@@ -313,7 +311,7 @@ public:
/// Generic partial data uploads
/// Only changes data. Offset and size must be inside original bounds.
void setSubData(#if $cubemap #GLenum target, #end if #${offsetParameter}, ${sizeParameter}, GLenum format, GLenum type, const GLvoid* data#if $hasMipmaps #, int mipmapLevel = 0#end if #);
/// Partial data upload via glm or c++ type (see gltypeinfo)
/// Partial data upload via glm, tg, or c++ type (see gltypeinfo)
template <typename DataT>
void setSubData(#if $cubemap #GLenum target, #end if #${offsetParameter}, ${sizeParameter}, std::vector<DataT> const& data#if $hasMipmaps #, int mipmapLevel = 0#end if #)
{
......@@ -327,7 +325,7 @@ public:
}
/// Same as above
/// Usage:
/// glm::vec3 texData[] = { ... }
/// tg::vec3 texData[] = { ... }
/// setSubData(${offsetParameterCall}, ${sizeParameterCall}, texData);
template <typename DataT, std::size_t N>
void setSubData(#if $cubemap #GLenum target, #end if #${offsetParameter}, ${sizeParameter}, const DataT(&data)[N]#if $hasMipmaps #, int mipmapLevel = 0#end if #)
......@@ -342,7 +340,7 @@ public:
}
/// Same as above
/// Usage:
/// glm::vec3 texData[][] = { ... }
/// tg::vec3 texData[][] = { ... }
/// // it's #echo "".join(["[" + P + "]" for P in $sizeVarsReverse])#
/// setSubData(${offsetParameterCall}, texData);
template <typename DataT, $sizeParameter>
......@@ -360,7 +358,7 @@ public:
std::vector<char> getData(GLenum format, GLenum type#if $hasMipmaps #, int mipmapLevel = 0#end if #);
/// Generic data download
void getData(GLenum format, GLenum type, size_t bufferSize, void* buffer#if $hasMipmaps #, int mipmapLevel = 0#end if #);
/// Data download via glm or c++ type (see gltypeinfo)
/// Data download via glm, tg, or c++ type (see gltypeinfo)
template <typename DataT>
std::vector<DataT> getData(int mipmapLevel = 0)
{
......@@ -375,7 +373,7 @@ public:
std::vector<char> getSubData(GLenum format, GLenum type, ${offsetParameter}, ${sizeParameter}#if $hasMipmaps #, int mipmapLevel = 0#end if #);
/// Generic partial data download
void getSubData(GLenum format, GLenum type, ${offsetParameter}, ${sizeParameter}, size_t bufferSize, void* buffer#if $hasMipmaps #, int mipmapLevel = 0#end if #);
/// Partial data download via glm or c++ type (see gltypeinfo)
/// Partial data download via glm, tg, or c++ type (see gltypeinfo)
template <typename DataT>
std::vector<DataT> getSubData(${offsetParameter}, ${sizeParameter}, int mipmapLevel = 0)
{
......@@ -413,7 +411,7 @@ public:
/// Fills the specific mipmap level (default 0) with the given data
/// Requires OpenGL 4.4 (for now) and will throw a run-time error otherwise
void clear(GLenum format, GLenum type, const GLvoid* data#if $hasMipmaps #, int mipmapLevel = 0#end if #);
/// Clear via glm or c++ type (see gltypeinfo)
/// Clear via glm, tg, or c++ type (see gltypeinfo)
/// CAREFUL: pointers do not work!
template <typename DataT>
void clear(DataT const& data#if $hasMipmaps #, int mipmapLevel = 0#end if #)
......
......@@ -2,6 +2,7 @@
#include <glow/common/log.hh>
#ifdef GLOW_HAS_GLM
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
......@@ -15,6 +16,7 @@
#include <glm/mat4x2.hpp>
#include <glm/mat4x3.hpp>
#include <glm/mat4x4.hpp>
#endif
#ifdef GLOW_HAS_TG
#include <typed-geometry/tg-lean.hh>
......@@ -89,6 +91,7 @@ template <>
detail::glBaseType glTypeOf<double>::basetype = detail::glBaseType::Double;
#ifdef GLOW_HAS_GLM
// ==========================================================
// GLM Types
template <>
......@@ -234,6 +237,8 @@ template <>
detail::glBaseType glTypeOf<glm::dmat4x3>::basetype = detail::glBaseType::Double;
template <>
detail::glBaseType glTypeOf<glm::dmat4x4>::basetype = detail::glBaseType::Double;
#endif
#ifdef GLOW_HAS_TG
// ==========================================================
......
......@@ -7,8 +7,7 @@
#include <glow/common/traits.hh>
#include <glow/gl.hh>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <typed-geometry/types/color.hh>
#include <initializer_list>
......@@ -333,10 +332,10 @@ struct clearColor
GLfloat color[4];
template <class T, class = decltype(detail::get_color4(T()))>
explicit clearColor(T const& v) : clearColor(static_cast<glm::vec4 const&>(detail::get_color4(v)))
explicit clearColor(T const& v) : clearColor(static_cast<tg::color4 const&>(detail::get_color4(v)))
{
}
explicit clearColor(glm::vec4 const& c) : clearColor(c.r, c.g, c.b, c.a) {}
explicit clearColor(tg::color4 const& c) : clearColor(c.r, c.g, c.b, c.a) {}
clearColor(float r, float g, float b, float a)
{
glGetFloatv(GL_COLOR_CLEAR_VALUE, color);
......@@ -351,12 +350,12 @@ struct blendColor
GLfloat color[4];
template <class T, class = decltype(detail::get_color4(T()))>
explicit blendColor(T const& v) : blendColor(static_cast<glm::vec4 const&>(detail::get_color4(v)))
explicit blendColor(T const& v) : blendColor(static_cast<tg::color4 const&>(detail::get_color4(v)))
{
}
explicit blendColor(glm::vec4 const& c) : blendColor(c.r, c.g, c.b, c.a) {}
explicit blendColor(tg::color4 const& c) : blendColor(c.r, c.g, c.b, c.a) {}
blendColor(float r, float g, float b, float a)
{
glGetFloatv(GL_BLEND_COLOR, color);
......
#pragma once
#ifdef GLOW_HAS_GLM
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#endif
#ifdef GLOW_HAS_TG
#include <typed-geometry/tg-lean.hh>
#include <typed-geometry/types/color.hh>
#endif
namespace glow
{
namespace detail
{
// TODO: make proper conversion once glow is switched over to tg
inline glm::vec4 get_color4(glm::vec3 v) { return {v.x, v.y, v.z, 1}; }
inline glm::vec4 get_color4(glm::vec4 v) { return v; }
#ifdef GLOW_HAS_GLM
inline tg::color4 get_color4(glm::vec3 v) { return {v.x, v.y, v.z, 1}; }
inline tg::color4 get_color4(glm::vec4 v) { return {v.x, v.y, v.z, v.w}; }
#endif
#ifdef GLOW_HAS_TG
inline glm::vec4 get_color4(tg::color3 c) { return {c.r, c.g, c.b, 1}; }
inline glm::vec4 get_color4(tg::color4 c) { return {c.r, c.g, c.b, c.a}; }
inline tg::color4 get_color4(tg::color3 c) { return {c.r, c.g, c.b, 1}; }
inline tg::color4 get_color4(tg::color4 c) { return {c.r, c.g, c.b, c.a}; }
#endif
}
}
......@@ -8,7 +8,7 @@
#include "ColorSpace.hh"
#include <glm/vec4.hpp>
#include <typed-geometry/tg-lean.hh>
#include <functional>
#include <string>
......@@ -61,7 +61,7 @@ private:
GLenum mPreferredInternalFormat = GL_INVALID_ENUM;
glm::vec4 mBorderColor = glm::vec4(-1);
tg::color4 mBorderColor = tg::color4(-1);
/// List of data surfaces in this texture
std::vector<SharedSurfaceData> mSurfaces;
......@@ -108,8 +108,8 @@ public:
void serialize(Archive& ar)
{
ar(mWidth, mHeight, mDepth, mTarget, mWrapS, mWrapT, mWrapR, mMinFilter, mMagFilter, mCompareMode,
mCompareFunction, mAnisotropicFiltering, mPreferredInternalFormat, mBorderColor.x, mBorderColor.y,
mBorderColor.z, mBorderColor.w, mSurfaces, mMetadata);
mCompareFunction, mAnisotropicFiltering, mPreferredInternalFormat, mBorderColor.r, mBorderColor.g,
mBorderColor.b, mBorderColor.a, mSurfaces, mMetadata);
}
public: // serialization
......
#include "transform.hh"
#include <iostream>
#include <typed-geometry/tg-std.hh>
const glow::transform glow::transform::Identity = transform();
std::string glow::to_string(glow::transform const& t)
{
std::stringstream ss;
ss << "[" << t.position << ", " << t.rotation << ", " << t.scale << "]";
return ss.str();
}
std::ostream& glow::operator<<(std::ostream& stream, glow::transform const& t)
{
stream << to_string(t);
return stream;
}
#pragma once
#include <iostream>
#include <sstream>
#include <glm/ext.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/matrix_inverse.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/matrix_decompose.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/transform.hpp>
#include <iosfwd>
#include <typed-geometry/feature/quat.hh>
#include <typed-geometry/tg.hh>
namespace glow
{
......@@ -21,49 +13,22 @@ public:
const static transform Identity;
/// Directions
static glm::vec3 Forward() { return {0, 0, -1}; }
static glm::vec3 Up() { return {0, 1, 0}; }
static glm::vec3 Right() { return {1, 0, 0}; }
static glm::quat RotationFromDirection(glm::vec3 const& direction, glm::vec3 const& up = Up())
{
float directionLength = glm::length(direction);
if (directionLength <= 0.001f)
return glm::quat();
glm::vec3 const normalizedDirection = direction / directionLength;
glm::vec3 const rightVector = glm::normalize(glm::cross(normalizedDirection, up));
glm::vec3 const upVector = glm::cross(rightVector, normalizedDirection);
glm::mat3 rotMatrix;
rotMatrix[0][0] = rightVector.x;
rotMatrix[0][1] = upVector.x;
rotMatrix[0][2] = -normalizedDirection.x;
rotMatrix[1][0] = rightVector.y;
rotMatrix[1][1] = upVector.y;
rotMatrix[1][2] = -normalizedDirection.y;
rotMatrix[2][0] = rightVector.z;
rotMatrix[2][1] = upVector.z;
rotMatrix[2][2] = -normalizedDirection.z;
return glm::quat(rotMatrix);
}
static tg::vec3 Forward() { return {0, 0, -1}; }
static tg::vec3 Up() { return {0, 1, 0}; }
static tg::vec3 Right() { return {1, 0, 0}; }
public:
glm::vec3 position{0};
glm::quat rotation{};
glm::vec3 scale{1};
tg::pos3 position = tg::pos3::zero;
tg::quat rotation = tg::quat::identity;
float scale = 1.f;
public:
transform() = default;
transform(glm::vec3 const& pos, glm::quat const& rot = glm::quat{}, glm::vec3 const& scale = glm::vec3{1})
: position(pos), rotation(rot), scale(scale)
{
}
transform(tg::pos3 const& pos, tg::quat const& rot = tg::quat::identity, float scale = 1.f) : position(pos), rotation(rot), scale(scale) {}
/// Constructor from Model Matrix
transform(glm::mat4 m)
explicit transform(tg::mat4 m)
{
// NOTE: The following is a cut-down version of glm::decompose
// (No Shear, no Perspective, slightly optimized / cleaned up)
......@@ -82,10 +47,10 @@ public:
m[3][3] = 1.f;
// Extract translation
position = glm::vec3(m[3]);
m[3] = glm::vec4(0, 0, 0, m[3].w);
position = tg::pos3(m[3]);
m[3] = tg::vec4(0, 0, 0, m[3].w);
glm::vec3 Row[3], Pdum3;
tg::vec3 Row[3], Pdum3;
// Extract Scale
for (auto i = 0; i < 3; ++i)
......@@ -93,22 +58,22 @@ public:
Row[i][j] = m[i][j];
// Compute X scale factor and normalize first row.
scale.x = length(Row[0]);
scale = length(Row[0]);
Row[0] = glm::normalize(Row[0]);
Row[1] += Row[0] * -glm::dot(Row[0], Row[1]);
Row[0] = normalize(Row[0]);
Row[1] += Row[0] * -dot(Row[0], Row[1]);
// Now, compute Y scale and normalize 2nd row.
scale.y = length(Row[1]);
Row[1] = glm::normalize(Row[1]);
// scale.y = length(Row[1]);
Row[1] = normalize(Row[1]);
// Compute XZ and YZ shears, orthogonalize 3rd row.
Row[2] += Row[0] * -glm::dot(Row[0], Row[2]);
Row[2] += Row[1] * -glm::dot(Row[1], Row[2]);
Row[2] += Row[0] * -dot(Row[0], Row[2]);
Row[2] += Row[1] * -dot(Row[1], Row[2]);
// Next, get Z scale and normalize 3rd row.
scale.z = length(Row[2]);
Row[2] = glm::normalize(Row[2]);
// scale.z = length(Row[2]);
Row[2] = normalize(Row[2]);
// At this point, the matrix (in rows[]) is orthonormal.
// Check for a coordinate system flip. If the determinant
......@@ -126,7 +91,7 @@ public:
float root, trace = Row[0].x + Row[1].y + Row[2].z;
if (trace > 0.f)
{
root = glm::sqrt(trace + 1.f);
root = tg::sqrt(trace + 1.f);
rotation.w = .5f * root;
root = .5f / root;
rotation.x = root * (Row[1].z - Row[2].y);
......@@ -144,7 +109,7 @@ public:
j = nextIndex[i];
k = nextIndex[j];
root = glm::sqrt(Row[i][i] - Row[j][j] - Row[k][k] + 1.f);
root = tg::sqrt(Row[i][i] - Row[j][j] - Row[k][k] + 1.f);
rotation[i] = .5f * root;
root = .5f / root;
......@@ -159,17 +124,17 @@ public:
/// Combine two Transforms
transform& operator*=(transform const& rhs)
{
position += (rotation * rhs.position) * scale;
position += (rotation * tg::vec3(rhs.position)) * scale;
rotation *= rhs.rotation;
scale *= rhs.scale;
return *this;
}
/// Moves the transform relative to the world
void moveGlobal(glm::vec3 const& direction) { position += direction; }
void moveGlobal(tg::vec3 const& direction) { position += direction; }
/// Moves the transform relative to its own orientation
void moveLocal(glm::vec3 const& direction) { moveGlobal(rotation * direction); }
void moveLocal(tg::vec3 const& direction) { moveGlobal(rotation * direction); }
void moveForward(float distance) { moveLocal(Forward() * distance); }
void moveRight(float distance) { moveLocal(Right() * distance); }
void moveUp(float distance) { moveLocal(Up() * distance); }
......@@ -177,53 +142,42 @@ public:
void moveLeft(float distance) { moveRight(-distance); }
void moveDown(float distance) { moveUp(-distance); }
void rotate(glm::quat const& rot) { rotation *= rot; }
void rotate(glm::vec3 const& rot) { rotation *= glm::quat(rot); }
void applyScale(glm::vec3 const& scal) { scale *= scal; }
void rotate(tg::quat const& rot) { rotation *= rot; }
void applyScale(float scal) { scale *= scal; }
void lerpToPosition(glm::vec3 const& pos, float amount) { position = glm::lerp(position, pos, amount); }
void lerpToRotation(glm::quat const& rot, float amount) { rotation = glm::slerp(rotation, rot, amount); }
void lerpToScale(glm::vec3 const& scal, float amount) { scale = glm::lerp(scale, scal, amount); }
void lerpToPosition(tg::pos3 const& pos, float amount) { position = tg::lerp(position, pos, amount); }
void lerpToRotation(tg::quat const& rot, float amount) { rotation = tg::slerp(rotation, rot, amount); }
void lerpToScale(float scal, float amount) { scale = tg::lerp(scale, scal, amount); }
void lerpTo(transform const& target, float amount)
{
position = glm::lerp(position, target.position, amount);
rotation = glm::slerp(rotation, target.rotation, amount);
scale = glm::lerp(scale, target.scale, amount);
position = tg::lerp(position, target.position, amount);
rotation = tg::slerp(rotation, target.rotation, amount);
scale = tg::lerp(scale, target.scale, amount);
}
/// -- Getters and Setters --
glm::mat4 getModelMatrix() const
{
return glm::translate(glm::mat4(1), position) * glm::toMat4(rotation) * glm::scale(glm::mat4(1), scale);
}
tg::mat4 getModelMatrix() const { return tg::translation(position) * to_mat4(rotation) * tg::scaling<3>(scale); }
glm::mat4 getModelMatrixNoRotation() const
{
return glm::translate(glm::mat4(1), position) * glm::scale(glm::mat4(1), scale);
}
/// Returns a local, relative position based on an offset
/// Takes rotation into account
glm::vec3 getRelativePosition(glm::vec3 const& offset) const { return position + (rotation * offset); }
tg::mat4 getModelMatrixNoRotation() const { return tg::translation(position) * tg::scaling<3>(scale); }
/// -- Miscellaneous --
glm::vec3 getForwardVector() const
tg::vec3 getForwardVector() const
{
auto const rotMatrix = glm::toMat3(rotation);
return glm::vec3(-rotMatrix[0][2], -rotMatrix[1][2], -rotMatrix[2][2]);
auto const rotMatrix = to_mat3(rotation);
return tg::vec3(-rotMatrix[0][2], -rotMatrix[1][2], -rotMatrix[2][2]);
}
glm::vec3 getRightVector() const
tg::vec3 getRightVector() const
{
auto const rotMatrix = glm::toMat3(rotation);
return glm::vec3(rotMatrix[0][0], rotMatrix[1][0], rotMatrix[2][0]);
auto const rotMatrix = to_mat3(rotation);
return tg::vec3(rotMatrix[0][0], rotMatrix[1][0], rotMatrix[2][0]);
}
glm::vec3 getUpVector() const
tg::vec3 getUpVector() const
{
auto const rotMatrix = glm::toMat3(rotation);
return glm::vec3(rotMatrix[0][1], rotMatrix[1][1], rotMatrix[2][1]);
auto const rotMatrix = to_mat3(rotation);
return tg::vec3(rotMatrix[0][1], rotMatrix[1][1], rotMatrix[2][1]);
}
public:
......@@ -240,17 +194,8 @@ public:
static float halftimeLerpAlpha(float halftime, float dt) { return 1 - std::pow(.5f, dt / halftime); }
};
inline std::string to_string(transform const& t)
{
std::stringstream ss;
ss << "[" << glm::to_string(t.position) << ", " << glm::to_string(t.rotation) << ", " << glm::to_string(t.scale) << "]";
return ss.str();
}
std::string to_string(transform const& t);
inline std::ostream& operator<<(std::ostream& stream, transform const& t)
{
stream << to_string(t);
return stream;
}
std::ostream& operator<<(std::ostream& stream, transform const& t);
}
......@@ -4,7 +4,7 @@
#include <limits>
#include <glm/glm.hpp>
#include <typed-geometry/functions/minmax.hh>
#include "Program.hh"
#include "Texture.hh"
......@@ -248,15 +248,15 @@ bool BoundFramebuffer::isCurrent() const