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

PredatorCZ / PreCore / 460

pending completion
460

push

github-actions-ci

PredatorCZ
try fix coverage

3204 of 6095 relevant lines covered (52.57%)

354.19 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
    more info in README for PreCore Project
3

4
    Copyright 2018-2022 Lukas Cone
5

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

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

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

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

24
using namespace es;
25

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

139
Matrix44 Matrix44::operator-() const {
×
140
  auto thisMat = glm::inverse(AsMat4(*this));
141
  return AsMat4(thisMat);
×
142
}
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