git.s-ol.nu ~forks/DiligentCore / a364a1a
Added Scale and Rotation for Matrix3x3 azhirnov 10 months ago
2 changed file(s) with 71 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
7676 {
7777 VERIFY_EXPR(Idx < NUM_PLANES);
7878 const Plane3D* Planes = reinterpret_cast<const Plane3D*>(this);
79 return Planes[static_cast<size_t>(Idx)];
80 }
81
82 Plane3D& GetPlane(PLANE_IDX Idx)
83 {
84 VERIFY_EXPR(Idx < NUM_PLANES);
85 Plane3D* Planes = reinterpret_cast<Plane3D*>(this);
7986 return Planes[static_cast<size_t>(Idx)];
8087 }
8188 };
971971 1, 0, 0,
972972 0, 1, 0,
973973 0, 0, 1 //
974 };
975 }
976
977 static Matrix3x3 Scale(T x, T y, T z)
978 {
979 return Matrix3x3 //
980 {
981 x,
982 0,
983 0,
984 0,
985 y,
986 0,
987 0,
988 0,
989 z,
990 };
991 }
992
993 // D3D-style left-handed matrix that rotates a point around the x axis. Angle (in radians)
994 // is measured clockwise when looking along the rotation axis toward the origin:
995 // (x' y' z') = (x y z) * RotationX
996 static Matrix3x3 RotationX(T angleInRadians)
997 {
998 auto s = std::sin(angleInRadians);
999 auto c = std::cos(angleInRadians);
1000
1001 return Matrix3x3 // clang-format off
1002 {
1003 1, 0, 0,
1004 0, c, s,
1005 0, -s, c // clang-format on
1006 };
1007 }
1008
1009 // D3D-style left-handed matrix that rotates a point around the y axis. Angle (in radians)
1010 // is measured clockwise when looking along the rotation axis toward the origin:
1011 // (x' y' z' 1) = (x y z 1) * RotationY
1012 static Matrix3x3 RotationY(T angleInRadians)
1013 {
1014 auto s = std::sin(angleInRadians);
1015 auto c = std::cos(angleInRadians);
1016
1017 return Matrix3x3 // clang-format off
1018 {
1019 c, 0, -s,
1020 0, 1, 0,
1021 s, 0, c // clang-format on
1022 };
1023 }
1024
1025 // D3D-style left-handed matrix that rotates a point around the z axis. Angle (in radians)
1026 // is measured clockwise when looking along the rotation axis toward the origin:
1027 // (x' y' z' 1) = (x y z 1) * RotationZ
1028 static Matrix3x3 RotationZ(T angleInRadians)
1029 {
1030 auto s = std::sin(angleInRadians);
1031 auto c = std::cos(angleInRadians);
1032
1033 return Matrix3x3 // clang-format off
1034 {
1035 c, s, 0,
1036 -s, c, 0,
1037 0, 0, 1 // clang-format on
9741038 };
9751039 }
9761040