From: Daniel Karbach Date: Thu, 3 Nov 2016 16:22:07 +0000 (+0100) Subject: glm backwards compatibility X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=dcd54cacda98c2c0f7cf0c7a9131fb858d8ee10a;p=blank.git glm backwards compatibility --- diff --git a/src/ai/AIController.hpp b/src/ai/AIController.hpp index cfd49d9..6d40ded 100644 --- a/src/ai/AIController.hpp +++ b/src/ai/AIController.hpp @@ -3,10 +3,9 @@ #include "../app/IntervalTimer.hpp" #include "../geometry/primitive.hpp" +#include "../graphics/glm.hpp" #include "../world/EntityController.hpp" -#include - namespace blank { diff --git a/src/ai/Spawner.cpp b/src/ai/Spawner.cpp index 1f9573b..2c5a94c 100644 --- a/src/ai/Spawner.cpp +++ b/src/ai/Spawner.cpp @@ -70,7 +70,7 @@ void Spawner::CheckDespawn() noexcept { bool safe = false; for (const Player &ref : refs) { glm::vec3 diff(ref.GetEntity().AbsoluteDifference(e)); - if (dot(diff, diff) < despawn_range) { + if (glm::length2(diff) < despawn_range) { safe = true; break; } diff --git a/src/ai/Spawner.hpp b/src/ai/Spawner.hpp index 72d2ac1..daa5f78 100644 --- a/src/ai/Spawner.hpp +++ b/src/ai/Spawner.hpp @@ -2,9 +2,9 @@ #define BLANK_AI_SPAWNER_HPP_ #include "../app/IntervalTimer.hpp" +#include "../graphics/glm.hpp" #include -#include namespace blank { diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index db4ae41..ef0fc23 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -6,6 +6,7 @@ #include "../geometry/distance.hpp" #include "../geometry/rotation.hpp" +#include "../graphics/glm.hpp" #include "../rand/GaloisLFSR.hpp" #include "../world/Entity.hpp" #include "../world/World.hpp" @@ -13,7 +14,6 @@ #include #include -#include namespace blank { @@ -58,7 +58,7 @@ void AIController::Update(Entity &e, float dt) { // orient head towards heading glm::vec3 heading(e.Heading()); // only half pitch, so we don't crane our neck - float tgt_pitch = std::atan(heading.y / length(glm::vec2(heading.x, heading.z))) * 0.5f; + float tgt_pitch = std::atan(heading.y / glm::length(glm::vec2(heading.x, heading.z))) * 0.5f; // always look straight ahead // maybe look at the pursuit target if there is one float tgt_yaw = 0.0f; @@ -77,11 +77,11 @@ Player *AIController::ClosestVisiblePlayer(const Entity &e) noexcept { // distance test const glm::vec3 diff(pe.AbsoluteDifference(e)); - float dist = length(diff); + float dist = glm::length(diff); if (dist > distance) continue; // FOV test, 45° in each direction - if (dot(diff / dist, aim.dir) < sight_angle) { + if (glm::dot(diff / dist, aim.dir) < sight_angle) { continue; } @@ -102,8 +102,8 @@ bool AIController::LineOfSight(const Entity &from, const Entity &to) const noexc const glm::ivec3 &reference(from.ChunkCoords()); Ray aim(from.Aim(reference)); const glm::vec3 diff(to.AbsoluteDifference(from)); - float dist = length(diff); - if (dist > sight_dist || dot(diff / dist, aim.dir) < sight_angle) { + float dist = glm::length(diff); + if (dist > sight_dist || glm::dot(diff / dist, aim.dir) < sight_angle) { return false; } WorldCollision col; @@ -166,7 +166,7 @@ void ChaseState::Update(AIController &ctrl, Entity &e, float dt) const { return; } // halt if we're close enough, flee if we're too close - float dist_sq = length2(e.AbsoluteDifference(steering.GetTargetEntity())); + float dist_sq = glm::length2(e.AbsoluteDifference(steering.GetTargetEntity())); if (dist_sq < 8.0f) { ctrl.SetState(flee, e); } else if (dist_sq < 25.0f) { diff --git a/src/audio/Audio.hpp b/src/audio/Audio.hpp index 800e247..dfa848f 100644 --- a/src/audio/Audio.hpp +++ b/src/audio/Audio.hpp @@ -2,9 +2,9 @@ #define BLANK_AUDIO_AUDIO_HPP_ #include "../app/IntervalTimer.hpp" +#include "../graphics/glm.hpp" #include -#include namespace blank { diff --git a/src/client/ChunkTransmission.hpp b/src/client/ChunkTransmission.hpp index 7e801ee..1d43649 100644 --- a/src/client/ChunkTransmission.hpp +++ b/src/client/ChunkTransmission.hpp @@ -1,10 +1,10 @@ #ifndef BLANK_CLIENT_CHUNKTRANSMISSION_HPP_ #define BLANK_CLIENT_CHUNKTRANSMISSION_HPP_ +#include "../graphics/glm.hpp" #include "../world/Chunk.hpp" #include -#include namespace blank { diff --git a/src/client/net.cpp b/src/client/net.cpp index bb28f15..5510872 100644 --- a/src/client/net.cpp +++ b/src/client/net.cpp @@ -432,7 +432,7 @@ void NetworkedInput::MergePlayerCorrection(uint16_t seq, const EntityState &corr } glm::vec3 displacement(replay.GetState().Diff(player_state)); - const float disp_squared = dot(displacement, displacement); + const float disp_squared = glm::dot(displacement, displacement); if (disp_squared < 16.0f * numeric_limits::epsilon()) { SetMovement(restore_movement); diff --git a/src/geometry/Location.hpp b/src/geometry/Location.hpp index 43d94dc..d475b3b 100644 --- a/src/geometry/Location.hpp +++ b/src/geometry/Location.hpp @@ -1,7 +1,7 @@ #ifndef BLANK_GEOMETRY_LOCATION_HPP_ #define BLANK_GEOMETRY_LOCATION_HPP_ -#include +#include "../graphics/glm.hpp" namespace blank { @@ -11,7 +11,7 @@ struct Location { using Coarse = glm::ivec3; using CoarseScalar = int; - using Fine = glm::tvec3; + using Fine = TVEC3; using FineScalar = T; using Self = Location; diff --git a/src/geometry/distance.hpp b/src/geometry/distance.hpp index ef2f8a2..9156808 100644 --- a/src/geometry/distance.hpp +++ b/src/geometry/distance.hpp @@ -1,9 +1,10 @@ #ifndef BLANK_GEOMETRY_DISTANCE_HPP_ #define BLANK_GEOMETRY_DISTANCE_HPP_ +#include "../graphics/glm.hpp" + #include #include -#include #include #include @@ -12,26 +13,26 @@ namespace blank { template inline bool iszero(const T &v) noexcept { - return length2(v) < std::numeric_limits::epsilon(); + return glm::length2(v) < std::numeric_limits::epsilon(); } template inline void limit(Vec &v, float max) noexcept { - float len2 = length2(v); + float len2 = glm::length2(v); float max2 = max * max; if (len2 > max2) { - v = normalize(v) * max; + v = glm::normalize(v) * max; } } -template -T manhattan_distance(const glm::tvec3 &a, const glm::tvec3 &b) noexcept { - return compAdd(abs(a - b)); +template +T manhattan_distance(const TVEC3 &a, const TVEC3 &b) noexcept { + return glm::compAdd(glm::abs(a - b)); } -template -T manhattan_radius(const glm::tvec3 &v) noexcept { - return compMax(abs(v)); +template +T manhattan_radius(const TVEC3 &v) noexcept { + return glm::compMax(glm::abs(v)); } } diff --git a/src/geometry/geometry.cpp b/src/geometry/geometry.cpp index 668e729..5db29c8 100644 --- a/src/geometry/geometry.cpp +++ b/src/geometry/geometry.cpp @@ -14,7 +14,7 @@ namespace blank { glm::mat3 find_rotation(const glm::vec3 &a, const glm::vec3 &b) noexcept { - glm::vec3 v(cross(a, b)); + glm::vec3 v(glm::cross(a, b)); if (iszero(v)) { // a and b are parallel if (iszero(a - b)) { @@ -30,15 +30,15 @@ glm::mat3 find_rotation(const glm::vec3 &a, const glm::vec3 &b) noexcept { } else { arb.y += 1.0f; } - glm::vec3 axis(normalize(cross(a, arb))); + glm::vec3 axis(glm::normalize(glm::cross(a, arb))); return glm::mat3(glm::rotate(PI, axis)); } } - float mv = length2(v); - float c = dot(a, b); + float mv = glm::length2(v); + float c = glm::dot(a, b); float f = (1 - c) / mv; - glm::mat3 vx(matrixCross3(v)); - return glm::mat3(1.0f) + vx + (pow2(vx) * f); + glm::mat3 vx(glm::matrixCross3(v)); + return glm::mat3(1.0f) + vx + (glm::pow2(vx) * f); } std::ostream &operator <<(std::ostream &out, const AABB &box) { @@ -106,7 +106,7 @@ bool Intersection( *dist = t_min; } if (normal) { - glm::vec3 min_all(min(t1, t2)); + glm::vec3 min_all(glm::min(t1, t2)); if (min_all.x > min_all.y) { if (min_all.x > min_all.z) { normal->x = t2.x < t1.x ? 1 : -1; @@ -159,15 +159,15 @@ bool Intersection( glm::vec3(b_m[0]), glm::vec3(b_m[1]), glm::vec3(b_m[2]), - normalize(cross(glm::vec3(a_m[0]), glm::vec3(b_m[0]))), - normalize(cross(glm::vec3(a_m[0]), glm::vec3(b_m[1]))), - normalize(cross(glm::vec3(a_m[0]), glm::vec3(b_m[2]))), - normalize(cross(glm::vec3(a_m[1]), glm::vec3(b_m[0]))), - normalize(cross(glm::vec3(a_m[1]), glm::vec3(b_m[1]))), - normalize(cross(glm::vec3(a_m[1]), glm::vec3(b_m[2]))), - normalize(cross(glm::vec3(a_m[2]), glm::vec3(b_m[0]))), - normalize(cross(glm::vec3(a_m[2]), glm::vec3(b_m[1]))), - normalize(cross(glm::vec3(a_m[2]), glm::vec3(b_m[2]))), + glm::normalize(glm::cross(glm::vec3(a_m[0]), glm::vec3(b_m[0]))), + glm::normalize(glm::cross(glm::vec3(a_m[0]), glm::vec3(b_m[1]))), + glm::normalize(glm::cross(glm::vec3(a_m[0]), glm::vec3(b_m[2]))), + glm::normalize(glm::cross(glm::vec3(a_m[1]), glm::vec3(b_m[0]))), + glm::normalize(glm::cross(glm::vec3(a_m[1]), glm::vec3(b_m[1]))), + glm::normalize(glm::cross(glm::vec3(a_m[1]), glm::vec3(b_m[2]))), + glm::normalize(glm::cross(glm::vec3(a_m[2]), glm::vec3(b_m[0]))), + glm::normalize(glm::cross(glm::vec3(a_m[2]), glm::vec3(b_m[1]))), + glm::normalize(glm::cross(glm::vec3(a_m[2]), glm::vec3(b_m[2]))), }; depth = std::numeric_limits::infinity(); @@ -175,7 +175,7 @@ bool Intersection( int cur_axis = 0; for (const glm::vec3 &axis : axes) { - if (any(isnan(axis))) { + if (glm::any(glm::isnan(axis))) { // can result from the cross products if A and B have parallel axes ++cur_axis; continue; @@ -270,7 +270,7 @@ bool CullTest(const AABB &box, const Frustum &frustum) noexcept { ((plane.normal.y > 0.0f) ? box.max.y : box.min.y), ((plane.normal.z > 0.0f) ? box.max.z : box.min.z) ); - const float dp = dot(plane.normal, np); + const float dp = glm::dot(plane.normal, np); // cull if nearest point is on the "outside" side of the plane if (dp < -plane.dist) return true; } diff --git a/src/geometry/primitive.hpp b/src/geometry/primitive.hpp index b9f2187..76064c1 100644 --- a/src/geometry/primitive.hpp +++ b/src/geometry/primitive.hpp @@ -1,9 +1,10 @@ #ifndef BLANK_GEOMETRY_PRIMITIVE_HPP_ #define BLANK_GEOMETRY_PRIMITIVE_HPP_ +#include "../graphics/glm.hpp" + #include #include -#include #include @@ -25,8 +26,8 @@ struct AABB { /// return distance between origin and farthest vertex float OriginRadius() const noexcept { - glm::vec3 high(glm::max(abs(min), abs(max))); - return length(high); + glm::vec3 high(glm::max(glm::abs(min), glm::abs(max))); + return glm::length(high); } }; @@ -51,10 +52,10 @@ struct Ray { // for derivation, see http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html // x1 = orig // x2-x1 = dir, which means |x2-x1| is 1.0 - return length(cross(dir, orig - point)); + return glm::length(glm::cross(dir, orig - point)); } float DistanceSquared(const glm::vec3 &point) const noexcept { - return length2(cross(dir, orig - point)); + return glm::length2(glm::cross(dir, orig - point)); } }; @@ -105,7 +106,7 @@ struct Plane { : normal(abcd), dist(abcd.w) { } void Normalize() noexcept { - const float l = length(normal); + const float l = glm::length(normal); normal /= l; dist /= l; } diff --git a/src/geometry/rotation.hpp b/src/geometry/rotation.hpp index ac208dc..3365a32 100644 --- a/src/geometry/rotation.hpp +++ b/src/geometry/rotation.hpp @@ -1,7 +1,7 @@ #ifndef BLANK_GEOMETRY_ROTATION_HPP_ #define BLANK_GEOMETRY_ROTATION_HPP_ -#include +#include "../graphics/glm.hpp" namespace blank { diff --git a/src/graphics/BlendedSprite.hpp b/src/graphics/BlendedSprite.hpp index a15d8a1..b103a4d 100644 --- a/src/graphics/BlendedSprite.hpp +++ b/src/graphics/BlendedSprite.hpp @@ -1,10 +1,10 @@ #ifndef BLANK_GRAPHICS_BLENDEDSPRITE_HPP_ #define BLANK_GRAPHICS_BLENDEDSPRITE_HPP_ +#include "glm.hpp" #include "Program.hpp" #include -#include namespace blank { diff --git a/src/graphics/BlockLighting.hpp b/src/graphics/BlockLighting.hpp index 9b3e8af..d0d4ea4 100644 --- a/src/graphics/BlockLighting.hpp +++ b/src/graphics/BlockLighting.hpp @@ -1,10 +1,10 @@ #ifndef BLANK_GRAPHICS_BLOCKLIGHTING_HPP_ #define BLANK_GRAPHICS_BLOCKLIGHTING_HPP_ +#include "glm.hpp" #include "Program.hpp" #include -#include namespace blank { diff --git a/src/graphics/BlockMesh.hpp b/src/graphics/BlockMesh.hpp index 5342992..ff41df9 100644 --- a/src/graphics/BlockMesh.hpp +++ b/src/graphics/BlockMesh.hpp @@ -1,11 +1,11 @@ #ifndef BLANK_GRAPHICS_BLOCKMESH_HPP_ #define BLANK_GRAPHICS_BLOCKMESH_HPP_ +#include "glm.hpp" #include "VertexArray.hpp" #include #include -#include namespace blank { @@ -15,7 +15,7 @@ class BlockMesh { public: using Position = glm::vec3; using TexCoord = glm::vec3; - using ColorMod = glm::tvec3; + using ColorMod = TVEC3; using Light = float; using Index = unsigned int; diff --git a/src/graphics/Camera.hpp b/src/graphics/Camera.hpp index 95175de..d1fa508 100644 --- a/src/graphics/Camera.hpp +++ b/src/graphics/Camera.hpp @@ -1,7 +1,7 @@ #ifndef BLANK_GRAPHICS_CAMERA_HPP_ #define BLANK_GRAPHICS_CAMERA_HPP_ -#include +#include "glm.hpp" namespace blank { diff --git a/src/graphics/Canvas.hpp b/src/graphics/Canvas.hpp index a9ce7f5..b1d8282 100644 --- a/src/graphics/Canvas.hpp +++ b/src/graphics/Canvas.hpp @@ -1,7 +1,7 @@ #ifndef BLANK_GRAPHICS_CANVAS_HPP_ #define BLANK_GRAPHICS_CANVAS_HPP_ -#include +#include "glm.hpp" namespace blank { diff --git a/src/graphics/DirectionalLighting.hpp b/src/graphics/DirectionalLighting.hpp index 4255401..dd76f5e 100644 --- a/src/graphics/DirectionalLighting.hpp +++ b/src/graphics/DirectionalLighting.hpp @@ -1,10 +1,10 @@ #ifndef BLANK_GRAPHICS_DIRECTIONALLIGHTING_HPP_ #define BLANK_GRAPHICS_DIRECTIONALLIGHTING_HPP_ +#include "glm.hpp" #include "Program.hpp" #include -#include namespace blank { diff --git a/src/graphics/EntityMesh.hpp b/src/graphics/EntityMesh.hpp index 58b29e5..cdb7ed2 100644 --- a/src/graphics/EntityMesh.hpp +++ b/src/graphics/EntityMesh.hpp @@ -1,11 +1,11 @@ #ifndef BLANK_GRAPHICS_ENTITYMESH_HPP_ #define BLANK_GRAPHICS_ENTITYMESH_HPP_ +#include "glm.hpp" #include "VertexArray.hpp" #include #include -#include namespace blank { @@ -15,7 +15,7 @@ class EntityMesh { public: using Position = glm::vec3; using TexCoord = glm::vec3; - using ColorMod = glm::tvec3; + using ColorMod = TVEC3; using Normal = glm::vec3; using Index = unsigned int; diff --git a/src/graphics/Font.hpp b/src/graphics/Font.hpp index b940059..d52d43f 100644 --- a/src/graphics/Font.hpp +++ b/src/graphics/Font.hpp @@ -1,8 +1,9 @@ #ifndef BLANK_GRAPHICS_FONT_HPP_ #define BLANK_GRAPHICS_FONT_HPP_ +#include "glm.hpp" + #include -#include namespace blank { diff --git a/src/graphics/PlainColor.hpp b/src/graphics/PlainColor.hpp index cfaaebe..6cdf110 100644 --- a/src/graphics/PlainColor.hpp +++ b/src/graphics/PlainColor.hpp @@ -1,10 +1,10 @@ #ifndef BLANK_GRAPHICS_PLAINCOLOR_HPP_ #define BLANK_GRAPHICS_PLAINCOLOR_HPP_ +#include "glm.hpp" #include "Program.hpp" #include -#include namespace blank { diff --git a/src/graphics/PrimitiveMesh.hpp b/src/graphics/PrimitiveMesh.hpp index 577321a..247cc6a 100644 --- a/src/graphics/PrimitiveMesh.hpp +++ b/src/graphics/PrimitiveMesh.hpp @@ -1,11 +1,11 @@ #ifndef BLANK_GRAPHICS_PRIMITIVEMESH_HPP_ #define BLANK_GRAPHICS_PRIMITIVEMESH_HPP_ +#include "glm.hpp" #include "VertexArray.hpp" #include #include -#include namespace blank { @@ -16,7 +16,7 @@ class PrimitiveMesh { public: using Position = glm::vec3; - using Color = glm::tvec4; + using Color = TVEC4; using Index = unsigned short; using Positions = std::vector; diff --git a/src/graphics/Program.hpp b/src/graphics/Program.hpp index ff01f9d..7f65901 100644 --- a/src/graphics/Program.hpp +++ b/src/graphics/Program.hpp @@ -1,10 +1,11 @@ #ifndef BLANK_GRAPHICS_PROGRAM_HPP_ #define BLANK_GRAPHICS_PROGRAM_HPP_ +#include "glm.hpp" + #include #include #include -#include namespace blank { diff --git a/src/graphics/SkyBoxMesh.hpp b/src/graphics/SkyBoxMesh.hpp index 2378327..2962f07 100644 --- a/src/graphics/SkyBoxMesh.hpp +++ b/src/graphics/SkyBoxMesh.hpp @@ -1,10 +1,10 @@ #ifndef BLANK_GRAPHICS_SKYBOXMESH_HPP_ #define BLANK_GRAPHICS_SKYBOXMESH_HPP_ +#include "glm.hpp" #include "VertexArray.hpp" #include -#include namespace blank { diff --git a/src/graphics/SpriteMesh.hpp b/src/graphics/SpriteMesh.hpp index 0c6c9a1..019af86 100644 --- a/src/graphics/SpriteMesh.hpp +++ b/src/graphics/SpriteMesh.hpp @@ -1,11 +1,11 @@ #ifndef BLANK_GRPAHICS_SPRITEMESH_HPP_ #define BLANK_GRPAHICS_SPRITEMESH_HPP_ +#include "glm.hpp" #include "VertexArray.hpp" #include #include -#include namespace blank { diff --git a/src/graphics/Viewport.hpp b/src/graphics/Viewport.hpp index de62c48..69c66a7 100644 --- a/src/graphics/Viewport.hpp +++ b/src/graphics/Viewport.hpp @@ -7,11 +7,10 @@ #include "Camera.hpp" #include "Canvas.hpp" #include "DirectionalLighting.hpp" +#include "glm.hpp" #include "PlainColor.hpp" #include "SkyBoxShader.hpp" -#include - namespace blank { diff --git a/src/graphics/align.hpp b/src/graphics/align.hpp index 6563e29..eba70f7 100644 --- a/src/graphics/align.hpp +++ b/src/graphics/align.hpp @@ -1,7 +1,7 @@ #ifndef BLANK_GRAPHICS_ALIGN_HPP_ #define BLANK_GRAPHICS_ALIGN_HPP_ -#include +#include "glm.hpp" namespace blank { diff --git a/src/graphics/gl_traits.hpp b/src/graphics/gl_traits.hpp index 2a599b3..89d2dea 100644 --- a/src/graphics/gl_traits.hpp +++ b/src/graphics/gl_traits.hpp @@ -1,8 +1,9 @@ #ifndef BLANK_GRAPHICS_GL_TRAITS_HPP_ #define BLANK_GRAPHICS_GL_TRAITS_HPP_ +#include "glm.hpp" + #include -#include namespace blank { @@ -72,47 +73,47 @@ template<> struct gl_traits { template<> template -struct gl_traits> { +struct gl_traits> { static constexpr GLint size = 1; static constexpr GLenum type = gl_traits::type; }; template -constexpr GLint gl_traits>::size; +constexpr GLint gl_traits>::size; template -constexpr GLenum gl_traits>::type; +constexpr GLenum gl_traits>::type; template<> template -struct gl_traits> { +struct gl_traits> { static constexpr GLint size = 2; static constexpr GLenum type = gl_traits::type; }; template -constexpr GLint gl_traits>::size; +constexpr GLint gl_traits>::size; template -constexpr GLenum gl_traits>::type; +constexpr GLenum gl_traits>::type; template<> template -struct gl_traits> { +struct gl_traits> { static constexpr GLint size = 3; static constexpr GLenum type = gl_traits::type; }; template -constexpr GLint gl_traits>::size; +constexpr GLint gl_traits>::size; template -constexpr GLenum gl_traits>::type; +constexpr GLenum gl_traits>::type; template<> template -struct gl_traits> { +struct gl_traits> { static constexpr GLint size = 4; static constexpr GLenum type = gl_traits::type; }; template -constexpr GLint gl_traits>::size; +constexpr GLint gl_traits>::size; template -constexpr GLenum gl_traits>::type; +constexpr GLenum gl_traits>::type; } diff --git a/src/graphics/glm.hpp b/src/graphics/glm.hpp new file mode 100644 index 0000000..db886e0 --- /dev/null +++ b/src/graphics/glm.hpp @@ -0,0 +1,24 @@ +#ifndef BLANK_GRAPHICS_GLM_HPP_ +#define BLANK_GRAPHICS_GLM_HPP_ + +#ifndef GLM_FORCE_RADIANS +# define GLM_FORCE_RADIANS 1 +#endif + +#include + +// GLM moved tvec[1234] from glm::detail to glm in 0.9.6 + +#if GLM_VERSION < 96 +# define TVEC1 glm::detail::tvec1 +# define TVEC2 glm::detail::tvec2 +# define TVEC3 glm::detail::tvec3 +# define TVEC4 glm::detail::tvec4 +#else +# define TVEC1 glm::tvec1 +# define TVEC2 glm::tvec2 +# define TVEC3 glm::tvec3 +# define TVEC4 glm::tvec4 +#endif + +#endif diff --git a/src/io/TokenStreamReader.hpp b/src/io/TokenStreamReader.hpp index 9436aba..c702703 100644 --- a/src/io/TokenStreamReader.hpp +++ b/src/io/TokenStreamReader.hpp @@ -3,10 +3,10 @@ #include "Token.hpp" #include "Tokenizer.hpp" +#include "../graphics/glm.hpp" #include #include -#include namespace blank { diff --git a/src/model/CollisionBounds.hpp b/src/model/CollisionBounds.hpp index e43b0d8..a612286 100644 --- a/src/model/CollisionBounds.hpp +++ b/src/model/CollisionBounds.hpp @@ -2,8 +2,7 @@ #define BLANK_MODEL_COLLISIONBOUNDS_HPP_ #include "../graphics/PrimitiveMesh.hpp" - -#include +#include "../graphics/glm.hpp" namespace blank { diff --git a/src/model/Instance.hpp b/src/model/Instance.hpp index 80c8f71..60e1950 100644 --- a/src/model/Instance.hpp +++ b/src/model/Instance.hpp @@ -2,9 +2,9 @@ #define BLANK_MODEL_INSTANCE_HPP_ #include "Part.hpp" +#include "../graphics/glm.hpp" #include -#include #include diff --git a/src/model/Model.hpp b/src/model/Model.hpp index 145a6d9..54b5256 100644 --- a/src/model/Model.hpp +++ b/src/model/Model.hpp @@ -2,11 +2,11 @@ #define BLANK_MODEL_MODEL_HPP_ #include "Part.hpp" +#include "../graphics/glm.hpp" #include #include #include -#include #include diff --git a/src/model/Part.hpp b/src/model/Part.hpp index 3a17f20..6499bb7 100644 --- a/src/model/Part.hpp +++ b/src/model/Part.hpp @@ -1,18 +1,19 @@ #ifndef BLAMK_MODEL_PART_HPP_ #define BLAMK_MODEL_PART_HPP_ +#include "../graphics/EntityMesh.hpp" +#include "../graphics/glm.hpp" + #include #include #include #include -#include #include namespace blank { class DirectionalLighting; -class EntityMesh; class Instance; class Model; class ResourceIndex; @@ -56,8 +57,8 @@ private: std::vector tex_map; mutable std::unique_ptr mesh; State initial; - glm::tvec3 hsl_mod; - glm::tvec3 rgb_mod; + EntityMesh::ColorMod hsl_mod; + EntityMesh::ColorMod rgb_mod; std::uint16_t id; }; diff --git a/src/model/Shape.hpp b/src/model/Shape.hpp index fe58d01..80dc4a3 100644 --- a/src/model/Shape.hpp +++ b/src/model/Shape.hpp @@ -5,11 +5,11 @@ #include "../geometry/primitive.hpp" #include "../graphics/BlockMesh.hpp" #include "../graphics/EntityMesh.hpp" +#include "../graphics/glm.hpp" #include "../world/Block.hpp" #include #include -#include namespace blank { diff --git a/src/model/bounds.hpp b/src/model/bounds.hpp index df5f77f..7177290 100644 --- a/src/model/bounds.hpp +++ b/src/model/bounds.hpp @@ -3,9 +3,9 @@ #include "CollisionBounds.hpp" #include "../geometry/primitive.hpp" +#include "../graphics/glm.hpp" #include -#include namespace blank { diff --git a/src/model/model.cpp b/src/model/model.cpp index ed44313..9a5801b 100644 --- a/src/model/model.cpp +++ b/src/model/model.cpp @@ -137,10 +137,10 @@ void Part::Read(TokenStreamReader &in, ResourceIndex &tex_index, const ShapeRegi in.ReadQuat(initial.orientation); } else if (name == "hsl_mod") { in.ReadVec(color_conv); - hsl_mod = glm::tvec3(color_conv * 255.0f); + hsl_mod = EntityMesh::ColorMod(color_conv * 255.0f); } else if (name == "rgb_mod") { in.ReadVec(color_conv); - rgb_mod = glm::tvec3(color_conv * 255.0f); + rgb_mod = EntityMesh::ColorMod(color_conv * 255.0f); } else if (name == "textures") { in.Skip(Token::BRACKET_OPEN); while (in.HasMore() && in.Peek().type != Token::BRACKET_CLOSE) { @@ -193,7 +193,7 @@ void Part::Index(std::vector &index) noexcept { } glm::mat4 Part::LocalTransform(const Instance &inst) const noexcept { - glm::mat4 transform(toMat4(initial.orientation * inst.state[id].orientation)); + glm::mat4 transform(glm::toMat4(initial.orientation * inst.state[id].orientation)); transform[3] = glm::vec4(initial.position + inst.state[id].position, 1.0f); return transform; } diff --git a/src/net/Packet.hpp b/src/net/Packet.hpp index 7dede0d..d7da977 100644 --- a/src/net/Packet.hpp +++ b/src/net/Packet.hpp @@ -1,11 +1,12 @@ #ifndef BLANK_NET_PACKET_HPP_ #define BLANK_NET_PACKET_HPP_ +#include "../graphics/glm.hpp" + #include #include #include #include -#include namespace blank { diff --git a/src/net/net.cpp b/src/net/net.cpp index 7de901e..4f7fc66 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -493,7 +493,7 @@ void Packet::Payload::Read(glm::quat &val, size_t off) const noexcept { } } // omitted component squared is 1 - length squared of others - val[largest_index] = sqrt(1.0f - dot(val, val)); + val[largest_index] = sqrt(1.0f - glm::length2(val)); // and already normalized } diff --git a/src/rand/OctaveNoise.hpp b/src/rand/OctaveNoise.hpp index 7d5832f..4c8b78e 100644 --- a/src/rand/OctaveNoise.hpp +++ b/src/rand/OctaveNoise.hpp @@ -1,7 +1,7 @@ #ifndef BLANK_RAND_OCTAVENOISE_HPP_ #define BLANK_RAND_OCTAVENOISE_HPP_ -#include +#include "../graphics/glm.hpp" namespace blank { diff --git a/src/rand/SimplexNoise.hpp b/src/rand/SimplexNoise.hpp index 6260426..dbe3d59 100644 --- a/src/rand/SimplexNoise.hpp +++ b/src/rand/SimplexNoise.hpp @@ -1,8 +1,9 @@ #ifndef BLANK_RAND_SIMPLEXNOISE_HPP_ #define BLANK_RAND_SIMPLEXNOISE_HPP_ +#include "../graphics/glm.hpp" + #include -#include namespace blank { diff --git a/src/rand/WorleyNoise.hpp b/src/rand/WorleyNoise.hpp index 20631c4..24ef724 100644 --- a/src/rand/WorleyNoise.hpp +++ b/src/rand/WorleyNoise.hpp @@ -1,7 +1,7 @@ #ifndef BLANK_RAND_WORLEYNOISE_HPP_ #define BLANK_RAND_WORLEYNOISE_HPP_ -#include +#include "../graphics/glm.hpp" namespace blank { diff --git a/src/rand/noise.cpp b/src/rand/noise.cpp index b3a9bc8..bd6571b 100644 --- a/src/rand/noise.cpp +++ b/src/rand/noise.cpp @@ -3,6 +3,7 @@ #include "WorleyNoise.hpp" #include +#include namespace { @@ -122,28 +123,28 @@ float SimplexNoise::operator ()(const glm::vec3 &in) const noexcept { // I know 0.6 is wrong, but for some reason it looks better than 0.5 // 0 - float t = glm::clamp(0.6f - dot(offset[0], offset[0]), 0.0f, 1.0f); + float t = glm::clamp(0.6f - glm::length2(offset[0]), 0.0f, 1.0f); t *= t; int corner = Perm12(index[0] + Perm(index[1] + Perm(index[2]))); - n += t * t * dot(Grad(corner), offset[0]); + n += t * t * glm::dot(Grad(corner), offset[0]); // 1 - t = glm::clamp(0.6f - dot(offset[1], offset[1]), 0.0f, 1.0f); + t = glm::clamp(0.6f - glm::length2(offset[1]), 0.0f, 1.0f); t *= t; corner = Perm12(index[0] + second_int.x + Perm(index[1] + second_int.y + Perm(index[2] + second_int.z))); - n += t * t * dot(Grad(corner), offset[1]); + n += t * t * glm::dot(Grad(corner), offset[1]); // 2 - t = glm::clamp(0.6f - dot(offset[2], offset[2]), 0.0f, 1.0f); + t = glm::clamp(0.6f - glm::length2(offset[2]), 0.0f, 1.0f); t *= t; corner = Perm12(index[0] + third_int.x + Perm(index[1] + third_int.y + Perm(index[2] + third_int.z))); - n += t * t * dot(Grad(corner), offset[2]); + n += t * t * glm::dot(Grad(corner), offset[2]); // 3 - t = glm::clamp(0.6f - dot(offset[3], offset[3]), 0.0f, 1.0f); + t = glm::clamp(0.6f - glm::length2(offset[3]), 0.0f, 1.0f); t *= t; corner = Perm12(index[0] + 1 + Perm(index[1] + 1 + Perm(index[2] + 1))); - n += t * t * dot(Grad(corner), offset[3]); + n += t * t * glm::dot(Grad(corner), offset[3]); return 32.0f * n; } @@ -169,7 +170,7 @@ WorleyNoise::WorleyNoise(unsigned int seed) noexcept } float WorleyNoise::operator ()(const glm::vec3 &in) const noexcept { - glm::vec3 center = floor(in); + glm::vec3 center = glm::floor(in); float closest = 1.0f; // cannot be farther away than 1.0 @@ -192,8 +193,7 @@ float WorleyNoise::operator ()(const glm::vec3 &in) const noexcept { cube_rand = 159739 * cube_rand + 112139; point.z += float(cube_rand % 262144) / 262144.0f; - glm::vec3 diff(in - point); - float distance = sqrt(dot(diff, diff)); + float distance = glm::distance(in, point); if (distance < closest) { closest = distance; } diff --git a/src/server/net.cpp b/src/server/net.cpp index e8325da..e210fef 100644 --- a/src/server/net.cpp +++ b/src/server/net.cpp @@ -355,7 +355,7 @@ void ClientConnection::SendUpdates() { void ClientConnection::CheckPlayerFix() { // player_update_state's position holds the client's most recent prediction glm::vec3 diff = player_update_state.Diff(PlayerEntity().GetState()); - float dist_squared = dot(diff, diff); + float dist_squared = glm::length2(diff); // if client's prediction is off by more than 1cm, send // our (authoritative) state back so it can fix it diff --git a/src/shared/states.cpp b/src/shared/states.cpp index 1b90715..fc422bb 100644 --- a/src/shared/states.cpp +++ b/src/shared/states.cpp @@ -18,8 +18,8 @@ ChatState::ChatState(Environment &env, State &parent, Responder &responder) , input(env.assets.small_ui_font) { input.Position(glm::vec3(25.0f, -25.0f, -1.0f), Gravity::SOUTH_WEST, Gravity::SOUTH_WEST); input.Width(env.viewport.Width() - 50.0f); - input.Foreground(glm::vec4(1.0f)); - input.Background(glm::vec4(0.5f)); + input.Foreground(PrimitiveMesh::Color(255)); + input.Background(PrimitiveMesh::Color(127)); } void ChatState::Preset(const std::string &text) { diff --git a/src/ui/HUD.hpp b/src/ui/HUD.hpp index b842da3..cbe2876 100644 --- a/src/ui/HUD.hpp +++ b/src/ui/HUD.hpp @@ -4,10 +4,9 @@ #include "FixedText.hpp" #include "MessageBox.hpp" #include "../graphics/EntityMesh.hpp" +#include "../graphics/glm.hpp" #include "../graphics/PrimitiveMesh.hpp" -#include - namespace blank { diff --git a/src/ui/Interface.hpp b/src/ui/Interface.hpp index 9a6e927..bcc6c66 100644 --- a/src/ui/Interface.hpp +++ b/src/ui/Interface.hpp @@ -2,9 +2,9 @@ #define BLANK_UI_INTERFACE_HPP_ #include "../app/Config.hpp" +#include "../graphics/glm.hpp" #include -#include namespace blank { diff --git a/src/ui/MessageBox.hpp b/src/ui/MessageBox.hpp index b5a82c8..2cfdec9 100644 --- a/src/ui/MessageBox.hpp +++ b/src/ui/MessageBox.hpp @@ -3,11 +3,11 @@ #include "Text.hpp" #include "../graphics/align.hpp" +#include "../graphics/glm.hpp" #include "../graphics/PrimitiveMesh.hpp" #include #include -#include namespace blank { @@ -44,8 +44,8 @@ private: glm::vec3 adv; glm::vec2 size; - glm::vec4 bg; - glm::vec4 fg; + PrimitiveMesh::Color bg; + PrimitiveMesh::Color fg; PrimitiveMesh bg_mesh; diff --git a/src/ui/PlayerController.hpp b/src/ui/PlayerController.hpp index 48c3bdc..69a15e9 100644 --- a/src/ui/PlayerController.hpp +++ b/src/ui/PlayerController.hpp @@ -1,8 +1,7 @@ #ifndef BLANK_UI_PLAYERCONTROLLER_HPP_ #define BLANK_UI_PLAYERCONTROLLER_HPP_ -#include - +#include "../graphics/glm.hpp" #include "../world/EntityCollision.hpp" #include "../world/EntityController.hpp" #include "../world/WorldCollision.hpp" diff --git a/src/ui/Text.hpp b/src/ui/Text.hpp index c431873..591740a 100644 --- a/src/ui/Text.hpp +++ b/src/ui/Text.hpp @@ -2,11 +2,11 @@ #define BLANK_UI_TEXT_HPP_ #include "../graphics/align.hpp" +#include "../graphics/glm.hpp" #include "../graphics/Texture.hpp" #include "../graphics/SpriteMesh.hpp" #include -#include namespace blank { diff --git a/src/ui/TextInput.hpp b/src/ui/TextInput.hpp index 44999fa..66f2ded 100644 --- a/src/ui/TextInput.hpp +++ b/src/ui/TextInput.hpp @@ -39,8 +39,8 @@ public: void Position(const glm::vec3 &p, Gravity g, Gravity pv) noexcept; void Width(float) noexcept; - void Foreground(const glm::vec4 &col) noexcept { fg = col; dirty_cursor = true; } - void Background(const glm::vec4 &col) noexcept { bg = col; dirty_box = true; } + void Foreground(const PrimitiveMesh::Color &col) noexcept { fg = col; dirty_cursor = true; } + void Background(const PrimitiveMesh::Color &col) noexcept { bg = col; dirty_box = true; } void Handle(const SDL_TextInputEvent &); void Handle(const SDL_TextEditingEvent &); @@ -59,8 +59,8 @@ private: PrimitiveMesh bg_mesh; PrimitiveMesh cursor_mesh; - glm::vec4 bg; - glm::vec4 fg; + PrimitiveMesh::Color bg; + PrimitiveMesh::Color fg; glm::vec3 position; glm::vec2 size; diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 2d3b467..5ff408b 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -54,8 +54,8 @@ PlayerController::~PlayerController() { } void PlayerController::SetMovement(const glm::vec3 &m) noexcept { - if (dot(m, m) > 1.0f) { - move_dir = normalize(m); + if (glm::dot(m, m) > 1.0f) { + move_dir = glm::normalize(m); } else { move_dir = m; } @@ -108,8 +108,8 @@ void PlayerController::UpdatePlayer() noexcept { if (!iszero(move_dir)) { // scale input by max velocity, apply yaw, and transform to world space steering.SetTargetVelocity(glm::vec3( - glm::vec4(rotateY(move_dir * entity.MaxVelocity(), entity.Yaw()), 0.0f) - * transpose(entity.Transform()) + glm::vec4(glm::rotateY(move_dir * entity.MaxVelocity(), entity.Yaw()), 0.0f) + * glm::transpose(entity.Transform()) )); steering.Enable(Steering::TARGET_VELOCITY); steering.Disable(Steering::HALT); @@ -221,7 +221,7 @@ void DirectInput::PlaceBlock() { // if view is straight up or down, this will be a null vector (NaN after normalization) // in that case maybe the model forward should be used? // the current implementation implicitly falls back to TURN_NONE which is -Z - const glm::vec3 local_forward(normalize(view_forward - proj(view_forward, player_up))); + const glm::vec3 local_forward(glm::normalize(view_forward - glm::proj(view_forward, player_up))); // FIXME: I suspect this only works when player_up is positive Y if (local_forward.x > 0.707f) { new_block.SetTurn(Block::TURN_RIGHT); diff --git a/src/ui/widgets.cpp b/src/ui/widgets.cpp index d05ea2f..bae54cb 100644 --- a/src/ui/widgets.cpp +++ b/src/ui/widgets.cpp @@ -86,7 +86,7 @@ void MessageBox::Render(Viewport &viewport) noexcept { } BlendedSprite &prog = viewport.SpriteProgram(); prog.SetBG(glm::vec4(0.0f)); - prog.SetFG(fg); + prog.SetFG(glm::vec4(fg) * (1.0f / 255.0f)); for (Text &txt : lines) { prog.SetM(viewport.Cursor()); txt.Render(viewport); @@ -329,7 +329,7 @@ void TextInput::Render(Viewport &viewport) { if (!input.empty()) { BlendedSprite &prog = viewport.SpriteProgram(); prog.SetBG(glm::vec4(0.0f)); - prog.SetFG(fg); + prog.SetFG(glm::vec4(fg) * (1.0f / 255.0f)); prog.SetM(viewport.Cursor()); text.Render(viewport); } diff --git a/src/world/Block.hpp b/src/world/Block.hpp index ea3de59..2eac5ff 100644 --- a/src/world/Block.hpp +++ b/src/world/Block.hpp @@ -1,8 +1,9 @@ #ifndef BLANK_WORLD_BLOCK_HPP_ #define BLANK_WORLD_BLOCK_HPP_ +#include "../graphics/glm.hpp" + #include -#include namespace blank { @@ -86,7 +87,7 @@ struct Block { } static Face NormalFace(const glm::vec3 &norm) noexcept { - const glm::vec3 anorm(abs(norm)); + const glm::vec3 anorm(glm::abs(norm)); if (anorm.x > anorm.y) { if (anorm.x > anorm.z) { return norm.x > 0.0f ? FACE_RIGHT : FACE_LEFT; diff --git a/src/world/BlockGravity.hpp b/src/world/BlockGravity.hpp index 6a17b61..3900207 100644 --- a/src/world/BlockGravity.hpp +++ b/src/world/BlockGravity.hpp @@ -1,8 +1,9 @@ #ifndef BLANK_WORLD_BLOCKGRAVITY_HPP_ #define BLANK_WORLD_BLOCKGRAVITY_HPP_ +#include "../graphics/glm.hpp" + #include -#include namespace blank { diff --git a/src/world/BlockType.hpp b/src/world/BlockType.hpp index f1b887d..c55c674 100644 --- a/src/world/BlockType.hpp +++ b/src/world/BlockType.hpp @@ -5,10 +5,10 @@ #include "BlockGravity.hpp" #include "../graphics/BlockMesh.hpp" #include "../graphics/EntityMesh.hpp" +#include "../graphics/glm.hpp" #include "../graphics/PrimitiveMesh.hpp" #include "../model/Shape.hpp" -#include #include #include @@ -25,9 +25,9 @@ struct BlockType { const Shape *shape; std::vector textures; - glm::tvec3 hsl_mod; - glm::tvec3 rgb_mod; - glm::tvec3 outline_color; + TVEC3 hsl_mod; + TVEC3 rgb_mod; + TVEC3 outline_color; /// gravity configuration or null if not emitting gravity std::unique_ptr gravity; diff --git a/src/world/Chunk.hpp b/src/world/Chunk.hpp index 6779414..9776567 100644 --- a/src/world/Chunk.hpp +++ b/src/world/Chunk.hpp @@ -5,10 +5,10 @@ #include "BlockTypeRegistry.hpp" #include "../geometry/Location.hpp" #include "../geometry/primitive.hpp" +#include "../graphics/glm.hpp" #include #include -#include #include @@ -55,6 +55,9 @@ public: pos.y >= 0 && pos.y < side && pos.z >= 0 && pos.z < side; } + static int ToIndex(const ExactLocation::Fine &pos) noexcept { + return ToIndex(RoughLocation::Fine(pos)); + } static constexpr int ToIndex(const RoughLocation::Fine &pos) noexcept { return pos.x + pos.y * side + pos.z * side * side; } @@ -178,7 +181,7 @@ public: const ExactLocation::Coarse &Position() const noexcept { return position; } glm::mat4 Transform(const ExactLocation::Coarse &offset) const noexcept { - return glm::translate((position - offset) * ExactLocation::Extent()); + return glm::translate(ExactLocation::Fine((position - offset) * ExactLocation::Extent())); } void *BlockData() noexcept { return &blocks[0]; } diff --git a/src/world/Entity.hpp b/src/world/Entity.hpp index b140a08..d5c3cb1 100644 --- a/src/world/Entity.hpp +++ b/src/world/Entity.hpp @@ -6,11 +6,11 @@ #include "EntityState.hpp" #include "Steering.hpp" #include "../geometry/primitive.hpp" +#include "../graphics/glm.hpp" #include "../model/Instance.hpp" #include #include -#include #include diff --git a/src/world/EntityDerivative.hpp b/src/world/EntityDerivative.hpp index d3a6f30..68654d3 100644 --- a/src/world/EntityDerivative.hpp +++ b/src/world/EntityDerivative.hpp @@ -1,7 +1,7 @@ #ifndef BLANK_WORLD_ENTITYDERIVATIVE_HPP_ #define BLANK_WORLD_ENTITYDERIVATIVE_HPP_ -#include +#include "../graphics/glm.hpp" namespace blank { diff --git a/src/world/EntityState.hpp b/src/world/EntityState.hpp index ee99c76..e862161 100644 --- a/src/world/EntityState.hpp +++ b/src/world/EntityState.hpp @@ -2,8 +2,8 @@ #define BLANK_WORLD_ENTITYSTATE_HPP_ #include "../geometry/Location.hpp" +#include "../graphics/glm.hpp" -#include #include diff --git a/src/world/Generator.cpp b/src/world/Generator.cpp index fa6e01e..51efa25 100644 --- a/src/world/Generator.cpp +++ b/src/world/Generator.cpp @@ -3,10 +3,9 @@ #include "BlockType.hpp" #include "BlockTypeRegistry.hpp" #include "Chunk.hpp" +#include "../graphics/glm.hpp" #include "../rand/OctaveNoise.hpp" -#include - namespace blank { diff --git a/src/world/Generator.hpp b/src/world/Generator.hpp index 50b5089..e431f7d 100644 --- a/src/world/Generator.hpp +++ b/src/world/Generator.hpp @@ -1,11 +1,11 @@ #ifndef BLANK_WORLD_GENERATOR_HPP_ #define BLANK_WORLD_GENERATOR_HPP_ +#include "../graphics/glm.hpp" #include "../rand/SimplexNoise.hpp" #include #include -#include namespace blank { diff --git a/src/world/Steering.hpp b/src/world/Steering.hpp index d6ec57f..6acd0cf 100644 --- a/src/world/Steering.hpp +++ b/src/world/Steering.hpp @@ -3,8 +3,7 @@ #include "../geometry/Location.hpp" #include "../geometry/primitive.hpp" - -#include +#include "../graphics/glm.hpp" namespace blank { diff --git a/src/world/World.hpp b/src/world/World.hpp index 40136c8..7785ed6 100644 --- a/src/world/World.hpp +++ b/src/world/World.hpp @@ -5,13 +5,13 @@ #include "Entity.hpp" #include "Generator.hpp" #include "Player.hpp" +#include "../graphics/glm.hpp" #include "../rand/GaloisLFSR.hpp" #include #include #include #include -#include namespace blank { diff --git a/src/world/WorldCollision.hpp b/src/world/WorldCollision.hpp index 65cba9d..8b0f5a1 100644 --- a/src/world/WorldCollision.hpp +++ b/src/world/WorldCollision.hpp @@ -3,8 +3,7 @@ #include "BlockType.hpp" #include "Chunk.hpp" - -#include +#include "../graphics/glm.hpp" namespace blank { diff --git a/src/world/block.cpp b/src/world/block.cpp index b0fdf61..32cbe04 100644 --- a/src/world/block.cpp +++ b/src/world/block.cpp @@ -149,13 +149,13 @@ void BlockType::Read( in.Skip(Token::BRACKET_CLOSE); } else if (name == "rgb_mod") { in.ReadVec(color_conv); - rgb_mod = glm::tvec3(color_conv * 255.0f); + rgb_mod = BlockMesh::ColorMod(color_conv * 255.0f); } else if (name == "hsl_mod") { in.ReadVec(color_conv); - hsl_mod = glm::tvec3(color_conv * 255.0f); + hsl_mod = BlockMesh::ColorMod(color_conv * 255.0f); } else if (name == "outline") { in.ReadVec(color_conv); - outline_color = glm::tvec3(color_conv * 255.0f); + outline_color = BlockMesh::ColorMod(color_conv * 255.0f); } else if (name == "gravity") { gravity = BlockGravity::Read(in); } else if (name == "label") { @@ -240,7 +240,7 @@ void BlockType::FillBlockMesh( void BlockType::OutlinePrimitiveMesh(PrimitiveMesh::Buffer &buf) const noexcept { if (!shape) return; shape->Outline(buf); - buf.colors.insert(buf.colors.end(), shape->OutlineCount(), glm::tvec4(outline_color, 255)); + buf.colors.insert(buf.colors.end(), shape->OutlineCount(), PrimitiveMesh::Color(outline_color, 255)); } @@ -297,8 +297,8 @@ struct RadialGravity : strength(strength) { } glm::vec3 GetGravity(const glm::vec3 &diff, const glm::mat4 &) const noexcept override { - float dist2 = length2(diff); - glm::vec3 dir = -normalize(diff); + float dist2 = glm::length2(diff); + glm::vec3 dir = -glm::normalize(diff); return dir * (strength / dist2); } diff --git a/src/world/chunk.cpp b/src/world/chunk.cpp index 7f7b185..3374e99 100644 --- a/src/world/chunk.cpp +++ b/src/world/chunk.cpp @@ -465,13 +465,13 @@ bool Chunk::Intersection( constexpr float block_rad = 2.0f; const float bb_radius = box_rad + block_rad; - const RoughLocation::Fine begin(max( + const RoughLocation::Fine begin(glm::max( RoughLocation::Fine(0), - RoughLocation::Fine(floor(box_coords - bb_radius)) + RoughLocation::Fine(glm::floor(box_coords - bb_radius)) )); - const RoughLocation::Fine end(min( + const RoughLocation::Fine end(glm::min( RoughLocation::Fine(side - 1), - RoughLocation::Fine(ceil(box_coords + bb_radius)) + RoughLocation::Fine(glm::ceil(box_coords + bb_radius)) ) - 1); for (RoughLocation::Fine pos(begin); pos.z < end.y; ++pos.z) { @@ -502,7 +502,7 @@ bool Chunk::Intersection( const glm::vec3 entity_coords(Mentity[3] - Mchunk[3]); const float ec_radius = entity.Radius() + Radius(); - if (distance2(entity_coords, Center()) > ec_radius * ec_radius) { + if (glm::distance2(entity_coords, Center()) > ec_radius * ec_radius) { return false; } @@ -514,13 +514,13 @@ bool Chunk::Intersection( constexpr float block_rad = 2.0f; const float eb_radius = entity.Radius() + block_rad; - const RoughLocation::Fine begin(max( + const RoughLocation::Fine begin(glm::max( RoughLocation::Fine(0), - RoughLocation::Fine(floor(entity_coords - eb_radius)) + RoughLocation::Fine(glm::floor(entity_coords - eb_radius)) )); - const RoughLocation::Fine end(min( + const RoughLocation::Fine end(glm::min( RoughLocation::Fine(side), - RoughLocation::Fine(ceil(entity_coords + eb_radius)) + RoughLocation::Fine(glm::ceil(entity_coords + eb_radius)) )); for (RoughLocation::Fine pos(begin); pos.z < end.z; ++pos.z) { @@ -819,7 +819,7 @@ void ChunkRenderer::Render(Viewport &viewport) { chunk_prog.SetTexture(block_tex); chunk_prog.SetFogDensity(fog_density); - Frustum frustum(transpose(chunk_prog.GetVP())); + Frustum frustum(glm::transpose(chunk_prog.GetVP())); AABB box; for (int i = 0; i < index.TotalChunks(); ++i) { diff --git a/src/world/world.cpp b/src/world/world.cpp index a12d86e..f0f9496 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -202,12 +202,12 @@ void Entity::UpdateTransforms() noexcept { if (model) { view_transform = model.EyesTransform(); } else { - view_transform = toMat4(glm::quat(glm::vec3(state.pitch, state.yaw, 0.0f))); + view_transform = glm::toMat4(glm::quat(glm::vec3(state.pitch, state.yaw, 0.0f))); } } void Entity::UpdateHeading() noexcept { - speed = length(Velocity()); + speed = glm::length(Velocity()); if (speed > std::numeric_limits::epsilon()) { heading = Velocity() / speed; } else { @@ -238,21 +238,21 @@ void Entity::OrientBody(float dt) noexcept { // check if our orientation and velocity are aligned const glm::vec3 forward(-model_transform[2]); // facing is local -Z rotated about local Y by yaw and transformed into world space - const glm::vec3 facing(normalize(glm::vec3(glm::vec4(rotateY(glm::vec3(0.0f, 0.0f, -1.0f), state.yaw), 0.0f) * transpose(model_transform)))); + const glm::vec3 facing(glm::normalize(glm::vec3(glm::vec4(glm::rotateY(glm::vec3(0.0f, 0.0f, -1.0f), state.yaw), 0.0f) * glm::transpose(model_transform)))); // only adjust if velocity isn't almost parallel to up - float vel_dot_up = dot(Velocity(), up); + float vel_dot_up = glm::dot(Velocity(), up); if (std::abs(1.0f - std::abs(vel_dot_up)) > std::numeric_limits::epsilon()) { // get direction of velocity projected onto model plane - glm::vec3 direction(normalize(Velocity() - (Velocity() * vel_dot_up))); + glm::vec3 direction(glm::normalize(Velocity() - (Velocity() * vel_dot_up))); // if velocity points away from our facing (with a little bias), flip it around // (the entity is "walking backwards") - if (dot(facing, direction) < -0.1f) { + if (glm::dot(facing, direction) < -0.1f) { direction = -direction; } // calculate the difference between forward and direction - const float absolute_difference = std::acos(dot(forward, direction)); + const float absolute_difference = std::acos(glm::dot(forward, direction)); // if direction is clockwise with respect to up vector, invert the angle - const float relative_difference = dot(cross(forward, direction), up) < 0.0f + const float relative_difference = glm::dot(glm::cross(forward, direction), up) < 0.0f ? -absolute_difference : absolute_difference; // only correct by half the difference max @@ -268,7 +268,7 @@ void Entity::OrientBody(float dt) noexcept { std::cout << std::endl; } // now rotate body by correction and head by -correction - state.orient = rotate(state.orient, correction, up); + state.orient = glm::rotate(state.orient, correction, up); state.yaw -= correction; } } @@ -283,7 +283,7 @@ void Entity::OrientHead(float dt) noexcept { if (std::abs(state.yaw) > max_head_yaw) { float deviation = state.yaw < 0.0f ? state.yaw + max_head_yaw : state.yaw - max_head_yaw; // rotate the entity by deviation about local Y - state.orient = rotate(state.orient, deviation, up); + state.orient = glm::rotate(state.orient, deviation, up); // and remove from head yaw state.yaw -= deviation; // shouldn't be necessary if max_head_yaw is < PI, but just to be sure :p @@ -364,7 +364,7 @@ void EntityState::AdjustHeading() noexcept { glm::mat4 EntityState::Transform(const glm::ivec3 &reference) const noexcept { const glm::vec3 translation = RelativePosition(reference); - glm::mat4 transform(toMat4(orient)); + glm::mat4 transform(glm::toMat4(orient)); transform[3] = glm::vec4(translation, 1.0f); return transform; } @@ -449,7 +449,7 @@ void Steering::UpdateWander(World &world, float dt) { world.Random().SNorm() * wander_disp ); if (!iszero(displacement)) { - wander_pos = normalize(wander_pos + displacement * dt) * wander_radius; + wander_pos = glm::normalize(wander_pos + displacement * dt) * wander_radius; } } @@ -476,7 +476,7 @@ void Steering::UpdateObstacle(World &world) { for (const WorldCollision &c : col) { // diff points from block to state glm::vec3 diff = entity.GetState().RelativePosition(c.ChunkPos()) - c.BlockCoords(); - float dist = length2(diff); + float dist = glm::length2(diff); if (dist < distance) { nearest = &c; difference = diff; @@ -489,9 +489,9 @@ void Steering::UpdateObstacle(World &world) { return; } // and try to avoid it - float to_go = dot(difference, entity.Heading()); + float to_go = glm::dot(difference, entity.Heading()); glm::vec3 point(entity.Position() + entity.Heading() * to_go); - obstacle_dir = normalize(point - nearest->BlockCoords()) * (entity.Speed() / std::sqrt(distance)); + obstacle_dir = glm::normalize(point - nearest->BlockCoords()) * (entity.Speed() / std::sqrt(distance)); } glm::vec3 Steering::Force(const EntityState &state) const noexcept { @@ -542,17 +542,17 @@ glm::vec3 Steering::Force(const EntityState &state) const noexcept { } bool Steering::SumForce(glm::vec3 &out, const glm::vec3 &in, float max) noexcept { - if (iszero(in) || any(isnan(in))) { + if (iszero(in) || glm::any(glm::isnan(in))) { return false; } - float current = iszero(out) ? 0.0f : length(out); + float current = iszero(out) ? 0.0f : glm::length(out); float remain = max - current; if (remain <= 0.0f) { return true; } - float additional = length(in); + float additional = glm::length(in); if (additional > remain) { - out += normalize(in) * remain; + out += glm::normalize(in) * remain; return true; } else { out += in; @@ -573,7 +573,7 @@ glm::vec3 Steering::Seek(const EntityState &state, const ExactLocation &loc) con if (iszero(diff)) { return glm::vec3(0.0f); } else { - return TargetVelocity(state, normalize(diff) * speed); + return TargetVelocity(state, glm::normalize(diff) * speed); } } @@ -582,13 +582,13 @@ glm::vec3 Steering::Flee(const EntityState &state, const ExactLocation &loc) con if (iszero(diff)) { return glm::vec3(0.0f); } else { - return TargetVelocity(state, normalize(diff) * speed); + return TargetVelocity(state, glm::normalize(diff) * speed); } } glm::vec3 Steering::Arrive(const EntityState &state, const ExactLocation &loc) const noexcept { const glm::vec3 diff(loc.Difference(state.pos).Absolute()); - const float dist = length(diff); + const float dist = glm::length(diff); if (dist < std::numeric_limits::epsilon()) { return glm::vec3(0.0f); } else { @@ -602,7 +602,7 @@ glm::vec3 Steering::Pursuit(const EntityState &state, const Entity &other) const if (iszero(diff)) { return TargetVelocity(state, other.Velocity()); } else { - const float time_estimate = length(diff) / speed; + const float time_estimate = glm::length(diff) / speed; ExactLocation prediction(other.ChunkCoords(), other.Position() + (other.Velocity() * time_estimate)); return Seek(state, prediction); } @@ -613,14 +613,14 @@ glm::vec3 Steering::Evade(const EntityState &state, const Entity &other) const n if (iszero(diff)) { return TargetVelocity(state, -other.Velocity()); } else { - const float time_estimate = length(diff) / speed; + const float time_estimate = glm::length(diff) / speed; ExactLocation prediction(other.ChunkCoords(), other.Position() + (other.Velocity() * time_estimate)); return Flee(state, prediction); } } glm::vec3 Steering::Wander(const EntityState &state) const noexcept { - return TargetVelocity(state, normalize(entity.Heading() * wander_dist + wander_pos) * speed); + return TargetVelocity(state, glm::normalize(entity.Heading() * wander_dist + wander_pos) * speed); } glm::vec3 Steering::ObstacleAvoidance(const EntityState &state) const noexcept { @@ -951,13 +951,13 @@ void World::ResolveWorldCollision( } // if entity is already going in the direction of correction, // let the problem resolve itself - if (dot(state.velocity, correction) >= 0.0f) { + if (glm::dot(state.velocity, correction) >= 0.0f) { return; } // apply correction, maybe could use some damping, gotta test state.pos.block += correction; // kill velocity? - glm::vec3 normal_velocity(proj(state.velocity, correction)); + glm::vec3 normal_velocity(glm::proj(state.velocity, correction)); state.velocity -= normal_velocity; } @@ -972,7 +972,7 @@ glm::vec3 World::CombinedInterpenetration( if (!c.Blocks()) continue; glm::vec3 normal(c.normal); // swap if neccessary (normal may point away from the entity) - if (dot(normal, state.RelativePosition(c.ChunkPos()) - c.BlockCoords()) < 0) { + if (glm::dot(normal, state.RelativePosition(c.ChunkPos()) - c.BlockCoords()) < 0) { normal = -normal; } // check if block surface is "inside" @@ -983,8 +983,8 @@ glm::vec3 World::CombinedInterpenetration( continue; } glm::vec3 local_pen(normal * c.depth); - min_pen = min(min_pen, local_pen); - max_pen = max(max_pen, local_pen); + min_pen = glm::min(min_pen, local_pen); + max_pen = glm::max(max_pen, local_pen); } glm::vec3 pen(0.0f); // only apply correction for axes where penetration is only in one direction @@ -1060,7 +1060,7 @@ void World::GetLight( glm::vec3 &col, glm::vec3 &amb ) { - BlockLookup center(chunks.Get(e.ChunkCoords()), e.Position()); + BlockLookup center(chunks.Get(e.ChunkCoords()), RoughLocation::Fine(e.Position())); if (!center) { // chunk unavailable, so make it really dark and from // some arbitrary direction @@ -1103,7 +1103,7 @@ void World::RenderDebug(Viewport &viewport) { PrimitiveMesh debug_mesh; PlainColor &prog = viewport.WorldColorProgram(); for (const Entity &entity : entities) { - debug_buf.OutlineBox(entity.Bounds(), glm::tvec4(255, 0, 0, 255)); + debug_buf.OutlineBox(entity.Bounds(), TVEC4(255, 0, 0, 255)); debug_mesh.Update(debug_buf); prog.SetM(entity.Transform(players.front().GetEntity().ChunkCoords())); debug_mesh.DrawLines(); diff --git a/tst/geometry/IntersectionTest.cpp b/tst/geometry/IntersectionTest.cpp index 521647e..1b61838 100644 --- a/tst/geometry/IntersectionTest.cpp +++ b/tst/geometry/IntersectionTest.cpp @@ -165,7 +165,7 @@ void IntersectionTest::testBoxBoxIntersection() { ); CPPUNIT_ASSERT_EQUAL_MESSAGE( "bad intersection normal (with rotation)", - glm::vec3(1, 0, 0), abs(normal) // normal can be in + or - x, therefore abs() + glm::vec3(1, 0, 0), glm::abs(normal) // normal can be in + or - x, therefore abs() ); Mb = glm::translate(glm::vec3(3, 0, 0)); // 3 to the right diff --git a/tst/geometry/LocationTest.hpp b/tst/geometry/LocationTest.hpp index d46be0b..104adcd 100644 --- a/tst/geometry/LocationTest.hpp +++ b/tst/geometry/LocationTest.hpp @@ -2,9 +2,9 @@ #define BLANK_TEST_GEOMETRY_LOCATIONTEST_HPP_ #include "geometry/Location.hpp" +#include "graphics/glm.hpp" #include -#include #include diff --git a/tst/graphics/GLTraitsTest.cpp b/tst/graphics/GLTraitsTest.cpp index 54d860c..5f13446 100644 --- a/tst/graphics/GLTraitsTest.cpp +++ b/tst/graphics/GLTraitsTest.cpp @@ -127,15 +127,15 @@ void GLTraitsTest::testType() { CPPUNIT_ASSERT_EQUAL_MESSAGE( "bad component type for vec2i", - GLenum(GL_INT), gl_traits>::type + GLenum(GL_INT), gl_traits::type ); CPPUNIT_ASSERT_EQUAL_MESSAGE( "bad component type for vec3i", - GLenum(GL_INT), gl_traits>::type + GLenum(GL_INT), gl_traits::type ); CPPUNIT_ASSERT_EQUAL_MESSAGE( "bad component type for vec4i", - GLenum(GL_INT), gl_traits>::type + GLenum(GL_INT), gl_traits::type ); } diff --git a/tst/net/PacketTest.cpp b/tst/net/PacketTest.cpp index 880d6a5..cf76d15 100644 --- a/tst/net/PacketTest.cpp +++ b/tst/net/PacketTest.cpp @@ -116,7 +116,7 @@ void PacketTest::testJoin() { EntityState write_state; write_state.pos = { { 7, 2, -3 }, { 1.5f, 0.9f, 12.0f } }; write_state.velocity = { 0.025f, 0.001f, 0.0f }; - write_state.orient = normalize(glm::quat(0.863f, 0.0f, 0.505f, 0.0f)); + write_state.orient = glm::normalize(glm::quat(0.863f, 0.0f, 0.505f, 0.0f)); write_state.pitch = 0.3f; write_state.yaw = -2.3f; write_entity.SetState(write_state); diff --git a/tst/net/PacketTest.hpp b/tst/net/PacketTest.hpp index 25256d9..81cdd82 100644 --- a/tst/net/PacketTest.hpp +++ b/tst/net/PacketTest.hpp @@ -2,6 +2,7 @@ #define BLANK_TEST_NET_PACKETTEST_HPP_ #include "geometry/primitive.hpp" +#include "graphics/glm.hpp" #include "net/Packet.hpp" #include "world/EntityState.hpp" @@ -9,7 +10,6 @@ #include #include #include -#include #include diff --git a/tst/rand/StabilityTest.hpp b/tst/rand/StabilityTest.hpp index a4ea86e..b2ee1ae 100644 --- a/tst/rand/StabilityTest.hpp +++ b/tst/rand/StabilityTest.hpp @@ -1,7 +1,8 @@ #ifndef BLANK_TEST_RAND_STABILITYTEST_HPP #define BLANK_TEST_RAND_STABILITYTEST_HPP -#include +#include "graphics/glm.hpp" + #include