mirror of
https://github.com/minetest/minetest.git
synced 2025-03-06 20:48:40 +01:00
Use matrix4::getRotationRadians
This commit is contained in:
parent
b6c71b2379
commit
d74af2f1a7
10 changed files with 34 additions and 28 deletions
|
@ -619,7 +619,7 @@ void CAnimatedMeshSceneNode::animateJoints(bool CalculateAbsolutePositions)
|
|||
|
||||
// Code is slow, needs to be fixed up
|
||||
|
||||
const core::quaternion RotationStart(PretransitingSave[n].getRotationDegrees() * core::DEGTORAD);
|
||||
const core::quaternion RotationStart(PretransitingSave[n].getRotationRadians());
|
||||
const core::quaternion RotationEnd(JointChildSceneNodes[n]->getRotation() * core::DEGTORAD);
|
||||
|
||||
core::quaternion QRotation;
|
||||
|
|
|
@ -1526,8 +1526,6 @@ bool CXMeshFileLoader::parseDataObjectAnimationKey(SkinnedMesh::SJoint *joint)
|
|||
os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING);
|
||||
}
|
||||
|
||||
// core::vector3df rotation = mat.getRotationDegrees();
|
||||
|
||||
AnimatedMesh->addRotationKey(joint, time, core::quaternion(mat.getTransposed()));
|
||||
AnimatedMesh->addPositionKey(joint, time, mat.getTranslation());
|
||||
|
||||
|
|
|
@ -441,8 +441,8 @@ void ClientEnvironment::getSelectedActiveObjects(
|
|||
GenericCAO* gcao = dynamic_cast<GenericCAO*>(obj);
|
||||
if (gcao != nullptr && gcao->getProperties().rotate_selectionbox) {
|
||||
gcao->getSceneNode()->updateAbsolutePosition();
|
||||
const v3f deg = obj->getSceneNode()->getAbsoluteTransformation().getRotationDegrees();
|
||||
collision = boxLineCollision(selection_box, deg,
|
||||
const v3f rad = obj->getSceneNode()->getAbsoluteTransformation().getRotationRadians();
|
||||
collision = boxLineCollision(selection_box, rad,
|
||||
rel_pos, line_vector, ¤t_intersection, ¤t_normal, ¤t_raw_normal);
|
||||
} else {
|
||||
collision = boxLineCollision(selection_box, rel_pos, line_vector,
|
||||
|
|
|
@ -3239,9 +3239,10 @@ PointedThing Game::updatePointedThing(
|
|||
hud->setSelectionPos(pos, camera_offset);
|
||||
GenericCAO* gcao = dynamic_cast<GenericCAO*>(runData.selected_object);
|
||||
if (gcao != nullptr && gcao->getProperties().rotate_selectionbox)
|
||||
hud->setSelectionRotation(gcao->getSceneNode()->getAbsoluteTransformation().getRotationDegrees());
|
||||
hud->setSelectionRotationRadians(gcao->getSceneNode()
|
||||
->getAbsoluteTransformation().getRotationRadians());
|
||||
else
|
||||
hud->setSelectionRotation(v3f());
|
||||
hud->setSelectionRotationRadians(v3f());
|
||||
}
|
||||
hud->setSelectedFaceNormal(result.raw_intersection_normal);
|
||||
} else if (result.type == POINTEDTHING_NODE) {
|
||||
|
@ -3261,7 +3262,7 @@ PointedThing Game::updatePointedThing(
|
|||
}
|
||||
hud->setSelectionPos(intToFloat(result.node_undersurface, BS),
|
||||
camera_offset);
|
||||
hud->setSelectionRotation(v3f());
|
||||
hud->setSelectionRotationRadians(v3f());
|
||||
hud->setSelectedFaceNormal(result.intersection_normal);
|
||||
}
|
||||
|
||||
|
|
|
@ -880,7 +880,7 @@ void Hud::drawSelectionMesh()
|
|||
core::matrix4 translate;
|
||||
translate.setTranslation(m_selection_pos_with_offset);
|
||||
core::matrix4 rotation;
|
||||
rotation.setRotationDegrees(m_selection_rotation);
|
||||
rotation.setRotationRadians(m_selection_rotation_radians);
|
||||
driver->setTransform(video::ETS_WORLD, translate * rotation);
|
||||
|
||||
if (m_mode == HIGHLIGHT_BOX) {
|
||||
|
|
|
@ -74,9 +74,15 @@ public:
|
|||
|
||||
v3f getSelectionPos() const { return m_selection_pos; }
|
||||
|
||||
void setSelectionRotation(v3f rotation) { m_selection_rotation = rotation; }
|
||||
void setSelectionRotationRadians(v3f rotation)
|
||||
{
|
||||
m_selection_rotation_radians = rotation;
|
||||
}
|
||||
|
||||
v3f getSelectionRotation() const { return m_selection_rotation; }
|
||||
v3f getSelectionRotationRadians() const
|
||||
{
|
||||
return m_selection_rotation_radians;
|
||||
}
|
||||
|
||||
void setSelectionMeshColor(const video::SColor &color)
|
||||
{
|
||||
|
@ -129,7 +135,7 @@ private:
|
|||
std::vector<aabb3f> m_halo_boxes;
|
||||
v3f m_selection_pos;
|
||||
v3f m_selection_pos_with_offset;
|
||||
v3f m_selection_rotation;
|
||||
v3f m_selection_rotation_radians;
|
||||
|
||||
scene::IMesh *m_selection_mesh = nullptr;
|
||||
video::SColor m_selection_mesh_color;
|
||||
|
|
|
@ -124,13 +124,13 @@ bool boxLineCollision(const aabb3f &box, const v3f start,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool boxLineCollision(const aabb3f &box, const v3f rotation,
|
||||
const v3f start, const v3f dir,
|
||||
bool boxLineCollision(const aabb3f &box, v3f rotation_radians,
|
||||
v3f start, v3f dir,
|
||||
v3f *collision_point, v3f *collision_normal, v3f *raw_collision_normal)
|
||||
{
|
||||
// Inversely transform the ray rather than rotating the box faces;
|
||||
// this allows us to continue using a simple ray - AABB intersection
|
||||
core::quaternion rot(rotation * core::DEGTORAD);
|
||||
core::quaternion rot(rotation_radians);
|
||||
rot.makeInverse();
|
||||
|
||||
bool collision = boxLineCollision(box, rot * start, rot * dir, collision_point, collision_normal);
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
v3f res;
|
||||
// First rotate by m_rotation, then rotate by the automatic rotate yaw
|
||||
(core::quaternion(v3f(0, -m_rotation_add_yaw * core::DEGTORAD, 0))
|
||||
* core::quaternion(rot.getRotationDegrees() * core::DEGTORAD))
|
||||
* core::quaternion(rot.getRotationRadians()))
|
||||
.toEuler(res);
|
||||
return res * core::RADTODEG;
|
||||
}
|
||||
|
|
|
@ -84,20 +84,20 @@ SECTION("getScale") {
|
|||
}
|
||||
}
|
||||
|
||||
SECTION("getRotationDegrees") {
|
||||
auto test_rotation_degrees = [](v3f deg, v3f scale) {
|
||||
SECTION("getRotationRadians") {
|
||||
auto test_rotation_degrees = [](v3f rad, v3f scale) {
|
||||
matrix4 S;
|
||||
S.setScale(scale);
|
||||
matrix4 R;
|
||||
R.setRotationDegrees(deg);
|
||||
v3f rot = (R * S).getRotationDegrees();
|
||||
R.setRotationRadians(rad);
|
||||
v3f rot = (R * S).getRotationRadians();
|
||||
matrix4 B;
|
||||
B.setRotationDegrees(rot);
|
||||
B.setRotationRadians(rot);
|
||||
CHECK(matrix_equals(R, B));
|
||||
};
|
||||
SECTION("returns a rotation equivalent to the original rotation") {
|
||||
test_rotation_degrees({100, 200, 300}, v3f(1));
|
||||
Catch::Generators::RandomFloatingGenerator<f32> gen_angle(0, 360, Catch::getSeed());
|
||||
test_rotation_degrees({1.0f, 2.0f, 3.0f}, v3f(1));
|
||||
Catch::Generators::RandomFloatingGenerator<f32> gen_angle(0.0f, 2 * core::PI, Catch::getSeed());
|
||||
Catch::Generators::RandomFloatingGenerator<f32> gen_scale(0.1f, 10, Catch::getSeed());
|
||||
auto draw = [](auto gen) {
|
||||
f32 f = gen.get();
|
||||
|
@ -109,11 +109,12 @@ SECTION("getRotationDegrees") {
|
|||
};
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
test_rotation_degrees(draw_v3f(gen_angle), draw_v3f(gen_scale));
|
||||
for (f32 i = 0; i < 360; i += 90)
|
||||
for (f32 j = 0; j < 360; j += 90)
|
||||
for (f32 k = 0; k < 360; k += 90) {
|
||||
for (f32 i = 0; i < 4; ++i)
|
||||
for (f32 j = 0; j < 4; ++j)
|
||||
for (f32 k = 0; k < 4; ++k) {
|
||||
v3f rad = core::PI / 4.0f * v3f(i, j, k);
|
||||
for (int l = 0; l < 100; ++l) {
|
||||
test_rotation_degrees({i, j, k}, draw_v3f(gen_scale));
|
||||
test_rotation_degrees(rad, draw_v3f(gen_scale));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ SECTION("matrix-euler roundtrip") {
|
|||
test_euler_angles_rad([](v3f rad) {
|
||||
matrix4 mat, mat2;
|
||||
mat.setRotationRadians(rad);
|
||||
v3f rad2 = mat.getRotationDegrees() * core::DEGTORAD;
|
||||
v3f rad2 = mat.getRotationRadians();
|
||||
mat2.setRotationRadians(rad2);
|
||||
CHECK(matrix_equals(mat, mat2));
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue