From 8b1e02759a771fb2f3556479e984072940138874 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 21 Jun 2022 22:35:20 -0400 Subject: [PATCH] Fixed transports. --- Source/Framework/GameMath/Box.cs | 2 +- Source/Framework/Util/MathFunctions.cs | 2 +- .../Game/Collision/Models/GameObjectModel.cs | 22 +++++++++---------- Source/Game/Collision/Models/ModelInstance.cs | 18 +++++++-------- Source/Game/Entities/GameObject/GameObject.cs | 2 +- Source/Game/Maps/TransportManager.cs | 10 +++++---- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Source/Framework/GameMath/Box.cs b/Source/Framework/GameMath/Box.cs index 82209bc96..6315f747c 100644 --- a/Source/Framework/GameMath/Box.cs +++ b/Source/Framework/GameMath/Box.cs @@ -72,7 +72,7 @@ namespace Framework.GameMath // M^-1 * (point - _corner[0]) = point in unit cube's object space // compute the inverse of M Matrix4x4.Invert(M, out M); - Vector3 osPoint = Vector3.Transform(point - Corner(0), M); + Vector3 osPoint = Vector3.TransformNormal(point - Corner(0), M); return (osPoint.X >= 0) && (osPoint.Y >= 0) && (osPoint.Z >= 0) && (osPoint.X <= 1) && (osPoint.Y <= 1) && (osPoint.Z <= 1); diff --git a/Source/Framework/Util/MathFunctions.cs b/Source/Framework/Util/MathFunctions.cs index 5a8a0cea2..d6e10d8c4 100644 --- a/Source/Framework/Util/MathFunctions.cs +++ b/Source/Framework/Util/MathFunctions.cs @@ -297,7 +297,7 @@ public static class MathFunctions rotation.M31 * box._center.GetAt(0) + rotation.M32 * box._center.GetAt(1) + rotation.M33 * box._center.GetAt(2) + translation.GetAt(2)); for (int i = 0; i < 3; ++i) - box._edgeVector[i] = Vector3.Transform(box._edgeVector[i], rotation); + box._edgeVector[i] = Vector3.TransformNormal(box._edgeVector[i], rotation); return box; } diff --git a/Source/Game/Collision/Models/GameObjectModel.cs b/Source/Game/Collision/Models/GameObjectModel.cs index c046343b2..c916db03f 100644 --- a/Source/Game/Collision/Models/GameObjectModel.cs +++ b/Source/Game/Collision/Models/GameObjectModel.cs @@ -71,7 +71,7 @@ namespace Game.Collision mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale); AxisAlignedBox rotated_bounds = new(); for (int i = 0; i < 8; ++i) - rotated_bounds.merge(Vector3.Transform(mdl_box.corner(i), iRotation)); + rotated_bounds.merge(Vector3.TransformNormal(mdl_box.corner(i), iRotation)); iBound = rotated_bounds + iPos; owner = modelOwner; @@ -101,8 +101,8 @@ namespace Game.Collision return false; // child bounds are defined in object space: - Vector3 p = Vector3.Transform((ray.Origin - iPos) * iInvScale, iInvRot); - Ray modRay = new Ray(p, Vector3.Transform(ray.Direction, iInvRot)); + Vector3 p = Vector3.TransformNormal((ray.Origin - iPos) * iInvScale, iInvRot); + Ray modRay = new Ray(p, Vector3.TransformNormal(ray.Direction, iInvRot)); float distance = maxDist * iInvScale; bool hit = iModel.IntersectRay(modRay, ref distance, stopAtFirstHit, ignoreFlags); if (hit) @@ -125,13 +125,13 @@ namespace Game.Collision return; // child bounds are defined in object space: - Vector3 pModel = Vector3.Transform((point - iPos) * iInvScale, iInvRot); - Vector3 zDirModel = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); + Vector3 pModel = Vector3.TransformNormal((point - iPos) * iInvScale, iInvRot); + Vector3 zDirModel = Vector3.TransformNormal(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); float zDist; if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info)) { Vector3 modelGround = pModel + zDist * zDirModel; - float world_Z = (Vector3.Transform(modelGround, iInvRot) * iScale + iPos).Z; + float world_Z = (Vector3.TransformNormal(modelGround, iInvRot) * iScale + iPos).Z; if (info.ground_Z < world_Z) { info.ground_Z = world_Z; @@ -152,13 +152,13 @@ namespace Game.Collision return false; // child bounds are defined in object space: - Vector3 pModel = Vector3.Transform((point - iPos) * iInvScale, iInvRot); - Vector3 zDirModel = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); + Vector3 pModel = Vector3.TransformNormal((point - iPos) * iInvScale, iInvRot); + Vector3 zDirModel = Vector3.TransformNormal(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); float zDist; if (iModel.GetLocationInfo(pModel, zDirModel, out zDist, info)) { Vector3 modelGround = pModel + zDist * zDirModel; - float world_Z = (Vector3.Transform(modelGround, iInvRot) * iScale + iPos).Z; + float world_Z = (Vector3.TransformNormal(modelGround, iInvRot) * iScale + iPos).Z; if (info.ground_Z < world_Z) { info.ground_Z = world_Z; @@ -172,7 +172,7 @@ namespace Game.Collision public bool GetLiquidLevel(Vector3 point, LocationInfo info, ref float liqHeight) { // child bounds are defined in object space: - Vector3 pModel = Vector3.Transform((point - iPos) * iInvScale, iInvRot); + Vector3 pModel = Vector3.TransformNormal((point - iPos) * iInvScale, iInvRot); //Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f); float zDist; if (info.hitModel.GetLiquidLevel(pModel, out zDist)) @@ -210,7 +210,7 @@ namespace Game.Collision mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale); AxisAlignedBox rotated_bounds = new(); for (int i = 0; i < 8; ++i) - rotated_bounds.merge(Vector3.Transform(mdl_box.corner(i), iRotation)); + rotated_bounds.merge(Vector3.TransformNormal(mdl_box.corner(i), iRotation)); iBound = rotated_bounds + iPos; diff --git a/Source/Game/Collision/Models/ModelInstance.cs b/Source/Game/Collision/Models/ModelInstance.cs index 7b1b3f3a1..ca753ffb4 100644 --- a/Source/Game/Collision/Models/ModelInstance.cs +++ b/Source/Game/Collision/Models/ModelInstance.cs @@ -123,8 +123,8 @@ namespace Game.Collision return false; // child bounds are defined in object space: - Vector3 p = Vector3.Transform((pRay.Origin - iPos) * iInvScale, iInvRot); - Ray modRay = new Ray(p, Vector3.Transform(pRay.Direction, iInvRot)); + Vector3 p = Vector3.TransformNormal((pRay.Origin - iPos) * iInvScale, iInvRot); + Ray modRay = new Ray(p, Vector3.TransformNormal(pRay.Direction, iInvRot)); float distance = pMaxDist * iInvScale; bool hit = iModel.IntersectRay(modRay, ref distance, pStopAtFirstHit, ignoreFlags); if (hit) @@ -146,8 +146,8 @@ namespace Game.Collision if (!iBound.contains(p)) return; // child bounds are defined in object space: - Vector3 pModel = Vector3.Transform((p - iPos) * iInvScale, iInvRot); - Vector3 zDirModel = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); + Vector3 pModel = Vector3.TransformNormal((p - iPos) * iInvScale, iInvRot); + Vector3 zDirModel = Vector3.TransformNormal(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); float zDist; if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info)) { @@ -155,7 +155,7 @@ namespace Game.Collision // Transform back to world space. Note that: // Mat * vec == vec * Mat.transpose() // and for rotation matrices: Mat.inverse() == Mat.transpose() - float world_Z = ((Vector3.Transform(modelGround, iInvRot)) * iScale + iPos).Z; + float world_Z = ((Vector3.TransformNormal(modelGround, iInvRot)) * iScale + iPos).Z; if (info.ground_Z < world_Z) { info.ground_Z = world_Z; @@ -167,7 +167,7 @@ namespace Game.Collision public bool GetLiquidLevel(Vector3 p, LocationInfo info, ref float liqHeight) { // child bounds are defined in object space: - Vector3 pModel = Vector3.Transform((p - iPos) * iInvScale, iInvRot); + Vector3 pModel = Vector3.TransformNormal((p - iPos) * iInvScale, iInvRot); //Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f); float zDist; if (info.hitModel.GetLiquidLevel(pModel, out zDist)) @@ -191,8 +191,8 @@ namespace Game.Collision if (!iBound.contains(p)) return false; // child bounds are defined in object space: - Vector3 pModel = Vector3.Transform((p - iPos) * iInvScale, iInvRot); - Vector3 zDirModel = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); + Vector3 pModel = Vector3.TransformNormal((p - iPos) * iInvScale, iInvRot); + Vector3 zDirModel = Vector3.TransformNormal(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); float zDist; if (iModel.GetLocationInfo(pModel, zDirModel, out zDist, info)) { @@ -200,7 +200,7 @@ namespace Game.Collision // Transform back to world space. Note that: // Mat * vec == vec * Mat.transpose() // and for rotation matrices: Mat.inverse() == Mat.transpose() - float world_Z = (Vector3.Transform(modelGround, iInvRot) * iScale + iPos).Z; + float world_Z = (Vector3.TransformNormal(modelGround, iInvRot) * iScale + iPos).Z; if (info.ground_Z < world_Z) // hm...could it be handled automatically with zDist at intersection? { info.ground_Z = world_Z; diff --git a/Source/Game/Entities/GameObject/GameObject.cs b/Source/Game/Entities/GameObject/GameObject.cs index 91c1786de..254d45b0e 100644 --- a/Source/Game/Entities/GameObject/GameObject.cs +++ b/Source/Game/Entities/GameObject/GameObject.cs @@ -3749,7 +3749,7 @@ namespace Game.Entities float animProgress = (float)(newProgress - oldAnimation.TimeIndex) / (float)(newAnimation.TimeIndex - oldAnimation.TimeIndex); - Vector3 dst = Vector3.Transform(Vector3.Lerp(prev, next, animProgress), pathRotation);//todo check this + Vector3 dst = Vector3.TransformNormal(Vector3.Lerp(prev, next, animProgress), pathRotation);//todo check this dst += _owner.GetStationaryPosition(); diff --git a/Source/Game/Maps/TransportManager.cs b/Source/Game/Maps/TransportManager.cs index a75b5bc1a..6ab6defff 100644 --- a/Source/Game/Maps/TransportManager.cs +++ b/Source/Game/Maps/TransportManager.cs @@ -334,7 +334,10 @@ namespace Game.Maps List pathPoints = new(); List pauses = new(); List events = new(); - TransportPathLeg leg = new(); + + transport.PathLegs.Add(new TransportPathLeg()); + + TransportPathLeg leg = transport.PathLegs[0]; leg.MapId = path[0].ContinentID; bool prevNodeWasTeleport = false; uint totalTime = 0; @@ -377,7 +380,6 @@ namespace Game.Maps transport.InInstance = CliDB.MapStorage.LookupByKey(transport.MapIds.First()).Instanceable(); transport.TotalPathTime = totalTime; - transport.PathLegs.Add(leg); } public void AddPathNodeToTransport(uint transportEntry, uint timeSeg, TransportAnimationRecord node) @@ -579,7 +581,7 @@ namespace Game.Maps (double)(time - prevSegmentTime) * 0.001, (double)(pathSegment.SegmentEndArrivalTimestamp - prevSegmentTime) * 0.001, segmentIndex == 0, - segmentIndex == leg.Segments.Count); + segmentIndex == leg.Segments.Count - 1); int splineIndex = 0; float splinePointProgress = 0; @@ -602,7 +604,7 @@ namespace Game.Maps { ++legIndex; - if (PathLegs.Count >= legIndex) + if (legIndex >= PathLegs.Count) return null; }