Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
acgl
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ACGL
acgl
Commits
79d8857a
Commit
79d8857a
authored
Dec 12, 2012
by
Robert Menzel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added approx equal functions for matrices and vectors in Math
parent
bcada566
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
136 additions
and
24 deletions
+136
-24
include/ACGL/Math/Functions.hh
include/ACGL/Math/Functions.hh
+55
-24
src/ACGL/Math/Functions.cc
src/ACGL/Math/Functions.cc
+80
-0
src/ACGL/Scene/Camera.cc
src/ACGL/Scene/Camera.cc
+1
-0
No files found.
include/ACGL/Math/Functions.hh
View file @
79d8857a
...
...
@@ -97,38 +97,69 @@ inline T min(T a, T b) {return(a < b ? a : b);}
inline
uint_t
ring
(
int_t
a
,
uint_t
mod
)
{
bool
b
=
a
<
0
;
a
=
abs
(
a
)
%
mod
;
return
(
b
?
mod
-
a
:
a
);}
inline
glm
::
mat3
rotationMatrixX
(
float
degree
)
{
glm
::
mat3
matrix
;
matrix
[
0
][
0
]
=
1.0
f
;
matrix
[
1
][
0
]
=
0.0
f
;
matrix
[
2
][
0
]
=
0.0
f
;
matrix
[
0
][
1
]
=
0.0
f
;
matrix
[
1
][
1
]
=
cosDeg
(
degree
);
matrix
[
2
][
1
]
=
-
sinDeg
(
degree
);
matrix
[
0
][
2
]
=
0.0
f
;
matrix
[
1
][
2
]
=
sinDeg
(
degree
);
matrix
[
2
][
2
]
=
cosDeg
(
degree
);
return
matrix
;
}
/**
* @brief Returns a rotation matrix that rotates a givn degree around the X-axis.
* @param degree is the angle in degree, not radians!
* @return The rotation matrix.
*/
glm
::
mat3
rotationMatrixX
(
float
degree
);
inline
glm
::
mat3
rotationMatrixY
(
float
degree
)
{
glm
::
mat3
matrix
;
matrix
[
0
][
0
]
=
cosDeg
(
degree
);
matrix
[
1
][
0
]
=
0.0
f
;
matrix
[
2
][
0
]
=
sinDeg
(
degree
);
matrix
[
0
][
1
]
=
0.0
f
;
matrix
[
1
][
1
]
=
1.0
f
;
matrix
[
2
][
1
]
=
0.0
f
;
matrix
[
0
][
2
]
=
-
sinDeg
(
degree
);
matrix
[
1
][
2
]
=
0.0
f
;
matrix
[
2
][
2
]
=
cosDeg
(
degree
);
return
matrix
;
}
/**
* @brief Returns a rotation matrix that rotates a givn degree around the Y-axis.
* @param degree is the angle in degree, not radians!
* @return The rotation matrix.
*/
glm
::
mat3
rotationMatrixY
(
float
degree
);
inline
glm
::
mat3
rotationMatrixZ
(
float
degree
)
{
glm
::
mat3
matrix
;
matrix
[
0
][
0
]
=
cosDeg
(
degree
);
matrix
[
1
][
0
]
=
-
sinDeg
(
degree
);
matrix
[
2
][
0
]
=
0.0
f
;
matrix
[
0
][
1
]
=
sinDeg
(
degree
);
matrix
[
1
][
1
]
=
cosDeg
(
degree
);
matrix
[
2
][
1
]
=
0.0
f
;
matrix
[
0
][
2
]
=
0.0
f
;
matrix
[
1
][
2
]
=
0.0
f
;
matrix
[
2
][
2
]
=
1.0
f
;
return
matrix
;
}
/**
* @brief Returns a rotation matrix that rotates a givn degree around the Z-axis.
* @param degree is the angle in degree, not radians!
* @return The rotation matrix.
*/
glm
::
mat3
rotationMatrixZ
(
float
degree
);
/**
* @brief Returns the inverse transpose of the given matrix to use as a normal matrix.
* @param The e.g. modelview matrix.
* @return The inverse transposed.
*/
inline
glm
::
mat3
normalMatrix
(
const
glm
::
mat4
&
matrix
)
{
return
glm
::
inverseTranspose
(
glm
::
mat3
(
matrix
)
);
}
/**
* @brief Test if two glm vectors are equal with respect to a given epsilon.
*/
template
<
typename
T
>
bool
isApproxEqual
(
const
T
&
_v1
,
const
T
&
_v2
,
float
_eps
=
.01
)
{
return
glm
::
distance
(
_v1
,
_v2
)
<
_eps
;
}
/**
* @brief isApproxEqual returns whether two glm 4x4 matrices are equal with respect to a small epsilon.
* @param _v1: first matrix
* @param _v2: second matrix
* @param _eps: small numerical value
* @return true if the sum off the componentwise difference is smaller than _eps.
*/
bool
isApproxEqual
(
const
glm
::
mat4
&
_v1
,
const
glm
::
mat4
&
_v2
,
float
_eps
=
.01
);
/**
* @brief isApproxEqual returns whether two glm 3x3 matrices are equal with respect to a small epsilon.
* @param _v1: first matrix
* @param _v2: second matrix
* @param _eps: small numerical value
* @return true if the sum off the componentwise difference is smaller than _eps.
*/
bool
isApproxEqual
(
const
glm
::
mat3
&
_v1
,
const
glm
::
mat3
&
_v2
,
float
_eps
=
.01
);
/**
* @brief Checks if a given matrix is orthonormal.
*/
bool
isOrthonormalMatrix
(
const
glm
::
mat3
&
_matrix
);
}
// Functions
}
// Math
}
// ACGL
...
...
src/ACGL/Math/Functions.cc
0 → 100644
View file @
79d8857a
#include <ACGL/Math/Math.hh> // will include the functions.hh but also the GLM
namespace
ACGL
{
namespace
Math
{
namespace
Functions
{
glm
::
mat3
rotationMatrixX
(
float
degree
)
{
glm
::
mat3
matrix
;
matrix
[
0
][
0
]
=
1.0
f
;
matrix
[
1
][
0
]
=
0.0
f
;
matrix
[
2
][
0
]
=
0.0
f
;
matrix
[
0
][
1
]
=
0.0
f
;
matrix
[
1
][
1
]
=
cosDeg
(
degree
);
matrix
[
2
][
1
]
=
-
sinDeg
(
degree
);
matrix
[
0
][
2
]
=
0.0
f
;
matrix
[
1
][
2
]
=
sinDeg
(
degree
);
matrix
[
2
][
2
]
=
cosDeg
(
degree
);
return
matrix
;
}
glm
::
mat3
rotationMatrixY
(
float
degree
)
{
glm
::
mat3
matrix
;
matrix
[
0
][
0
]
=
cosDeg
(
degree
);
matrix
[
1
][
0
]
=
0.0
f
;
matrix
[
2
][
0
]
=
sinDeg
(
degree
);
matrix
[
0
][
1
]
=
0.0
f
;
matrix
[
1
][
1
]
=
1.0
f
;
matrix
[
2
][
1
]
=
0.0
f
;
matrix
[
0
][
2
]
=
-
sinDeg
(
degree
);
matrix
[
1
][
2
]
=
0.0
f
;
matrix
[
2
][
2
]
=
cosDeg
(
degree
);
return
matrix
;
}
glm
::
mat3
rotationMatrixZ
(
float
degree
)
{
glm
::
mat3
matrix
;
matrix
[
0
][
0
]
=
cosDeg
(
degree
);
matrix
[
1
][
0
]
=
-
sinDeg
(
degree
);
matrix
[
2
][
0
]
=
0.0
f
;
matrix
[
0
][
1
]
=
sinDeg
(
degree
);
matrix
[
1
][
1
]
=
cosDeg
(
degree
);
matrix
[
2
][
1
]
=
0.0
f
;
matrix
[
0
][
2
]
=
0.0
f
;
matrix
[
1
][
2
]
=
0.0
f
;
matrix
[
2
][
2
]
=
1.0
f
;
return
matrix
;
}
bool
isApproxEqual
(
const
glm
::
mat4
&
_v1
,
const
glm
::
mat4
&
_v2
,
float
_eps
)
{
glm
::
mat4
diff
=
_v1
-
_v2
;
float
d
=
0
;
d
+=
glm
::
abs
(
diff
[
0
][
0
]);
d
+=
glm
::
abs
(
diff
[
0
][
1
]);
d
+=
glm
::
abs
(
diff
[
0
][
2
]);
d
+=
glm
::
abs
(
diff
[
0
][
3
]);
d
+=
glm
::
abs
(
diff
[
1
][
0
]);
d
+=
glm
::
abs
(
diff
[
1
][
1
]);
d
+=
glm
::
abs
(
diff
[
1
][
2
]);
d
+=
glm
::
abs
(
diff
[
1
][
3
]);
d
+=
glm
::
abs
(
diff
[
2
][
0
]);
d
+=
glm
::
abs
(
diff
[
2
][
1
]);
d
+=
glm
::
abs
(
diff
[
2
][
2
]);
d
+=
glm
::
abs
(
diff
[
2
][
3
]);
d
+=
glm
::
abs
(
diff
[
3
][
0
]);
d
+=
glm
::
abs
(
diff
[
3
][
1
]);
d
+=
glm
::
abs
(
diff
[
3
][
2
]);
d
+=
glm
::
abs
(
diff
[
3
][
3
]);
return
d
<
_eps
;
}
bool
isApproxEqual
(
const
glm
::
mat3
&
_v1
,
const
glm
::
mat3
&
_v2
,
float
_eps
)
{
glm
::
mat3
diff
=
_v1
-
_v2
;
float
d
=
0
;
d
+=
glm
::
abs
(
diff
[
0
][
0
]);
d
+=
glm
::
abs
(
diff
[
0
][
1
]);
d
+=
glm
::
abs
(
diff
[
0
][
2
]);
d
+=
glm
::
abs
(
diff
[
1
][
0
]);
d
+=
glm
::
abs
(
diff
[
1
][
1
]);
d
+=
glm
::
abs
(
diff
[
1
][
2
]);
d
+=
glm
::
abs
(
diff
[
2
][
0
]);
d
+=
glm
::
abs
(
diff
[
2
][
1
]);
d
+=
glm
::
abs
(
diff
[
2
][
2
]);
return
d
<
_eps
;
}
bool
isOrthonormalMatrix
(
const
glm
::
mat3
&
_matrix
)
{
return
isApproxEqual
(
glm
::
inverse
(
_matrix
),
glm
::
transpose
(
_matrix
));
}
}
// namespace
}
// namespace
}
// namespace
src/ACGL/Scene/Camera.cc
View file @
79d8857a
...
...
@@ -6,6 +6,7 @@
#include <ACGL/Scene/Camera.hh>
using
namespace
ACGL
;
using
namespace
ACGL
::
Scene
;
glm
::
mat4
Camera
::
getProjectionMatrix
(
void
)
const
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment