Make util.rotateX, util.rotateY, rotate.Z consistent with morrowind rotation

fix-static-urls
Petr Mikheev 3 years ago
parent a37066c9f0
commit d5ca091d6e

@ -93,13 +93,13 @@ namespace
EXPECT_EQ(getAsString(lua, "moveAndScale * v(300, 200, 100)"), "(156, 222, 68)");
EXPECT_THAT(getAsString(lua, "moveAndScale"), AllOf(StartsWith("TransformM{ move(6, 22, 18) scale(0.5, 1, 0.5) "), EndsWith(" }")));
EXPECT_EQ(getAsString(lua, "T.identity"), "TransformM{ }");
lua.safe_script("rx = T.rotateX(math.pi / 2)");
lua.safe_script("ry = T.rotateY(math.pi / 2)");
lua.safe_script("rz = T.rotateZ(math.pi / 2)");
lua.safe_script("rx = T.rotateX(-math.pi / 2)");
lua.safe_script("ry = T.rotateY(-math.pi / 2)");
lua.safe_script("rz = T.rotateZ(-math.pi / 2)");
EXPECT_LT(get<float>(lua, "(rx * v(1, 2, 3) - v(1, -3, 2)):length()"), 1e-6);
EXPECT_LT(get<float>(lua, "(ry * v(1, 2, 3) - v(3, 2, -1)):length()"), 1e-6);
EXPECT_LT(get<float>(lua, "(rz * v(1, 2, 3) - v(-2, 1, 3)):length()"), 1e-6);
lua.safe_script("rot = T.rotate(math.pi / 2, v(-1, -1, 0)) * T.rotateZ(-math.pi / 4)");
lua.safe_script("rot = T.rotate(math.pi / 2, v(-1, -1, 0)) * T.rotateZ(math.pi / 4)");
EXPECT_THAT(getAsString(lua, "rot"), HasSubstr("TransformQ"));
EXPECT_LT(get<float>(lua, "(rot * v(1, 0, 0) - v(0, 0, 1)):length()"), 1e-6);
EXPECT_LT(get<float>(lua, "(rot * rot:inverse() * v(1, 0, 0) - v(1, 0, 0)):length()"), 1e-6);

@ -105,9 +105,9 @@ namespace LuaUtil
[](const Vec3& v) { return TransformM{osg::Matrixf::scale(v)}; },
[](float x, float y, float z) { return TransformM{osg::Matrixf::scale(x, y, z)}; });
transforms["rotate"] = [](float angle, const Vec3& axis) { return TransformQ{osg::Quat(angle, axis)}; };
transforms["rotateX"] = [](float angle) { return TransformQ{osg::Quat(angle, Vec3(1, 0, 0))}; };
transforms["rotateY"] = [](float angle) { return TransformQ{osg::Quat(angle, Vec3(0, 1, 0))}; };
transforms["rotateZ"] = [](float angle) { return TransformQ{osg::Quat(angle, Vec3(0, 0, 1))}; };
transforms["rotateX"] = [](float angle) { return TransformQ{osg::Quat(angle, Vec3(-1, 0, 0))}; };
transforms["rotateY"] = [](float angle) { return TransformQ{osg::Quat(angle, Vec3(0, -1, 0))}; };
transforms["rotateZ"] = [](float angle) { return TransformQ{osg::Quat(angle, Vec3(0, 0, -1))}; };
transMType[sol::meta_function::multiplication] = sol::overload(
[](const TransformM& a, const Vec3& b) { return a.mM.preMult(b); },

@ -32,7 +32,7 @@
-- v:length() -- 5.0 length
-- v:length2() -- 25.0 square of the length
-- v:normalize() -- vector2(3/5, 4/5)
-- v:rotate(radians) -- rotate clockwise (returns rotated vector)
-- v:rotate(radians) -- rotate counterclockwise (returns rotated vector)
-- v1:dot(v2) -- dot product (returns a number)
-- v1 * v2 -- dot product
-- v1 + v2 -- vector addition
@ -183,26 +183,26 @@
-------------------------------------------------------------------------------
-- Rotation (any axis).
-- Rotation around a vector (counterclockwise if the vector points to us).
-- @function [parent=#TRANSFORM] rotate
-- @param #number angle
-- @param #Vector3 axis.
-- @return #Transform.
-------------------------------------------------------------------------------
-- X-axis rotation.
-- X-axis rotation (equivalent to `rotate(angle, vector3(-1, 0, 0))`).
-- @function [parent=#TRANSFORM] rotateX
-- @param #number angle
-- @return #Transform.
-------------------------------------------------------------------------------
-- Y-axis rotation.
-- Y-axis rotation (equivalent to `rotate(angle, vector3(0, -1, 0))`).
-- @function [parent=#TRANSFORM] rotateY
-- @param #number angle
-- @return #Transform.
-------------------------------------------------------------------------------
-- Z-axis rotation.
-- Z-axis rotation (equivalent to `rotate(angle, vector3(0, 0, -1))`).
-- @function [parent=#TRANSFORM] rotateZ
-- @param #number angle
-- @return #Transform.

Loading…
Cancel
Save