diff --git a/irr/include/matrix4.h b/irr/include/matrix4.h index 374fc6e4a..edfecce60 100644 --- a/irr/include/matrix4.h +++ b/irr/include/matrix4.h @@ -24,7 +24,7 @@ namespace core { //! 4x4 matrix. Mostly used as transformation matrix for 3d calculations. -/** The matrix is a D3D style matrix, row major with translations in the 4th row. */ +/** The matrix is stored in column major order, with translations in the 4th row. */ template class CMatrix4 { @@ -242,17 +242,11 @@ class CMatrix4 //! Translate a vector by the inverse of the translation part of this matrix. void inverseTranslateVect(vector3df &vect) const; - //! Rotate a vector by the inverse of the rotation part of this matrix. - void inverseRotateVect(vector3df &vect) const; + //! Scale a vector, then rotate by the inverse of the rotation part of this matrix. + void scaleThenInvRotVect(vector3df &vect) const; - //! Rotate a vector by the rotation part of this matrix. - void rotateVect(vector3df &vect) const; - - //! An alternate transform vector method, writing into a second vector - void rotateVect(core::vector3df &out, const core::vector3df &in) const; - - //! An alternate transform vector method, writing into an array of 3 floats - void rotateVect(T *out, const core::vector3df &in) const; + //! Rotate and scale a vector. Applies both rotation & scale part of the matrix. + void rotateAndScaleVect(vector3df &vect) const; //! Transforms the vector by this matrix /** This operation is performed as if the vector was 4d with the 4th component =1 */ @@ -1154,7 +1148,7 @@ inline bool CMatrix4::isIdentity_integer_base() const } template -inline void CMatrix4::rotateVect(vector3df &vect) const +inline void CMatrix4::rotateAndScaleVect(vector3df &vect) const { vector3d tmp(static_cast(vect.X), static_cast(vect.Y), static_cast(vect.Z)); vect.X = static_cast(tmp.X * M[0] + tmp.Y * M[4] + tmp.Z * M[8]); @@ -1162,26 +1156,8 @@ inline void CMatrix4::rotateVect(vector3df &vect) const vect.Z = static_cast(tmp.X * M[2] + tmp.Y * M[6] + tmp.Z * M[10]); } -//! An alternate transform vector method, writing into a second vector template -inline void CMatrix4::rotateVect(core::vector3df &out, const core::vector3df &in) const -{ - out.X = in.X * M[0] + in.Y * M[4] + in.Z * M[8]; - out.Y = in.X * M[1] + in.Y * M[5] + in.Z * M[9]; - out.Z = in.X * M[2] + in.Y * M[6] + in.Z * M[10]; -} - -//! An alternate transform vector method, writing into an array of 3 floats -template -inline void CMatrix4::rotateVect(T *out, const core::vector3df &in) const -{ - out[0] = in.X * M[0] + in.Y * M[4] + in.Z * M[8]; - out[1] = in.X * M[1] + in.Y * M[5] + in.Z * M[9]; - out[2] = in.X * M[2] + in.Y * M[6] + in.Z * M[10]; -} - -template -inline void CMatrix4::inverseRotateVect(vector3df &vect) const +inline void CMatrix4::scaleThenInvRotVect(vector3df &vect) const { vector3d tmp(static_cast(vect.X), static_cast(vect.Y), static_cast(vect.Z)); vect.X = static_cast(tmp.X * M[0] + tmp.Y * M[1] + tmp.Z * M[2]); @@ -1248,7 +1224,7 @@ inline void CMatrix4::transformPlane(core::plane3d &plane) const // Transform the normal by the transposed inverse of the matrix CMatrix4 transposedInverse(*this, EM4CONST_INVERSE_TRANSPOSED); vector3df normal = plane.Normal; - transposedInverse.rotateVect(normal); + transposedInverse.rotateAndScaleVect(normal); plane.setPlane(member, normal.normalize()); } diff --git a/irr/src/CB3DMeshFileLoader.cpp b/irr/src/CB3DMeshFileLoader.cpp index 6ee24af0e..66ad64a6f 100644 --- a/irr/src/CB3DMeshFileLoader.cpp +++ b/irr/src/CB3DMeshFileLoader.cpp @@ -388,7 +388,7 @@ bool CB3DMeshFileLoader::readChunkVRTS(CSkinnedMesh::SJoint *inJoint) // Transform the Vertex position by nested node... inJoint->GlobalMatrix.transformVect(Vertex.Pos); - inJoint->GlobalMatrix.rotateVect(Vertex.Normal); + inJoint->GlobalMatrix.rotateAndScaleVect(Vertex.Normal); // Add it... BaseVertices.push_back(Vertex); diff --git a/irr/src/CGLTFMeshFileLoader.cpp b/irr/src/CGLTFMeshFileLoader.cpp index 537911e88..b57a93159 100644 --- a/irr/src/CGLTFMeshFileLoader.cpp +++ b/irr/src/CGLTFMeshFileLoader.cpp @@ -350,8 +350,7 @@ static void transformVertices(std::vector &vertices, const cor // Apply scaling, rotation and rotation (in that order) to the position. transform.transformVect(vertex.Pos); // For the normal, we do not want to apply the translation. - // TODO note that this also applies scaling; the Irrlicht method is misnamed. - transform.rotateVect(vertex.Normal); + transform.rotateAndScaleVect(vertex.Normal); // Renormalize (length might have been affected by scaling). vertex.Normal.normalize(); } diff --git a/irr/src/CSkinnedMesh.cpp b/irr/src/CSkinnedMesh.cpp index 11773ad41..5e1452601 100644 --- a/irr/src/CSkinnedMesh.cpp +++ b/irr/src/CSkinnedMesh.cpp @@ -511,7 +511,7 @@ void CSkinnedMesh::skinJoint(SJoint *joint, SJoint *parentJoint) jointVertexPull.transformVect(thisVertexMove, weight.StaticPos); if (AnimateNormals) - jointVertexPull.rotateVect(thisNormalMove, weight.StaticNormal); + jointVertexPull.rotateAndScaleVect(thisNormalMove = weight.StaticNormal); if (!(*(weight.Moved))) { *(weight.Moved) = true; diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 5e724d05e..a5ba42689 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -404,10 +404,10 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio) // Compute absolute camera position and target m_headnode->getAbsoluteTransformation().transformVect(m_camera_position, rel_cam_pos); - m_headnode->getAbsoluteTransformation().rotateVect(m_camera_direction, rel_cam_target - rel_cam_pos); + m_headnode->getAbsoluteTransformation().rotateAndScaleVect(m_camera_direction = rel_cam_target - rel_cam_pos); - v3f abs_cam_up; - m_headnode->getAbsoluteTransformation().rotateVect(abs_cam_up, rel_cam_up); + v3f abs_cam_up = rel_cam_up; + m_headnode->getAbsoluteTransformation().rotateAndScaleVect(abs_cam_up); // Separate camera position for calculation v3f my_cp = m_camera_position; diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index 45995c0ea..1ab2dcfc1 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -1004,7 +1004,7 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor, core::CMatrix4 a; a.buildRotateFromTo(v3f(0,1,0), z_dir); v3f dir = m_camera_direction; - a.rotateVect(dir); + a.rotateAndScaleVect(dir); int br = 0; float step = BS*1.5; if(max_d > 35*BS) diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 637a2f500..090b81111 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -512,7 +512,7 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) // Angle according to camera view v3f fore(0.f, 0.f, 1.f); scene::ICameraSceneNode *cam = client->getSceneManager()->getActiveCamera(); - cam->getAbsoluteTransformation().rotateVect(fore); + cam->getAbsoluteTransformation().rotateAndScaleVect(fore); int angle = - fore.getHorizontalAngle().Y; // Limit angle and ajust with given offset diff --git a/src/client/particles.cpp b/src/client/particles.cpp index c19282424..de5a47179 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -357,8 +357,8 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius, if (attached_absolute_pos_rot_matrix) { // Apply attachment rotation - attached_absolute_pos_rot_matrix->rotateVect(pp.vel); - attached_absolute_pos_rot_matrix->rotateVect(pp.acc); + attached_absolute_pos_rot_matrix->rotateAndScaleVect(pp.vel); + attached_absolute_pos_rot_matrix->rotateAndScaleVect(pp.acc); } if (attractor_obj) @@ -366,7 +366,7 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius, if (attractor_direction_obj) { auto *attractor_absolute_pos_rot_matrix = attractor_direction_obj->getAbsolutePosRotMatrix(); if (attractor_absolute_pos_rot_matrix) - attractor_absolute_pos_rot_matrix->rotateVect(attractor_direction); + attractor_absolute_pos_rot_matrix->rotateAndScaleVect(attractor_direction); } pp.expirationtime = r_exp.pickWithin(); diff --git a/src/client/shadows/dynamicshadows.cpp b/src/client/shadows/dynamicshadows.cpp index 11db9bea7..b2a71863f 100644 --- a/src/client/shadows/dynamicshadows.cpp +++ b/src/client/shadows/dynamicshadows.cpp @@ -137,7 +137,7 @@ void DirectionalLight::update_frustum(const Camera *cam, Client *client, bool fo v3s16 cam_offset = cam->getOffset(); if (cam_offset != shadow_frustum.camera_offset) { v3f rotated_offset; - shadow_frustum.ViewMat.rotateVect(rotated_offset, intToFloat(cam_offset - shadow_frustum.camera_offset, BS)); + shadow_frustum.ViewMat.rotateAndScaleVect(rotated_offset = intToFloat(cam_offset - shadow_frustum.camera_offset, BS)); shadow_frustum.ViewMat.setTranslation(shadow_frustum.ViewMat.getTranslation() + rotated_offset); shadow_frustum.player += intToFloat(shadow_frustum.camera_offset - cam->getOffset(), BS); shadow_frustum.camera_offset = cam_offset; diff --git a/src/client/sky.cpp b/src/client/sky.cpp index 92e5df218..ec77c15aa 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -848,10 +848,10 @@ void Sky::updateStars() v3f p1 = v3f(d, 1, -d); v3f p2 = v3f(d, 1, d); v3f p3 = v3f(-d, 1, d); - a.rotateVect(p); - a.rotateVect(p1); - a.rotateVect(p2); - a.rotateVect(p3); + a.rotateAndScaleVect(p); + a.rotateAndScaleVect(p1); + a.rotateAndScaleVect(p2); + a.rotateAndScaleVect(p3); m_stars->Vertices.push_back(video::S3DVertex(p, {}, fallback_color, {})); m_stars->Vertices.push_back(video::S3DVertex(p1, {}, fallback_color, {})); m_stars->Vertices.push_back(video::S3DVertex(p2, {}, fallback_color, {})); diff --git a/src/gui/guiScene.cpp b/src/gui/guiScene.cpp index 239fbe015..451af3aed 100644 --- a/src/gui/guiScene.cpp +++ b/src/gui/guiScene.cpp @@ -226,7 +226,7 @@ void GUIScene::setCameraRotation(v3f rot) mat.setRotationDegrees(rot); m_cam_pos = v3f(0.f, 0.f, m_cam_distance); - mat.rotateVect(m_cam_pos); + mat.rotateAndScaleVect(m_cam_pos); m_cam_pos += m_target_pos; m_cam->setPosition(m_cam_pos);