From 8aab2c2a0afa9a9aecc5a76f1d5a2846180c158a Mon Sep 17 00:00:00 2001 From: LHoG <1476261+lhog@users.noreply.github.com> Date: Mon, 16 Dec 2024 01:05:32 +0100 Subject: [PATCH] First fugly version with GL4 quaternion shader --- .../shaders/GLSL/ModelVertProgGL4.glsl | 73 ++++++++++++++----- rts/Lua/LuaOpenGL.cpp | 2 +- rts/Lua/LuaSyncedRead.cpp | 2 +- rts/Rendering/Common/ModelDrawerData.h | 6 +- rts/Rendering/DebugColVolDrawer.cpp | 2 +- rts/Rendering/Models/3DModel.cpp | 16 ++-- rts/Rendering/Models/3DModel.h | 5 +- rts/Rendering/Models/ModelsMemStorage.h | 7 +- rts/Rendering/ModelsDataUploader.h | 4 +- rts/Sim/Features/Feature.h | 2 +- rts/Sim/Misc/CollisionHandler.cpp | 2 +- rts/Sim/Misc/CollisionVolume.cpp | 2 +- rts/Sim/Objects/SolidObject.h | 2 +- rts/Sim/Units/Scripts/UnitScript.cpp | 2 +- rts/Sim/Units/Scripts/UnitScript.h | 4 +- rts/Sim/Units/Unit.cpp | 2 +- rts/Sim/Units/Unit.h | 2 +- rts/Sim/Units/UnitTypes/Factory.cpp | 5 +- rts/Sim/Weapons/BeamLaser.cpp | 2 +- rts/System/Transform.cpp | 10 +++ rts/System/Transform.hpp | 2 + 21 files changed, 101 insertions(+), 53 deletions(-) diff --git a/cont/base/springcontent/shaders/GLSL/ModelVertProgGL4.glsl b/cont/base/springcontent/shaders/GLSL/ModelVertProgGL4.glsl index f3212610ef..defd8fa89f 100644 --- a/cont/base/springcontent/shaders/GLSL/ModelVertProgGL4.glsl +++ b/cont/base/springcontent/shaders/GLSL/ModelVertProgGL4.glsl @@ -83,8 +83,13 @@ layout(std140, binding = 1) uniform UniformParamsBuffer { vec4 teamColor[255]; //all team colors }; -layout(std140, binding = 0) readonly buffer MatrixBuffer { - mat4 mat[]; +struct Transform { + vec4 quat; + vec4 trSc; +}; + +layout(std140, binding = 0) readonly buffer TransformBuffer { + Transform transforms[]; }; uniform int cameraMode = 0; @@ -114,7 +119,7 @@ out Data { }; out float gl_ClipDistance[3]; -#line 1117 +#line 1122 void TransformPlayerCam(vec4 worldPos) { gl_Position = cameraViewProj * worldPos; @@ -132,6 +137,37 @@ uint GetUnpackedValue(uint packedValue, uint byteNum) { return (packedValue >> (8u * byteNum)) & 0xFFu; } +vec4 MultiplyQuat(vec4 a, vec4 b) +{ + return vec4(a.w * b.w - dot(a.w, b.w), a.w * b.xyz + b.w * a.xyz + cross(a.xyz, b.xyz)); +} + +vec3 RotateByQuaternion(vec4 q, vec3 v) { + return 2.0f * dot(q.xyz, v) * q.xyz + (q.w * q.w - dot(q.xyz, q.xyz)) * v + 2.0 * q.w * cross(q.xyz, v); +} + +vec4 RotateByQuaternion(vec4 q, vec4 v) { + return vec4(RotateByQuaternion(q, v.xyz), v.w); +} + +vec3 ApplyTransform(Transform tra, vec3 v) { + return RotateByQuaternion(tra.quat, v * tra.trSc.w) + tra.trSc.xyz; +} + +vec4 ApplyTransform(Transform tra, vec4 v) { + return vec4(ApplyTransform(tra, v.xyz), v.w); +} + +Transform ApplyTransform(Transform parentTra, Transform childTra) { + return Transform( + MultiplyQuat(parentTra.quat, childTra.quat), + vec4( + parentTra.trSc.xyz + RotateByQuaternion(parentTra.quat, parentTra.trSc.w * childTra.trSc.xyz), + parentTra.trSc.w * childTra.trSc.w + ) + ); +} + void GetModelSpaceVertex(out vec4 msPosition, out vec3 msNormal) { bool staticModel = (matrixMode > 0); @@ -146,13 +182,12 @@ void GetModelSpaceVertex(out vec4 msPosition, out vec3 msNormal) ); uint b0 = GetUnpackedValue(bonesInfo.x, 0); //first boneID - mat4 b0BoneMat = mat[instData.x + b0 + uint(!staticModel)]; - mat3 b0NormMat = mat3(b0BoneMat); + Transform b0BoneTra = transforms[instData.x + b0 + uint(!staticModel)]; - weights[0] *= b0BoneMat[3][3]; + weights[0] *= step(0.0, b0BoneTra.trSc.w); - msPosition = b0BoneMat * piecePos; - msNormal = b0NormMat * normal; + msPosition = ApplyTransform(b0BoneTra, piecePos); + msNormal = RotateByQuaternion(b0BoneTra.quat, normal); if (staticModel || weights[0] == 1.0) return; @@ -164,7 +199,7 @@ void GetModelSpaceVertex(out vec4 msPosition, out vec3 msNormal) wSum += weights[0]; uint numPieces = GetUnpackedValue(instData.z, 3); - mat4 bposeMat = mat[instData.w + b0]; + Transform bposeTra = transforms[instData.w + b0]; // Vertex[ModelSpace,BoneX] = PieceMat[BoneX] * InverseBindPosMat[BoneX] * BindPosMat[Bone0] * Vertex[Bone0] for (uint bi = 1; bi < 3; ++bi) { @@ -173,16 +208,15 @@ void GetModelSpaceVertex(out vec4 msPosition, out vec3 msNormal) if (bID == 0xFFu || weights[bi] == 0.0) continue; - mat4 bposeInvMat = mat[instData.w + numPieces + bID]; - mat4 boneMat = mat[instData.x + 1u + bID]; + Transform bposeInvTra = transforms[instData.w + numPieces + bID]; + Transform boneTra = transforms[instData.x + 1u + bID]; - weights[bi] *= boneMat[3][3]; + weights[bi] *= step(0.0, boneTra.trSc.w); - mat4 skinMat = boneMat * bposeInvMat * bposeMat; - mat3 normMat = mat3(skinMat); + Transform skinTra = ApplyTransform(ApplyTransform(boneTra, bposeInvTra), bposeTra); - msPosition += skinMat * piecePos * weights[bi]; - msNormal += normMat * normal * weights[bi]; + msPosition += ApplyTransform(skinTra, piecePos * weights[bi]); + msNormal += RotateByQuaternion(skinTra.quat, normal * weights[bi]); wSum += weights[bi]; } @@ -194,14 +228,15 @@ void main(void) { bool staticModel = (matrixMode > 0); - mat4 worldMatrix = staticModel ? staticModelMatrix : mat[instData.x]; //don't cover ARRAY_MATMODE yet + //mat4 worldMatrix = staticModel ? staticModelMatrix : mat[instData.x]; //don't cover ARRAY_MATMODE yet + Transform worldTra = transforms[instData.x]; //don't cover ARRAY_MATMODE yet vec4 modelPos; vec3 modelNormal; GetModelSpaceVertex(modelPos, modelNormal); - worldPos = worldMatrix * modelPos; - worldNormal = mat3(worldMatrix) * modelNormal; + worldPos = ApplyTransform(worldTra, modelPos); + worldNormal = RotateByQuaternion(worldTra.quat, modelNormal); gl_ClipDistance[0] = dot(modelPos, clipPlane0); //upper construction clip plane gl_ClipDistance[1] = dot(modelPos, clipPlane1); //lower construction clip plane diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index b5dd9c979c..154b0b5722 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -1423,7 +1423,7 @@ static void GLObjectPieceMultMatrix(lua_State* L, const CSolidObject* obj) if (lmp == nullptr) return; - glMultMatrixf(lmp->GetModelSpaceMatrix()); + glMultMatrixf(lmp->GetModelSpaceTransform().ToMatrix()); } static bool GLObjectDrawWithLuaMat(lua_State* L, CSolidObject* obj, LuaObjType objType) diff --git a/rts/Lua/LuaSyncedRead.cpp b/rts/Lua/LuaSyncedRead.cpp index d6164188d6..0ca480c826 100644 --- a/rts/Lua/LuaSyncedRead.cpp +++ b/rts/Lua/LuaSyncedRead.cpp @@ -8245,7 +8245,7 @@ static int GetSolidObjectPieceMatrix(lua_State* L, const CSolidObject* o) if (lmp == nullptr) return 0; - const CMatrix44f& mat = lmp->GetModelSpaceMatrix(); + const CMatrix44f& mat = lmp->GetModelSpaceTransform().ToMatrix(); for (float mi: mat.m) { lua_pushnumber(L, mi); diff --git a/rts/Rendering/Common/ModelDrawerData.h b/rts/Rendering/Common/ModelDrawerData.h index 75dd3a43a0..59b4eb7758 100644 --- a/rts/Rendering/Common/ModelDrawerData.h +++ b/rts/Rendering/Common/ModelDrawerData.h @@ -159,7 +159,7 @@ inline void CModelDrawerDataBase::UpdateObjectSMMA(const T* o) { ScopedTransformMemAlloc& smma = GetObjectTransformMemAlloc(o); - const auto tmNew = o->GetTransformMatrix(); + const auto tmNew = Transform::FromMatrix(o->GetTransformMatrix()); // from one point it doesn't worth the comparison, cause units usually move // but having not updated smma[0] allows for longer solid no-update areas in ModelUniformsUploader::UpdateDerived() @@ -174,12 +174,12 @@ inline void CModelDrawerDataBase::UpdateObjectSMMA(const T* o) if unlikely(!lmp.GetScriptVisible()) { //smma[i + 1] = CMatrix44f::Zero(); - smma.UpdateForced(i + 1, CMatrix44f::Zero()); + smma.UpdateForced(i + 1, Transform::Zero()); continue; } // UpdateIfChanged is not needed, wasCustomDirty takes that role - smma.UpdateForced(i + 1, lmp.GetModelSpaceMatrix()); + smma.UpdateForced(i + 1, lmp.GetModelSpaceTransform()); } } diff --git a/rts/Rendering/DebugColVolDrawer.cpp b/rts/Rendering/DebugColVolDrawer.cpp index b4d62529b1..e15da0b5e2 100644 --- a/rts/Rendering/DebugColVolDrawer.cpp +++ b/rts/Rendering/DebugColVolDrawer.cpp @@ -96,7 +96,7 @@ static void DrawObjectDebugPieces(const CSolidObject* o, const float4& defColor) float4{ (1.0f - (hitDeltaTime / 150.0f)), 0.0f, 0.0f, 1.0f } : defColor; - const CMatrix44f mp = mo * lmp->GetModelSpaceMatrix(); + const CMatrix44f mp = mo * lmp->GetModelSpaceTransform().ToMatrix(); // factors in the volume offsets DrawCollisionVolume(lmpVol, mp, curColor); } diff --git a/rts/Rendering/Models/3DModel.cpp b/rts/Rendering/Models/3DModel.cpp index ca6499ddb2..f076cdb2c6 100644 --- a/rts/Rendering/Models/3DModel.cpp +++ b/rts/Rendering/Models/3DModel.cpp @@ -461,7 +461,7 @@ void LocalModel::UpdateBoundingVolume() float3 bbMaxs = DEF_MAX_SIZE; for (const auto& lmPiece: pieces) { - const CMatrix44f& matrix = lmPiece.GetModelSpaceMatrix(); + const auto& tra = lmPiece.GetModelSpaceTransform(); const S3DModelPiece* piece = lmPiece.original; // skip empty pieces or bounds will not be sensible @@ -485,7 +485,7 @@ void LocalModel::UpdateBoundingVolume() }; for (const float3& v: verts) { - const float3 vertex = matrix * v; + const float3 vertex = tra * v; bbMins = float3::min(bbMins, vertex); bbMaxs = float3::max(bbMaxs, vertex); @@ -662,7 +662,7 @@ void LocalModelPiece::Draw() const assert(original); glPushMatrix(); - glMultMatrixf(GetModelSpaceMatrix()); + glMultMatrixf(GetModelSpaceTransform().ToMatrix()); S3DModelHelpers::BindLegacyAttrVBOs(); original->DrawElements(); S3DModelHelpers::UnbindLegacyAttrVBOs(); @@ -679,7 +679,7 @@ void LocalModelPiece::DrawLOD(uint32_t lod) const return; glPushMatrix(); - glMultMatrixf(GetModelSpaceMatrix()); + glMultMatrixf(GetModelSpaceTransform().ToMatrix()); if (const auto ldl = lodDispLists[lod]; ldl == 0) { S3DModelHelpers::BindLegacyAttrVBOs(); original->DrawElements(); @@ -711,8 +711,8 @@ bool LocalModelPiece::GetEmitDirPos(float3& emitPos, float3& emitDir) const return false; // note: actually OBJECT_TO_WORLD but transform is the same - emitPos = GetModelSpaceMatrix() * original->GetEmitPos() * WORLD_TO_OBJECT_SPACE; - emitDir = GetModelSpaceMatrix() * float4(original->GetEmitDir(), 0.0f) * WORLD_TO_OBJECT_SPACE; + emitPos = GetModelSpaceTransform() * original->GetEmitPos() * WORLD_TO_OBJECT_SPACE; + emitDir = GetModelSpaceTransform() * float4(original->GetEmitDir(), 0.0f) * WORLD_TO_OBJECT_SPACE; return true; } @@ -764,7 +764,7 @@ void S3DModel::SetPieceMatrices() for (size_t i = 0; i < pieceObjects.size(); ++i) { const auto* po = pieceObjects[i]; //traAlloc[0 + i] = po->bposeTransform.ToMatrix(); - traAlloc.UpdateForced((0 + i), po->bposeTransform.ToMatrix()); + traAlloc.UpdateForced((0 + i), po->bposeTransform); } // use this occasion and copy inverse bpose matrices @@ -772,6 +772,6 @@ void S3DModel::SetPieceMatrices() for (size_t i = 0; i < pieceObjects.size(); ++i) { const auto* po = pieceObjects[i]; //traAlloc[numPieces + i] = po->bposeInvTransform.ToMatrix(); - traAlloc.UpdateForced((numPieces + i), po->bposeInvTransform.ToMatrix()); + traAlloc.UpdateForced((numPieces + i), po->bposeInvTransform); } } diff --git a/rts/Rendering/Models/3DModel.h b/rts/Rendering/Models/3DModel.h index 1c8005de3c..5172ef48e2 100644 --- a/rts/Rendering/Models/3DModel.h +++ b/rts/Rendering/Models/3DModel.h @@ -443,7 +443,7 @@ struct LocalModelPiece } // note: actually OBJECT_TO_WORLD but transform is the same - float3 GetAbsolutePos() const { return (GetModelSpaceMatrix().GetPos() * WORLD_TO_OBJECT_SPACE); } + float3 GetAbsolutePos() const { return (GetModelSpaceTransform().t * WORLD_TO_OBJECT_SPACE); } bool GetEmitDirPos(float3& emitPos, float3& emitDir) const; @@ -476,7 +476,7 @@ struct LocalModelPiece const float3& GetDirection() const { return dir; } - CMatrix44f GetModelSpaceMatrix() const { if (dirty) UpdateParentMatricesRec(); return modelSpaceTra.ToMatrix(); } + Transform GetModelSpaceTransform() const { if (dirty) UpdateParentMatricesRec(); return modelSpaceTra; } const CollisionVolume* GetCollisionVolume() const { return &colvol; } CollisionVolume* GetCollisionVolume() { return &colvol; } @@ -538,7 +538,6 @@ struct LocalModel // raw forms, the piece-index must be valid const float3 GetRawPiecePos(int pieceIdx) const { return pieces[pieceIdx].GetAbsolutePos(); } - const CMatrix44f GetRawPieceMatrix(int pieceIdx) const { return pieces[pieceIdx].GetModelSpaceMatrix(); } // used by all SolidObject's; accounts for piece movement float GetDrawRadius() const { return (boundingVolume.GetBoundingRadius()); } diff --git a/rts/Rendering/Models/ModelsMemStorage.h b/rts/Rendering/Models/ModelsMemStorage.h index aef593bff0..1061913654 100644 --- a/rts/Rendering/Models/ModelsMemStorage.h +++ b/rts/Rendering/Models/ModelsMemStorage.h @@ -5,10 +5,11 @@ #include "ModelsMemStorageDefs.h" #include "ModelsLock.h" -#include "System/Matrix44f.h" +#include "System/Transform.hpp" #include "System/MemPoolTypes.h" #include "System/FreeListMap.h" #include "System/UnorderedMap.hpp" +#include "System/TypeToStr.h" #include "System/Threading/SpringThreading.h" #include "Sim/Misc/GlobalConstants.h" #include "Sim/Objects/SolidObjectDef.h" @@ -16,7 +17,7 @@ class TransformsMemStorage { public: - using MyType = CMatrix44f; + using MyType = Transform; using EqualCmpFunctor = bool(*)(const MyType&, const MyType&); public: explicit TransformsMemStorage(); @@ -93,7 +94,7 @@ class ScopedTransformMemAlloc { if (firstElem == TransformsMemStorage::INVALID_INDEX) return; - transformsMemStorage.Free(firstElem, numElems, &CMatrix44f::Zero()); + transformsMemStorage.Free(firstElem, numElems, &Transform::Zero()); } bool Valid() const { return firstElem != TransformsMemStorage::INVALID_INDEX; } diff --git a/rts/Rendering/ModelsDataUploader.h b/rts/Rendering/ModelsDataUploader.h index 66616e1f9e..fa9b53526f 100644 --- a/rts/Rendering/ModelsDataUploader.h +++ b/rts/Rendering/ModelsDataUploader.h @@ -5,7 +5,7 @@ #include #include -#include "System/Matrix44f.h" +#include "System/Transform.hpp" #include "System/TypeToStr.h" #include "Rendering/GL/StreamBuffer.h" #include "Rendering/Models/ModelsMemStorageDefs.h" @@ -21,7 +21,7 @@ struct S3DModel; class TransformsUploader { public: using MyClassName = TransformsUploader; - using MyDataType = CMatrix44f; + using MyDataType = Transform; public: void Init(); void Kill(); diff --git a/rts/Sim/Features/Feature.h b/rts/Sim/Features/Feature.h index 8e49ce5144..2d5912c0d4 100644 --- a/rts/Sim/Features/Feature.h +++ b/rts/Sim/Features/Feature.h @@ -97,7 +97,7 @@ class CFeature: public CSolidObject, public spring::noncopyable // NOTE: // unlike CUnit which recalculates the matrix on each call // (and uses the synced and error args) CFeature caches it - CMatrix44f GetTransformMatrix(bool synced = false, bool fullread = false) const final { return transMatrix[synced]; } + CMatrix44f GetTransformMatrix(bool synced = false, bool fullread = false) const override final { return transMatrix[synced]; } const CMatrix44f& GetTransformMatrixRef(bool synced = false) const { return transMatrix[synced]; } private: diff --git a/rts/Sim/Misc/CollisionHandler.cpp b/rts/Sim/Misc/CollisionHandler.cpp index fa36406a0c..020121e7e1 100644 --- a/rts/Sim/Misc/CollisionHandler.cpp +++ b/rts/Sim/Misc/CollisionHandler.cpp @@ -279,7 +279,7 @@ bool CCollisionHandler::IntersectPiecesHelper( if (!lmp->GetScriptVisible() || lmpVol->IgnoreHits()) continue; - volMat = m * lmp->GetModelSpaceMatrix(); + volMat = m * lmp->GetModelSpaceTransform().ToMatrix(); volMat.Translate(lmpVol->GetOffsets()); CollisionQuery cqn; diff --git a/rts/Sim/Misc/CollisionVolume.cpp b/rts/Sim/Misc/CollisionVolume.cpp index 491a262e6e..9ff48e0842 100644 --- a/rts/Sim/Misc/CollisionVolume.cpp +++ b/rts/Sim/Misc/CollisionVolume.cpp @@ -262,7 +262,7 @@ float CollisionVolume::GetPointSurfaceDistance( assert(this == lmp->GetCollisionVolume()); // transform into piece-space relative to pos - vm <<= lmp->GetModelSpaceMatrix(); + vm <<= lmp->GetModelSpaceTransform().ToMatrix(); } else { // SObj::GetTransformMatrix does not include this // (its translation component is pos, not midPos) diff --git a/rts/Sim/Objects/SolidObject.h b/rts/Sim/Objects/SolidObject.h index fab123caac..f06691d7d9 100644 --- a/rts/Sim/Objects/SolidObject.h +++ b/rts/Sim/Objects/SolidObject.h @@ -190,7 +190,7 @@ class CSolidObject: public CWorldObject { void UpdateDirVectors(const float3& uDir); CMatrix44f ComposeMatrix(const float3& p) const { return (CMatrix44f(p, -rightdir, updir, frontdir)); } - virtual CMatrix44f GetTransformMatrix(bool synced = false, bool fullread = false) const { return CMatrix44f(); }; + virtual CMatrix44f GetTransformMatrix(bool synced = false, bool fullread = false) const = 0; const CollisionVolume* GetCollisionVolume(const LocalModelPiece* lmp) const { if (lmp == nullptr) diff --git a/rts/Sim/Units/Scripts/UnitScript.cpp b/rts/Sim/Units/Scripts/UnitScript.cpp index dc4bc44fec..eea0913505 100644 --- a/rts/Sim/Units/Scripts/UnitScript.cpp +++ b/rts/Sim/Units/Scripts/UnitScript.cpp @@ -880,7 +880,7 @@ void CUnitScript::Shatter(int piece, const float3& pos, const float3& speed) const float pieceChance = 1.0f - (projectileHandler.GetCurrentParticles() - (projectileHandler.maxParticles - 2000)) / 2000.0f; if (pieceChance > 0.0f) { - const CMatrix44f m = unit->GetTransformMatrix() * lmp->GetModelSpaceMatrix(); + const CMatrix44f m = unit->GetTransformMatrix() * lmp->GetModelSpaceTransform().ToMatrix(); omp->Shatter(pieceChance, unit->model->type, unit->model->textureType, unit->team, pos, speed, m); } } diff --git a/rts/Sim/Units/Scripts/UnitScript.h b/rts/Sim/Units/Scripts/UnitScript.h index 8579a71a44..8a983a6065 100644 --- a/rts/Sim/Units/Scripts/UnitScript.h +++ b/rts/Sim/Units/Scripts/UnitScript.h @@ -92,8 +92,8 @@ class CUnitScript return (p->PieceFunc()); \ } - SCRIPT_TO_LOCALPIECE_FUNC( float3, GetPiecePos, GetAbsolutePos ) - SCRIPT_TO_LOCALPIECE_FUNC(CMatrix44f, GetPieceMatrix, GetModelSpaceMatrix) + SCRIPT_TO_LOCALPIECE_FUNC( float3, GetPiecePos , GetAbsolutePos ) + SCRIPT_TO_LOCALPIECE_FUNC(Transform, GetPieceTransform, GetModelSpaceTransform) bool GetEmitDirPos(int scriptPieceNum, float3& pos, float3& dir) const { if (!PieceExists(scriptPieceNum)) diff --git a/rts/Sim/Units/Unit.cpp b/rts/Sim/Units/Unit.cpp index 9f1ec62fbd..eecfd05c98 100644 --- a/rts/Sim/Units/Unit.cpp +++ b/rts/Sim/Units/Unit.cpp @@ -731,7 +731,7 @@ void CUnit::UpdateTransportees() // slave transportee orientation to piece if (tu.piece >= 0) { const CMatrix44f& transMat = GetTransformMatrix(true); - const CMatrix44f& pieceMat = script->GetPieceMatrix(tu.piece); + const auto pieceMat = script->GetPieceTransform(tu.piece).ToMatrix(); transportee->SetDirVectors(transMat * pieceMat); } diff --git a/rts/Sim/Units/Unit.h b/rts/Sim/Units/Unit.h index fe4af49685..15051b9a38 100644 --- a/rts/Sim/Units/Unit.h +++ b/rts/Sim/Units/Unit.h @@ -112,7 +112,7 @@ class CUnit : public CSolidObject void EnableScriptMoveType(); void DisableScriptMoveType(); - CMatrix44f GetTransformMatrix(bool synced = false, bool fullread = false) const final; + CMatrix44f GetTransformMatrix(bool synced = false, bool fullread = false) const override final; void DependentDied(CObject* o); diff --git a/rts/Sim/Units/UnitTypes/Factory.cpp b/rts/Sim/Units/UnitTypes/Factory.cpp index f5012fc967..80796a285c 100644 --- a/rts/Sim/Units/UnitTypes/Factory.cpp +++ b/rts/Sim/Units/UnitTypes/Factory.cpp @@ -219,11 +219,12 @@ void CFactory::UpdateBuild(CUnit* buildee) { const int buildPiece = script->QueryBuildInfo(); const float3& buildPos = CalcBuildPos(buildPiece); - const CMatrix44f& buildPieceMat = script->GetPieceMatrix(buildPiece); + const auto& buildPieceTra = script->GetPieceTransform(buildPiece); // see CMatrix44f::CMatrix44f(const float3 pos, const float3 x, const float3 y, const float3 z) // frontdir.x, frontdir.z - const int buildPieceHeading = GetHeadingFromVector(buildPieceMat[8], buildPieceMat[10]); + const float3 xzVec = buildPieceTra * float3{ math::HALFSQRT2, 0.0f, math::HALFSQRT2 }; + const int buildPieceHeading = GetHeadingFromVector(xzVec.x, xzVec.z); const int buildFaceHeading = GetHeadingFromFacing(buildFacing); float3 buildeePos = buildPos; diff --git a/rts/Sim/Weapons/BeamLaser.cpp b/rts/Sim/Weapons/BeamLaser.cpp index 238d3e8846..ef621d8591 100644 --- a/rts/Sim/Weapons/BeamLaser.cpp +++ b/rts/Sim/Weapons/BeamLaser.cpp @@ -120,7 +120,7 @@ void CBeamLaser::UpdatePosAndMuzzlePos() RECOIL_DETAILED_TRACY_ZONE; if (sweepFireState.IsSweepFiring()) { const int weaponPiece = owner->script->QueryWeapon(weaponNum); - const CMatrix44f weaponMat = owner->script->GetPieceMatrix(weaponPiece); + const auto weaponMat = owner->script->GetPieceTransform(weaponPiece).ToMatrix(); const float3 relWeaponPos = weaponMat.GetPos(); const float3 newWeaponDir = owner->GetObjectSpaceVec(float3(weaponMat[2], weaponMat[6], weaponMat[10])); diff --git a/rts/System/Transform.cpp b/rts/System/Transform.cpp index b0bfe92d15..b42a199ae0 100644 --- a/rts/System/Transform.cpp +++ b/rts/System/Transform.cpp @@ -14,6 +14,16 @@ CR_REG_METADATA(Transform, ( static_assert(sizeof (Transform) == 2 * 4 * sizeof(float)); static_assert(alignof(Transform) == alignof(decltype(Transform::r))); +const Transform& Transform::Zero() +{ + static const Transform zero{ + CQuaternion{ 0, 0, 0, 0 }, + float3{ 0, 0, 0 }, + 0 + }; + return zero; +} + void Transform::SetScaleSign(float signSrc) { s = std::copysignf(s, signSrc); diff --git a/rts/System/Transform.hpp b/rts/System/Transform.hpp index 955fdbb430..81fda8ad04 100644 --- a/rts/System/Transform.hpp +++ b/rts/System/Transform.hpp @@ -31,6 +31,8 @@ struct Transform { s = 1.0f; } + static const Transform& Zero(); + // can be used to enable/disable rendering void SetScaleSign(float signSrc);