Fixed transports.

This commit is contained in:
hondacrx
2022-06-21 22:35:20 -04:00
parent d42733e3b4
commit 8b1e02759a
6 changed files with 29 additions and 27 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ namespace Framework.GameMath
// M^-1 * (point - _corner[0]) = point in unit cube's object space // M^-1 * (point - _corner[0]) = point in unit cube's object space
// compute the inverse of M // compute the inverse of M
Matrix4x4.Invert(M, out 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) && return (osPoint.X >= 0) && (osPoint.Y >= 0) && (osPoint.Z >= 0) &&
(osPoint.X <= 1) && (osPoint.Y <= 1) && (osPoint.Z <= 1); (osPoint.X <= 1) && (osPoint.Y <= 1) && (osPoint.Z <= 1);
+1 -1
View File
@@ -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)); 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) 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; return box;
} }
+11 -11
View File
@@ -71,7 +71,7 @@ namespace Game.Collision
mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale); mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale);
AxisAlignedBox rotated_bounds = new(); AxisAlignedBox rotated_bounds = new();
for (int i = 0; i < 8; ++i) 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; iBound = rotated_bounds + iPos;
owner = modelOwner; owner = modelOwner;
@@ -101,8 +101,8 @@ namespace Game.Collision
return false; return false;
// child bounds are defined in object space: // child bounds are defined in object space:
Vector3 p = Vector3.Transform((ray.Origin - iPos) * iInvScale, iInvRot); Vector3 p = Vector3.TransformNormal((ray.Origin - iPos) * iInvScale, iInvRot);
Ray modRay = new Ray(p, Vector3.Transform(ray.Direction, iInvRot)); Ray modRay = new Ray(p, Vector3.TransformNormal(ray.Direction, iInvRot));
float distance = maxDist * iInvScale; float distance = maxDist * iInvScale;
bool hit = iModel.IntersectRay(modRay, ref distance, stopAtFirstHit, ignoreFlags); bool hit = iModel.IntersectRay(modRay, ref distance, stopAtFirstHit, ignoreFlags);
if (hit) if (hit)
@@ -125,13 +125,13 @@ namespace Game.Collision
return; return;
// child bounds are defined in object space: // 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 = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); Vector3 zDirModel = Vector3.TransformNormal(new Vector3(0.0f, 0.0f, -1.0f), iInvRot);
float zDist; float zDist;
if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info)) if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info))
{ {
Vector3 modelGround = pModel + zDist * zDirModel; 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) if (info.ground_Z < world_Z)
{ {
info.ground_Z = world_Z; info.ground_Z = world_Z;
@@ -152,13 +152,13 @@ namespace Game.Collision
return false; return false;
// child bounds are defined in object space: // 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 = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); Vector3 zDirModel = Vector3.TransformNormal(new Vector3(0.0f, 0.0f, -1.0f), iInvRot);
float zDist; float zDist;
if (iModel.GetLocationInfo(pModel, zDirModel, out zDist, info)) if (iModel.GetLocationInfo(pModel, zDirModel, out zDist, info))
{ {
Vector3 modelGround = pModel + zDist * zDirModel; 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) if (info.ground_Z < world_Z)
{ {
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) public bool GetLiquidLevel(Vector3 point, LocationInfo info, ref float liqHeight)
{ {
// child bounds are defined in object space: // 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); //Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
float zDist; float zDist;
if (info.hitModel.GetLiquidLevel(pModel, out 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); mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale);
AxisAlignedBox rotated_bounds = new(); AxisAlignedBox rotated_bounds = new();
for (int i = 0; i < 8; ++i) 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; iBound = rotated_bounds + iPos;
@@ -123,8 +123,8 @@ namespace Game.Collision
return false; return false;
// child bounds are defined in object space: // child bounds are defined in object space:
Vector3 p = Vector3.Transform((pRay.Origin - iPos) * iInvScale, iInvRot); Vector3 p = Vector3.TransformNormal((pRay.Origin - iPos) * iInvScale, iInvRot);
Ray modRay = new Ray(p, Vector3.Transform(pRay.Direction, iInvRot)); Ray modRay = new Ray(p, Vector3.TransformNormal(pRay.Direction, iInvRot));
float distance = pMaxDist * iInvScale; float distance = pMaxDist * iInvScale;
bool hit = iModel.IntersectRay(modRay, ref distance, pStopAtFirstHit, ignoreFlags); bool hit = iModel.IntersectRay(modRay, ref distance, pStopAtFirstHit, ignoreFlags);
if (hit) if (hit)
@@ -146,8 +146,8 @@ namespace Game.Collision
if (!iBound.contains(p)) if (!iBound.contains(p))
return; return;
// child bounds are defined in object space: // 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 = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); Vector3 zDirModel = Vector3.TransformNormal(new Vector3(0.0f, 0.0f, -1.0f), iInvRot);
float zDist; float zDist;
if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info)) if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info))
{ {
@@ -155,7 +155,7 @@ namespace Game.Collision
// Transform back to world space. Note that: // Transform back to world space. Note that:
// Mat * vec == vec * Mat.transpose() // Mat * vec == vec * Mat.transpose()
// and for rotation matrices: Mat.inverse() == 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) if (info.ground_Z < world_Z)
{ {
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) public bool GetLiquidLevel(Vector3 p, LocationInfo info, ref float liqHeight)
{ {
// child bounds are defined in object space: // 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); //Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
float zDist; float zDist;
if (info.hitModel.GetLiquidLevel(pModel, out zDist)) if (info.hitModel.GetLiquidLevel(pModel, out zDist))
@@ -191,8 +191,8 @@ namespace Game.Collision
if (!iBound.contains(p)) if (!iBound.contains(p))
return false; return false;
// child bounds are defined in object space: // 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 = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot); Vector3 zDirModel = Vector3.TransformNormal(new Vector3(0.0f, 0.0f, -1.0f), iInvRot);
float zDist; float zDist;
if (iModel.GetLocationInfo(pModel, zDirModel, out zDist, info)) if (iModel.GetLocationInfo(pModel, zDirModel, out zDist, info))
{ {
@@ -200,7 +200,7 @@ namespace Game.Collision
// Transform back to world space. Note that: // Transform back to world space. Note that:
// Mat * vec == vec * Mat.transpose() // Mat * vec == vec * Mat.transpose()
// and for rotation matrices: Mat.inverse() == 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? if (info.ground_Z < world_Z) // hm...could it be handled automatically with zDist at intersection?
{ {
info.ground_Z = world_Z; info.ground_Z = world_Z;
@@ -3749,7 +3749,7 @@ namespace Game.Entities
float animProgress = (float)(newProgress - oldAnimation.TimeIndex) / (float)(newAnimation.TimeIndex - oldAnimation.TimeIndex); 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(); dst += _owner.GetStationaryPosition();
+6 -4
View File
@@ -334,7 +334,10 @@ namespace Game.Maps
List<TaxiPathNodeRecord> pathPoints = new(); List<TaxiPathNodeRecord> pathPoints = new();
List<TaxiPathNodeRecord> pauses = new(); List<TaxiPathNodeRecord> pauses = new();
List<TaxiPathNodeRecord> events = new(); List<TaxiPathNodeRecord> events = new();
TransportPathLeg leg = new();
transport.PathLegs.Add(new TransportPathLeg());
TransportPathLeg leg = transport.PathLegs[0];
leg.MapId = path[0].ContinentID; leg.MapId = path[0].ContinentID;
bool prevNodeWasTeleport = false; bool prevNodeWasTeleport = false;
uint totalTime = 0; uint totalTime = 0;
@@ -377,7 +380,6 @@ namespace Game.Maps
transport.InInstance = CliDB.MapStorage.LookupByKey(transport.MapIds.First()).Instanceable(); transport.InInstance = CliDB.MapStorage.LookupByKey(transport.MapIds.First()).Instanceable();
transport.TotalPathTime = totalTime; transport.TotalPathTime = totalTime;
transport.PathLegs.Add(leg);
} }
public void AddPathNodeToTransport(uint transportEntry, uint timeSeg, TransportAnimationRecord node) public void AddPathNodeToTransport(uint transportEntry, uint timeSeg, TransportAnimationRecord node)
@@ -579,7 +581,7 @@ namespace Game.Maps
(double)(time - prevSegmentTime) * 0.001, (double)(time - prevSegmentTime) * 0.001,
(double)(pathSegment.SegmentEndArrivalTimestamp - prevSegmentTime) * 0.001, (double)(pathSegment.SegmentEndArrivalTimestamp - prevSegmentTime) * 0.001,
segmentIndex == 0, segmentIndex == 0,
segmentIndex == leg.Segments.Count); segmentIndex == leg.Segments.Count - 1);
int splineIndex = 0; int splineIndex = 0;
float splinePointProgress = 0; float splinePointProgress = 0;
@@ -602,7 +604,7 @@ namespace Game.Maps
{ {
++legIndex; ++legIndex;
if (PathLegs.Count >= legIndex) if (legIndex >= PathLegs.Count)
return null; return null;
} }