• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / PreCore / 461

pending completion
461

push

github-actions-ci

PredatorCZ
update readme

3204 of 6096 relevant lines covered (52.56%)

354.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.46
/src/matrix44.cpp
1
/*  a source for Matrix44 class
2

3
    Copyright 2018-2023 Lukas Cone
4

5
    Licensed under the Apache License, Version 2.0 (the "License");
6
    you may not use this file except in compliance with the License.
7
    You may obtain a copy of the License at
8

9
      http://www.apache.org/licenses/LICENSE-2.0
10

11
    Unless required by applicable law or agreed to in writing, software
12
    distributed under the License is distributed on an "AS IS" BASIS,
13
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
    See the License for the specific language governing permissions and
15
    limitations under the License.
16
*/
17

18
#define GLM_FORCE_QUAT_DATA_XYZW
19
#include "spike/type/matrix44.hpp"
20
#include "glm/ext.hpp"
21
#include "glm/glm.hpp"
22

23
using namespace es;
24

25
static const Vector4A16 &AsVec(const glm::vec4 &in) {
26
  return reinterpret_cast<const Vector4A16 &>(in);
27
}
28

29
static const Vector4A16 &AsVec(const glm::quat &in) {
30
  return reinterpret_cast<const Vector4A16 &>(in);
31
}
32

33
static const glm::quat &AsQuat(const Vector4A16 &in) {
34
  return reinterpret_cast<const glm::quat &>(in);
35
}
36

37
static const glm::vec4 &AsVec(const Vector4A16 &in) {
38
  return reinterpret_cast<const glm::vec4 &>(in);
39
}
40

41
static const Matrix44 &AsMat4(const glm::mat4 &in) {
42
  return reinterpret_cast<const Matrix44 &>(in);
43
}
44

45
static const glm::mat4 &AsMat4(const Matrix44 &in) {
46
  return reinterpret_cast<const glm::mat4 &>(in);
47
}
48

49
[[maybe_unused]] static glm::mat4 &AsMat4(Matrix44 &in) {
50
  return reinterpret_cast<glm::mat4 &>(in);
51
}
52

53
static_assert(sizeof(glm::mat4) == sizeof(Matrix44));
54
static_assert(alignof(glm::mat4) == alignof(Matrix44));
55
static_assert(sizeof(glm::vec4) == sizeof(Vector4A16));
56
static_assert(alignof(glm::vec4) == alignof(Vector4A16));
57
static_assert(sizeof(glm::quat) == sizeof(Vector4A16));
58
static_assert(alignof(glm::quat) == alignof(Vector4A16));
59

60
void Matrix44::Decompose(Vector4A16 &position, Vector4A16 &rotation,
1✔
61
                         Vector4A16 &scale) const {
62
  position = r4();
1✔
63
  scale.X = r1().Length();
1✔
64
  scale.Y = r2().Length();
1✔
65
  scale.Z = r3().Length();
1✔
66

67
  if (r1().Dot(Vector4A16(Vector(r2()).Cross(r3()), 0.0f)) < 0)
1✔
68
    scale *= -1;
69

70
  Matrix44 tmp(*this);
1✔
71
  tmp.r1() /= scale.X;
1✔
72
  tmp.r2() /= scale.Y;
1✔
73
  tmp.r3() /= scale.Z;
1✔
74
  rotation = tmp.ToQuat();
1✔
75
}
1✔
76

77
void Matrix44::Compose(const Vector4A16 &position, const Vector4A16 &rotation,
1✔
78
                       const Vector4A16 &scale) {
79
  FromQuat(rotation);
1✔
80
  r4() = position;
1✔
81
  r4().w = 1.f;
1✔
82
  r1() *= scale.X;
1✔
83
  r2() *= scale.Y;
1✔
84
  r3() *= scale.Z;
1✔
85
}
1✔
86

87
void Matrix44::MakeIdentity() {
7✔
88
  r1() = Vector4A16(1.0f, 0.0f, 0.0f, 0.0f);
7✔
89
  r2() = Vector4A16(0.0f, 1.0f, 0.0f, 0.0f);
7✔
90
  r3() = Vector4A16(0.0f, 0.0f, 1.0f, 0.0f);
7✔
91
  r4() = Vector4A16(0.0f, 0.0f, 0.0f, 1.0f);
7✔
92
}
7✔
93

94
Matrix44::Matrix44() { MakeIdentity(); }
20✔
95

96
Matrix44::Matrix44(const Vector4A16 &quat) {
10✔
97
  MakeIdentity();
2✔
98
  FromQuat(quat);
2✔
99
}
2✔
100

101
void Matrix44::FromQuat(const Vector4A16 &q) {
3✔
102
  *this = AsMat4(glm::mat4_cast(glm::quat(AsQuat(q))));
3✔
103
}
3✔
104

105
Vector4A16 Matrix44::ToQuat() const {
1✔
106
  auto asQuat = glm::quat_cast(AsMat4(*this));
1✔
107
  return {asQuat.y, asQuat.z, asQuat.w, asQuat.x};
1✔
108
}
109

110
void Matrix44::Transpose() {
2✔
111
  __m128 tmp00 =
112
      _mm_shuffle_ps(r1()._data, r2()._data, _MM_SHUFFLE(1, 0, 1, 0));
2✔
113
  __m128 tmp01 =
114
      _mm_shuffle_ps(r1()._data, r2()._data, _MM_SHUFFLE(2, 1, 2, 1));
115

116
  r1()._data = _mm_shuffle_ps(tmp00, r3()._data, _MM_SHUFFLE(3, 0, 2, 0));
2✔
117
  r2()._data = _mm_shuffle_ps(tmp01, r3()._data, _MM_SHUFFLE(3, 1, 2, 0));
2✔
118
  r3()._data = _mm_shuffle_ps(tmp01, r3()._data, _MM_SHUFFLE(3, 2, 3, 1));
2✔
119
}
2✔
120

121
void Matrix44::TransposeFull() {
×
122
  _MM_TRANSPOSE4_PS(r1()._data, r2()._data, r3()._data, r4()._data);
×
123
}
124

125
namespace es {
126
Vector4A16 operator*(const Vector4A16 &point, const es::Matrix44 &mtx) {
1✔
127
  auto result = AsVec(point) * AsMat4(mtx);
1✔
128
  return AsVec(result);
1✔
129
}
130
} // namespace es
131

132
Matrix44 Matrix44::operator*(const Matrix44 &right) const {
×
133
  auto &thisMat = AsMat4(*this);
134
  auto &rightMat = AsMat4(right);
135
  return AsMat4(thisMat * rightMat);
×
136
}
137

138
Matrix44 Matrix44::operator-() const {
×
139
  auto thisMat = glm::inverse(AsMat4(*this));
140
  return AsMat4(thisMat);
×
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc